For your first lab, you will create a Java program that allows two
people to play a game of Connect 4 with each other. Rules of the
game (and a one-player flash applet) can be found at Milton Bradley's
site
here.
A full description of the game sans flash can be found at
wikipedia.
Program output:
Your program should print the board, ask for a move from black, print
the board, ask for a move for red, and so on, until either one of the
players has won, or until the board is completley filled in, with no
legal moves remaining. Your program should check for errors in
input, allowing players to try again if they enter a bad move. A
sample session might be:
0123456
.......
.......
.......
.......
.......
.......
.......
Enter a position to play, Red:3
0123456
.......
.......
.......
.......
.......
.......
...R...
Enter a position to play, Black:4
0123456
.......
.......
.......
.......
.......
.......
...RB..
Enter a position to play, Red:3
0123456
.......
.......
.......
.......
.......
...R...
...RB..
Enter a position to play, Black:4
0123456
.......
.......
.......
.......
.......
...RB..
...RB..
Enter a position to play, Red:3
0123456
.......
.......
.......
.......
...R...
...RB..
...RB..
Enter a position to play, Black:4
0123456
.......
.......
.......
.......
...RB..
...RB..
...RB..
Enter a position to play, Red:3
0123456
.......
.......
.......
...R...
...RB..
...RB..
...RB..
Red Wins
A different sample run might be:
0123456
.......
.......
.......
.......
.......
.......
.......
Enter a position to play, Red:3
0123456
.......
.......
.......
.......
.......
.......
...R...
Enter a position to play, Black:3
0123456
.......
.......
.......
.......
.......
...B...
...R...
Enter a position to play, Red:3
0123456
.......
.......
.......
.......
...R...
...B...
...R...
Enter a position to play, Black:3
0123456
.......
.......
.......
...B...
...R...
...B...
...R...
Enter a position to play, Red:3
0123456
.......
.......
...R...
...B...
...R...
...B...
...R...
Enter a position to play, Black:3
0123456
.......
...B...
...R...
...B...
...R...
...B...
...R...
Enter a position to play, Red:3
0123456
...R...
...B...
...R...
...B...
...R...
...B...
...R...
Enter a position to play, Black:3
Illegal move, try again.
0123456
...R...
...B...
...R...
...B...
...R...
...B...
...R...
Enter a position to play, Black:0
0123456
...R...
...B...
...R...
...B...
...R...
...B...
B..R...
Enter a position to play, Red:4
0123456
...R...
...B...
...R...
...B...
...R...
...B...
B..RR..
Enter a position to play, Black:0
0123456
...R...
...B...
...R...
...B...
...R...
B..B...
B..RR..
Enter a position to play, Red:5
0123456
...R...
...B...
...R...
...B...
...R...
B..B...
B..RRR.
Enter a position to play, Black:0
0123456
...R...
...B...
...R...
...B...
B..R...
B..B...
B..RRR.
Enter a position to play, Red:6
0123456
...R...
...B...
...R...
...B...
B..R...
B..B...
B..RRRR
Red Wins