GameGrid: Game programming with Java

Research project PHBern  
HomePrintJava-Online

Exercise 6: Reversi Game

Game rules:

On an 8 × 8-board two players alternately put white and black stones. At the beginning of the game, two white and two black stones are placed in the middle of the board. The pieces can be placed only in empty location, which have at least one neighbouring location occupied (left, right, up, down, NOT diagonally)

not allowed
allowed
stones reversed

If a stone was placed, all the opponent's pieces, which are located in rows or diagonals between the new and already placed stones of the same color get reversed, meaning they change to the players own color. The goal is to have as many stones of your own color on the board as possible. The game is finished when all locations are occupied.

As template you can use the file Reversi_0.java

Edit Reversi_0.java in the Online-Editor

Download (Reversi_0.zip)

 

It is recommended to develop the game in the following steps:

Step 1: Set pieces with a mouse click in any empty location

 

 

Step 2: Check if at least one of the adjacent location is occupied

 

 
Step 3: Set alternating white and black stones


   

Step 4: Reverse the stones between a newly set stone and all of the same color on the same line.

 

Help

Step 5: Check if the game is over and display the results if it is.