Project 2, Connect Four
-->
Connect Four
Assigned | Friday, March 1th |
---|---|
Program Due | Friday, March 15th by 2:00am |
Weight | 7% |
Updates |
Objectives
To gain experience in the following areas.
- Using enumerated types
- Writing unit tests
- Working with the object-oriented paradigm
- Documenting classes
- Documenting methods
For this project, we will be coding a text based version of Connect Four. If you are unfamiliar with the game, please go here to learn more: http://en.wikipedia.org/wiki/Connect_Four
You will be creating three classes: Project2.java, ConnectFour.java, Move.java. Descriptions are below:
Project2.java
Project2 will be a text based menu that does the folowing:
- Ask player one for their name
- Ask player two for their name
- Ask for the number of rows and columns in the board
- While the game hasn't ended and no player has entered q:
Continue prompting, players by name, for the column they'd like to play. After each move, redisplay the board. - If the game has ended, ask the player if they want to play again
- If at any point a player hits Q, immediately exit the program
An invalid move should cause the menu to reprompt the player for their move.
ConnectFour.java
ConnectFour.java should contain the board state and which player's turn it is. The ConnectFour object should be able to allow the currnet player to move, report on whether the game has ended or not, and convert itself to a string for the purpose of display. When storing the board, use the Move enum to ensure that the player's moves are all in a valid state. For example, if you choose to represent the board as a two dimensional array, you should make that array of type Move to ensure that the only valid values for a space are PLAYER1, PLAYER2, or EMPTY. Note that a board that has an area of less than 25 spaces should be considered invalid, and you should include the following line: throw new RuntimeException("Invalid board size");
Move.java
This enum represents a state at a given position on the board. It can take on the values PLAYER1, PLAYER2, or EMPTY.
Unit Testing
ConnectFour should have a main class with a test for all major functions showing they work with a variety of inputs.
Notes
- Players can only quit when being asked for their moves--a player who's name is Q should be accepted.
- If a player enters an invalid type of input -- a string that is not either a number or Q for a move -- it is acceptable to simply let the program crash.
- If new game is selected, the program should NOT reprompt for a new board size
- Unit testing should be in a main in ConnectFour, and should show that you have tested all of ConnectFour's functions well enough that you are sure they work.
Sample Output
Welcome to ConnectFour! At any time you may press Q to exit! Please enter player one's name: Max Morawski Please enter player two's name: Susan Mitchell How many rows would you like? 10 How many columns would you like? 10 __________ __________ __________ __________ __________ __________ __________ __________ __________ __________ Max Morawski, where would you like to move? 0 __________ __________ __________ __________ __________ __________ __________ __________ __________ X_________ Susan Mitchell, where would you like to move? 1 __________ __________ __________ __________ __________ __________ __________ __________ __________ XO________ Max Morawski, where would you like to move? Q Exiting.