Hardware Reference
In-Depth Information
Main game loop
1. When the start buton is pressed, the runGame funcion is called to start the game.
If the game is being launched for the irst ime, the isFirstGame variable is set
to true . The computer always plays irst for the very irst ime ater the game is
launched and the irst turn is randomized for consecuive plays.
2. When a new game is iniialized, the getNewBoard method is called to create
an empty board object to get started with the game. All game moves by the
computer and the human player are recorded to this object. This is used to
determine whether there is a winner as well as the computer to determine
potenial moves to play the game.
3. Once we enter the main game loop, the game loop is divided into two tasks,
the computer and the human's turn.
4. When it is the player's turn, we wait for the player to play their turn using the
butons. When a buton press is detected, using the animatePlayerMoving
method, a coin drop is simulated. The game's board object is updated with the
latest move.
5. This is followed by the computer's turn. The getComputerMove method calls the
getPotentialMoves funcion to determine the best possible moves available
for the computer's turn. Then, the computer's coin drop is simulated using the
animateComputerMoving() method.
6. The game AI runs a check after each turn has been played to determine whether
the player or the computer is a winner using the isWinner method.
7. If either of them has won the game, an image declaring the winner is chosen.
The game also checks whether the game was a ie. When either of the earlier
menioned three events occur, the program breaks out of the game loop and
displays the winner (or a ie) and waits for the start buton event to return to
the main menu. Consequently, this will enable you to start a new game.
Objective complete - mini debriefing
Now that the code review is complete, let's move on to the next task to implement a simple
marquee and wire up the input butons.
 
Search WWH ::




Custom Search