Conditional or if statements ask questions about the program state to choose from a set of different sequences of commands (Basically if something is true then a chosen set of commands will execute, and if not, a different set of commands will execute or nothing will happen). Examples of if statements can be seen in almost all game and software applications. To find specific examples, we can look at the programming behind Crossy Road.
In Crossy Road, you have to tap the screen in order to move forward. An if statements would have been used by the programmer so that if screen is touched then move forward by 1.
Similarly, if the screen is swiped sideways or backwards, the game will automatically move the character sideways or backwards by 1 every time the screen is swiped in the desire direction. The basic code for this would sound like if screen swiped from left to right then move right by 1 OR if screen swiped from right to left then move left by 1. The same thing happens for moving backwards except the screen would need to be swiped downwards and the character would move down or backwards by 1.
Watch out though! If you get hit my a car or a train, or even if you fall in water, then game stops and you temporarily 'die'. Don't worry though! Like in any video game you can try again and come back to life. The if statement to simulate this would be something like if character touches car then stop everything. The actual code for the game is much more complicated because after you 'die' different screens and options are brought up however, the main code for the whole action of 'dying' is probably similar.
One of the really cool things about Crossy Road that keeps players interested is you can win different characters. If you have 100 coins then you can go to the prize machine to win a character. One of the codes for this would be if coins = <100 then show 'win a prize' button. If you wanted to go further you'd need a code that said if the button was pressed then show a different background, bring up a different script or 'character' etc. You would need a whole new set of codes to program the actual prize machine.
One of the other cool things about Crossy Road is that if you have a certain character, the 'map' or 'roads' will be specified to that certain characters habitat or theme. To do this there would need to be an if code that said if '_______' character is selected then change background to '________'. Examples of this are desert areas for desert animals and winter areas for winter animals. There is also a map that turns black and white for Frankenstein and the main grassy one for all the basic characters.
My 4 yr old grandson downloaded and play this game. He seems to enjoy it.
ReplyDeletefallout shelter for pc best action game on android 123 games