Chomp Game Instructions
Follow the order
below in completing the different phases of the Chomp Game project.
Chomp Version 1 ... Human
Player vs. Computer Player. (no sound)
After the instructor has gone over the following files: ChompGame, ChompBoard, Position, ComputerPlayer, and HumanPlayer, then begin by running the Chomp Version 1 applet program and watch the
text display within the applet just
above the board. The display prompts the two human players when it is their
turn to move. Note that as a player clicks a square on the Chomp board that all of the squares to the right and below the square clicked are removed from the game (painted gray). The goal of the game is to not have to pick the upper left square which is "poison". You can refresh your browser to test the game again. Run Chomp Version 1.
Here is what you need to do to complete Chomp Version 1:
-
Make a ch12 package folder in your ACP project folder.
-
Make a Chomp_v1 folder in your ch12 package folder.
-
Get all of the starter files from email and save them to your Chomp_v1 folder.
-
Complete the code in the methods of the CharMatrix class.
-
Complete the code in the init() and hasMoved() methods of the BoardGameApplet class.
-
Run and test the program and make sure it runs properly, then email me the files.
-
Post the files on the web using the ChompV1.html file and archive the files as follows:
- Use the name Chomp_v1A.jar. for the version where the human moves first.
- Use the name Chomp_v1B.jar. for the version where the computer moves first.
Procede to the next phase and make sure you follow the instructions exactly!
Chomp Version 2 ... Human Player vs.
Human Player (with sound).
Run the Chomp Version 2 applet program and watch the text display within the applet just above the board. The display prompts either the human or the computer player to move. Run Chomp Version 2.
Here is what you need to do to complete Chomp Version 2:
- Make a new folder named Chomp_v2 in your ch12 package folder in your ACP project folder in your Eclipse workspace.
- Duplicate only the following .java files in the Chomp_v1 folder and place them in your Chomp_v2 folder:
- CharMatrix.java
- ChompBoard.java
- ChompGame.java
- ComputerPlayer.java
- Player.java
- Position.java
- Strategy.java
- HumanPlayer.java
- Check the package declarations and change them to package ch12.Chomp_v2; Make sure there are no other package declarations that reference the Chomp_v1 package folder.
- Get the following files from email and place them in your new Chomp_v2 folder in your Eclipse workspace:
- Various sound files: Chomp1.wav, Chomp2.wav, Player1Won.wav, Player2Won.wav, and welcome.wav should be placed directly in the Chomp_v2 package folder. No separate sound folder is needed.
- BoardGameApplet.java
- Add this import statement at the top of any file that needs it: import java.applet.AudioClip;
- Modify the Player interface to add the method getWinSound() that returns a value of type AudioClip.
- Modify the HumanPlayer.java file to make it an abstract class that still implements the Player and MouseListener interfaces. You will have the same instance variables and same constructor but there will be some changes. Add two instance variables named myChompSound and myWinningSound of type AudioClip. Add two additional parameters to the constructor named chompSound and winningSound. The parameters will initialize the instance variables. The getPrompt() and getWinMessage() methods will be made abstract methods. Add the method getWinSound() but don't make it abstract. You should be able to figure out what type of code it needs. Keep the MouseListener signatures as before along with the entire mouseReleased() method and the makeMove() method. They will not change.
- Create the two files HumanPlayer1.java and HumanPlayer2.java that will extend the new HumanPlayer abstract class.
- Each of these classes should contain only the methods not provided by the HumanPlayer class' abstract methods.
- These two classes will each have a constructor, which calls the constructor of the HumanPlayer abstract class. The constructor for each of these classes should pass the applet, game, and board parameters plus two new sound parameters named chompSound and winningSound for that player up the line to the HumanPlayer class. Each of these classes will have NO instance variables. The code for the displayPrompt method in each class should display a specific prompt for the human player 1 or human player 2 (e.g., “Your turn, Player 1” and “Your turn, Player 2”) and different winning messages, like "Congratulations, you won, Human Player 1!", etc.
- Finally, finish the code in the new BoardGameApplet.java by following the inline instructions.
- When you have the program running properly including sounds, then email me all of your files and post the applet on the web using the ChompV2.html file. Archive all files including the sounds in Chomp_v2.jar
Procede to the next phase and make sure you follow the instructions exactly!
Chomp Version 3 ... Human Player vs.
Human Player vs. Computer Player (with sound).
Run the Chomp Version 3 applet program and watch the text display within the applet just above the board. The display prompts either of the two human players or the computer player to move. Run the program several times to see that the game randomly begins with any of the three players. Run Chomp Version 3.
Here is what you need to do to complete Chomp Version 3:
- Begin by creating the folder Chomp_v3 in your ch12 package folder.
- Duplicate all files in your Chomp_v2 folder (including the sound files) except BoardGameApplet and place them in your Chomp_v3 folder.
- Get the new BoardGameApplet.java file from email.
- Check the package declarations of all files and make sure they are package ch12.Chomp_v3; Make sure there are no other package declarations that reference the Chomp_v2 package folder.
- Get the additional chomp.wav file from email. This is the file that will be played when the Computer moves.
- Modify the ComputerPlayer.java file so that it can accept chomp and winning sounds from the driver when a ComputerPlayer is being constructed. To do this add two instance variables myChompSound and myWinningSound to the ComputerPlayer class and then add two additional parameters to the constructor signature named chompSound and winningSound. The parameters will initialize the instance variables. Next, add the getWinSound() method and change the getPrompt() and getWinMessage() methods to specify the computer in the strings returned, as in " Your turn Computer ... " and for the winning message just have " Computer ". (Note the space on either side of the word computer. The "You won" part will be added in BoardGameApplet. Finally, add the line to play myChompSound in the appropriate place in ComputerPlayer.java.
- Modify the HumanPlayer1 and HumanPlayer2 classes so that the winning messages says just " Human Player 1 " or " Human Player 2 ". The "You won" part will be added in BoardGameApplet.
- Modify the BoardGameApplet.java file so that the Chomp game includes two Human players and one Computer player. You will need to modify code in both the init() method, hasMoved(), and actionPerformed methods. Follow the inline instructions. Get it to work and then email me all of your files and then post it on the web. One Note of Explanation: in the game.isWon() branch you will play the first winning sound and then fire a clock to play the second winning sound in actionPerformed. We need this so we can get a delay between the two sounds. Note there are two global variables w1 and w2 of type Player that will refer to winning player 1 and winning player 2. The two winning players are the next two players after the losing one, so you should be able to get references for w1 and w2.
- When you have the program running properly including sounds, then email me all of your files and post the applet on the web using the ChompV3.html file. Archive all files including the sounds in Chomp_v3.jar
Procede to the next phase and make sure you follow the instructions exactly!
Coding Chomp Version 4 ... Computer Player vs. Computer Player (with sound).
Run the Chomp Version 4 applet program and watch the text display within the applet just above the board. The display prompts either of the two computer players to move. Run the program several times to see that the game randomly selects either of the comuter players to start first. Run Chomp Version 4.
Here is what you need to do to complete Chomp Version 4:
- Begin by creating the folder Chomp_v4 in your ch12 package folder.
- Duplicate all files in your Chomp_v3 folder except the BoardGameApplet file and place them in your Chomp_v3 folder. Make sure you duplicate the sound files.
- Check the package declarations and change them to package ch12.Chomp_v4; Make sure there are no other package declarations that reference the Chomp_v3 package folder.
- Get the additional chomp1.wav, chomp2.wav, Comp1Won.wav, and Comp2Won.wav files from email.
- Modify your ComputerPlayer class to add one additional parameter to the constructor ... a String parameter named num. Add an instance variable named number to the class and pass off num to number in the constructor. Then add the instance variable number to the string values returned by getPrompt() and getWinMessage(). This will make the prompts and winning messages specific to computer player 1 and computer player 2. When you call the constructor in the driver, be sure and add the extra parameter of "1" or "2" to the parameter list.
- Get the new BoardGameApplet.java file and follow the inline instructions to know what code to write. This version of the Chomp game includes only two Computer players. You will need to write code in the init() method, the hasMoved() method, and the actionPerformed() method. Follow the inline instructions. Get it to work and then email me all of your files and then post it on the web using the ChompV4.html file. Archive all files including the sounds in Chomp_v4.jar
Back to Top