Download presentation
Presentation is loading. Please wait.
1
CIS125GA_03 Things that help
2
Methods Planning Code Flowcharts Comments Pseudocode
Contents: Slides Methods Planning Code Flowcharts Comments Pseudocode
3
Methods Dissected A Method / Function can do several things:
Ask a Question about the state Do some Math Modify the Values of an Object’s properties Update and Start are both Methods. ReturnType NameOfMethod (Parameters) { Instructions; }
4
Methods Dissected Cont.
Think of a Method as a little factory. Parameters / Arguments are Raw Materials going in. The Method processes it. Return – ed values are your final Product. Int DamageTaken (HP, FireBallPoints) { HP -= FireballPoints Return HP }
5
Methods Dissected Further
There are 3 Questions you should ask yourself when designing a Method. What do I want to achieve? (Method Instructions) What information does it need to run? (Parameters) What do I need to get back from it? (Return)
6
Planning your Code Code for games involves asking a lot of questions about the State, then selecting a branch to modify the state in response. The questions you ask will be Booleans (True or False Questions) or Mathematical Operations. The more Branches you have, the more complicated the game. Common Questions include: Is the Hero’s HP above 0? Did the Sword Hit the enemies weak spot? Is the Mob facing the player? Is the Timer below 1 minute? Is the Player Colliding with the power up? Did the player Collide with the trigger?
7
PseudoCode PSUEDOCODE Is writing down your code in plain Human Language, as part of your planning process. Similar to Human Languages, if you can articulate what you want to do in words, you can “translate” it to Programming languages. Each Written Line should be equivalent to a Line of code. You may write, In EXAMPLE: IF Lancelot enters the Forest, THEN Turn on the grail shaped beacon.
8
Visual Programming See if you can figure out what the code is doing. Answer is a click away! Once the trigger is touched, the door becomes open-able by the character. Once the trigger (which is an area in space) is exited by the player, the door is closeable.
9
FlowChart Example: Has the 1 button been pressed? No Yes Do Nothing
Does the Hero have more than 0 HP AND does the Enemy have more than 0 HP? No Yes Debug Log Game Over Turn Off Level Light Assign a random number to HitDamage Debug Log HitDamage Is HitDamage Greater than or Equal to 5? No Yes Debug Log "Hit!" Enable Hero Light Disable Enemy Light Subtract HitDamage from EnemyHP, then re-assign it to the variable Debug Log EnemyHP (the new value) Debug Log "Miss!" Disable Hero Light Enable Enemy Light
10
Comments A // COMMENT is text placed into your code that computer ignores, but maintains the sanity of you and other programmers! A special symbol tells the computer what text is comment, and what is code. You can Comment out large blocks of code with a /* at the beginning, and a */ at the end. In MonoDevelop, you can also R-CLICK several lines of code and Toggle line comments on and off. This is helpful for troubleshooting!
11
Pseudocode & Comments Cont.
Your Comments will likely look like your Pseudocode, but recognize the difference: Pseudocode is what you just write out somewhere for planning. Comments are text you insert In Your Code, that the computer ignores, but people read.
12
EXAMPLE: Let’s take our Pseudocode, and make it into some comments in our code: // This is a block of code that turns on the Beacon. Void TurnOnGrailShapedBeacon () { // If Lancelot is in the forest AND if the Beacon isn’t currently on: if ( lancelotInForest = true && beaconOn = false) // Then we tell the computer that it is on and we make it visible in the game {beaconOn = true; beaconOpacity = 100; }
13
Example: In Alice, it may look like this:
(Assuming Lancelot is the crispy knight, and the forest is all apple trees..) See the comment line? You will need to LIBERALLY comment your code from now on!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.