Prog 3 Tic Tac More
Prof. Reed, CS 102, Fall 2011
Due at 11:59pm on the date indicated in the Course Schedule
9/23 updates shown below in green
You may work with a partner on this project.
You may have played tic-tac-toe, where the object is to get 3 in a row. This is a slight extension, where the object is to get 4 in a row OR to get 3 in a row along one of the edges. The first part of the game looks like:
Welcome to TicTacMore Author: Dale Reed CS 102, program #3. Written in Java using Eclipse. Lab: Wed 7am with Edmund Hilary The object of the game is to get either 4 in a row or 3 in a row on any edge. Player X starts and play alternates until someone wins or the board is full. You may only move in a square adjacent to a piece already played. 1 2 3 4 5 A . . . . . A B . . . . . B C . . . . . C D . . . . . D E . . . . . E 1 2 3 4 5 1. Enter row and column for move (e.g. b3) -> c3 1 2 3 4 5 A . . . . . A B . . . . . B C . . X . . C D . . . . . D E . . . . . E 1 2 3 4 5 2. Enter row and column for move (e.g. b3) -> b2 1 2 3 4 5 A . . . . . A B . O . . . B C . . X . . C D . . . . . D E . . . . . E 1 2 3 4 5 3. Enter row and column for move (e.g. b3) -> x Exiting program... Thanks for playing. Exiting...
You need to know the following concepts in order to write this program:
Everything from the previous programs (variables, if statements, loops, input/output, Strings)
How to handle a 5 x 5 board implemented using 25 variables (unless you are working ahead to use arrays). I suggest you look at this program (solution to Square-Up, Program #3 from CS 107 Spring 2011) to see how to do this.
Breaking your program up using methods. Using classes and objects
Using existing classes to create a graphical representation, similar to that used in this program.
Hints:
Consider writing the program a step at a time, using the following order. The number of points for each item are shown, out of the 55 total points for program execution.
(0 points) Get the instructions to display. Declare and initialize the variables used to represent the board. Write the method to display the board.
(10 points) Write the method to get user input, keeping track of the move number. Then write the method that modifies the board, based on the user input. On odd numbered moves it is the turn of 'X' to play. On even numbered moves it is the turn of 'O' to play. Put this code in a loop so multiple moves can be made. When the user input is 'x' then give a message and exit the game.
(5 points) Write the method that verifies each move is adjacent to at least one existing piece on the board. The one exception to this is that the first move of 'X' can be anywhere on the board.
(10 points) Write the method to check for a win of 3 in a row along one of the edges. Give a message, display the final board configuration and exit the program if found.
(10 points) Write the method to check for a win of 4 in a row anywhere else on the board. Give a message, display the final board configuration and exit the program if found.
(0 points) Once the above is working, turn it in to Blackboard before continuing on to the next stage.
(20 points) Modify your program so that in addition to the textual representation it also displays a graphical representation. To do this you will need to be familiar with using the files shown in this program: Board.java (displays board and handles results of move selection), Square.java, Circle.java and Canvas.java (implements the drawing for us - don't change this file.) Note that for our program you will not be implementing mouse input, but rather input will always come from the keyboard.
Turn in your program into Blackboard, into the Program 3 assignment. You can turn it in multiple times, but only the most recent version turned in will be graded.
Looking for up to 10 points of extra credit? Be sure that you have turned in a completed working version of the basic requirements before you try any of the items below.
(4 points) Create a mouse-driven program using a graphical user interface.
( 6 points) Figure out how to have your program play against a smart computer opponent.