Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chomp. How is the game played Human player goes first choose a square, all to the right and down are “eaten” computer takes a turn whoever is forced to.

Similar presentations


Presentation on theme: "Chomp. How is the game played Human player goes first choose a square, all to the right and down are “eaten” computer takes a turn whoever is forced to."— Presentation transcript:

1 Chomp

2 How is the game played Human player goes first choose a square, all to the right and down are “eaten” computer takes a turn whoever is forced to take the last square (with the X) loses.

3 All complete but 2 classes

4 How the game works starts with BoardGame applet init method creates: 1.game object 2.the board 3.the players adds a display field and the board to the applet’s content pane chooses 1 st player calls player makeMove method.

5 The first thing to do is understand the program as it is. Look at –position –human player –computer player –game –game board

6 Position: simplest class public class Position { private int row, col; /** * Constructor */ public Position(int r, int c) { row = r; col = c; } /** * Returns this position's row */ public int getRow() { return row; } /** * Returns this position's column */ public int getCol() { return col; } used by players, board and strategy

7 Strategy only used by Computer player stores moves 2 ways to move random with strategy try to play without discovering the strategy the computer uses first!!

8 The ChompGame class public class ChompGame extends CharMatrix keeps track of board’s configuration implements the moves does not display the board – done by ChompBoard is a “model” of the game only ChompGame and Strategy know anything about the rules of the game.

9 Char Matrix Needed for ChompGame Finish and test this class first. No need to add any extra constructors or methods. How will you test this to be sure it works? XXXX XXXX XXXX CharMatrix c = new CharMatrix(3,4,’x’); create a 3 row 4 column matrix of x’s c.clearRect(1,3,2,4); clear from row 1 to row 2 col 3 to col 4 XXXX XX XX

10 Board Game Applet top class derived from JApplet complete except the hasMoved method. init method creates: –game object –the board –the players –adds a display field and the board to the applet’s content pane. Very general. Doesn’t care what game is played or how players make their moves as long as they take turns.

11 Board Game has moved method Called by each player when that player completes its current move. First: updates to next player. Second: Either displays a winning message if the game is over or else displays a prompt and has the other player to make the next move Needed because a player does not complete the move right away when make Move is called –human player awaits a mouse click –computer player waits until display stops flashing


Download ppt "Chomp. How is the game played Human player goes first choose a square, all to the right and down are “eaten” computer takes a turn whoever is forced to."

Similar presentations


Ads by Google