Read without ads and support Scribd by becoming a Scribd Premium Reader.
 
 Java Games with Greenfoot Lesson4: Tic-Tac-Toe GameWrap-up
In this lesson, we will make the Board class check the game progress and stop thegame once someone has won. I will then introduce the concept of Java Arrays. Wewill add code to constantly check whether three game balls of the same color haslined up and to mark those winning game balls.
Step 1: Add isGold(), isSteel(), and isUnclicked() functions tothe Game Ball Class
 To check the status of a game, we check the status of each game piece of the gameboard. The status of a game piece in this Tic-Tac-Toe game is: UNCLICKED, GOLD,and STEEL. To allow objects of other classes to check the status of a Game Ballobject, we add three more
access
functions: isGold(), isSteel(), and isUnclicked(). The access functions of a class are functions to get or set the member variables of that class. The setGold(), setSteel(), and reset() functions that we added in theprevious lessons are also considered as access functions of the GameBall class.
 
Step2: Add Progress Checking to the Board Class
 There are eight ways of winning a Tic-Tac-Toe game:
 
 This is the code to check for player1’s win (three steel balls line up): This is the code to check for player2’s win (three gold balls line up):
Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • More From This User

    Notes
    Load more