Wednesday, February 22, 2012

Lab 13: Connect Four


For this lob you will implement a simple text-based version of the Connect Four game.

The Connect Four board has 6 rows and 7 columns. Your program will display a text-based board and then ask the user to enter the column on which to drop a piece. The program will then show the new board with the piece dropped in the appropriate place. The colors (players) will alternate. You do not have to check to see if one of them has won (but, it would be very good practice for the test!).

Below is a sample interaction with the program:
0 1 2 3 4 5 6 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 

Enter column for B's move:0
0 1 2 3 4 5 6 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
B _ _ _ _ _ _ 

Enter column for R's move:0
0 1 2 3 4 5 6 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
R _ _ _ _ _ _ 
B _ _ _ _ _ _ 

Enter column for B's move:0
0 1 2 3 4 5 6 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
B _ _ _ _ _ _ 
R _ _ _ _ _ _ 
B _ _ _ _ _ _ 

Enter column for R's move:1
0 1 2 3 4 5 6 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
B _ _ _ _ _ _ 
R _ _ _ _ _ _ 
B R _ _ _ _ _ 

Enter column for B's move:6
0 1 2 3 4 5 6 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
B _ _ _ _ _ _ 
R _ _ _ _ _ _ 
B R _ _ _ _ B 

Enter column for R's move:6
0 1 2 3 4 5 6 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
_ _ _ _ _ _ _ 
B _ _ _ _ _ _ 
R _ _ _ _ _ R 
B R _ _ _ _ B 

Enter column for B's move:


You will implement a Board class which holds the state of the board using a 2-dimensional array. This class should have a toString method and a drop method which handles the dropping of a new piece on the board.

As always, turn it in on the dropbox.cse.sc.edu.



No comments: