GameGrid: Game programming with Java

Research project PHBern  
HomePrintJava-Online

Exercise 11: TCP Reversi Game


Program a Reversi game that can be played over the Internet.

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.

Tutorials and examples of TCPGame programming can be found at www.aplu.ch/jgamegrid.

 

As template you can use the file TcpReversi_0.java

Edit TcpReversi_0.java in the Online-Editor

Download (TcpReversi_0.zip)

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

Step1: Set stones with a mouse click in any empty location

For this to work, a GGMouseListener has to be put to use. Implement it at the Class's header and call the method addMouseListener(this, GGMouse.lPress) in the constructor. Check, if the clicked location is empty and set a white stone there if it is.

 

 

Stept 2: The coordinates of a placed stone should be transmitted to the opponent and appear there as well.

 

 

 

Step 3: Check if there is at least one occupied adjacent cell


 

Step 4: Reverse the stones between the newly placed stone and other stones of the same color

 

Help

Schritt 5: Handle Game over and view the results