Announcements
| Motivation
| Goals
| Overview
| Rules
| Requirements
Useful Classes
| Coding
| Testing
| At Home
| Hints
| Hand-in
| Solution
It is getting close to the end of the semester and since you and your friends are so busy with classes, you have not had the opportunity to hang out together. Therefore, you have set yourself to the task of finding a bonding activity. Inspiration has just struck: a game! A challenge requiring thought and at least two people. The game to rule all games: a connect four tournament has been scheduled at the end of the semester. To ensure that your team has the best chance of winning, you have the inspiration to create a practice connect four game so that you and your friends will be the champions at the tournament. As an aspiring programmer, you've decided to implement a Java program so that everyone on your hall can practice with each other. Your program allows the user to choose the size of the board and pit their talents against another player. This task is described in more detail below. In this project you will design, code, and test your connect four database program.
Required Reading
Read Chapters 8, 9, 12 (sections 12.1 and 12.2), the Java IO web page, and the Exceptions web page.
Back to Top
The goals of this assignment are: Back to Top
Back to Top
Back to Top
Game Basics Back to Top
Much of this program will reply upon good input / output to both the console and also various data files. Several standard JAVA classes work together in a fairly complex way to accomplish this. Use the following Java API
classes to complete this program. Click on links below for Java API documentation. Useful classes in the Java
util package: (import
java.util.*): Useful class in your project
stationery (no import needed): Useful objects (see the Java
API documentation for System):
DO NOT USE ANY
OF THE JAVABOOK2 CLASSES! DO NOT USE THE
VECTOR CLASS! Back to Top
Use the stationery file
Assignment2 from cs302. Remember to save this as Assignment2 in your
U:\private\cs302\ folder. Refer to
Lesson 2 Step 2: How to create
a new project if you need help creating a project. To use an incremental coding
approach when creating your instantiable classes, you can begin by coding and
testing each method one at a time, starting with a constructor. Use your main
method in the ConnectFour class to send messages to test these methods as they
are coded. When a main method is used in this manner it is called a driver
program. Once the instantiable class is completed, replace the test messages in
main with the desired main program. As you are coding, don't
forget to follow the commenting
and style requirements. Back to Top
Once the program is coded
you are not done. You still need to determine that your program works correctly
and robustly. A correct program is one where each operation adheres exactly to
the specifications laid out in the assignment description. A robust program is
one that doesn't crash when unexpected or erroneous situations occur such as
when the user enters invalid input. Error detection and resolution is an
important aspect of this assignment. There are many places where the user's
input can cause an error and your
program must give clear error messages and must not crash or lose information
from your files. Unless otherwise
specified, after an error message is displayed, the prompt that appeared before
the invalid input was entered is redisplayed. For numeric input, make sure that
numbers are entered (i.e. catch NumberFormatExceptions), and that they are
reasonable (e.g. you cannot have a negative number for copyright year). If
there is an invalid input, display the error message below before redisplaying
the prompt for input. Invalid Input. Try
again. Ensure
that no input contain '|' (i.e. pipe) characters. They may contain other characters,
including ':' (i.e. colon) characters. If they contain any pipes, remove the pipes from the input value
before adding them to the database. An empty string is considered invalid input.Display an error message and re-prompt the
user to enter. . Several other common error situations that
your program needs to handle include: · reading from a non-existent file · playing out of bounds · invalid menu choices This list is not exhaustive.
You need to ensure that your program behaves well for both expected and
unexpected situations. To receive
full credit, your code must compile and run correctly. It should not
cause any exceptions that are not caught. Your program must display the menus
with the options in the order specified and it must not ask the user for any
additional information. You also must follow these commenting and style requirements. What to do to work at
home. Warning: If you are having difficulty with the
installation, then you should do your work in the CS computer labs. Problems
with installation are not an acceptable excuse for not completing your work by
the due date. Some tips to get you
started. · START EARLY! · Read Chapter
8 for information about processing Strings and characters. · Read Chapter
9 for information about using arrays. · Read the Java IO web page for
information about Input/Output (I/O). · See ConsoleIO.java for an example of console input
and output. · See FileIO.java for an example of file input and
output. · Test for
error situations on each operation before starting the next operation. · You will need
to create new classes. See
Step 5: How to add a source file to an existing project of the Lesson
2 tutorial if you need help adding new source files. What you must hand in for
this assignment. Use the Handin
program to hand in the files listed below. See Step 7: How to hand-in your
work of the Lesson 2 tutorial for instructions on how to use the Handin
program. These files must be handed
in anytime prior to the due date. Note: You may hand in your files before the
deadline as many times as you wish. We suggest that you use your hand-in
directory to keep your most recent working copy as you develop your solution. No solution will be
provided for this assignment. © 2002 modified from an assignment
originally written by Jim Skrentny © 2001 Goals: What we hope to learn.
Game Overview: What's Going to Be Involved?
In this assignment, you will be writing a program called ConnectFour that will let users play games of connect four. As games are played, the win/loss/draw records of all the players will be updated. Furthermore, you will be saving games to files so that you can postpone them and continue bonding with your friends later.
The medium for these games will be the black console window, where you will be prining out a character representation of a connect four game. Here is an example of a game in progress:
In other words, we you not be using any javabook packae classes. Instead, you'll use many of the provided JAVA standard utility and input/output classes.
Game Rules: What Is Connect Four?
End Game Examples:
| - - - - - - - |
| - - - - - - - |
| - - - o x x - |
| - - o x x o - |
| - X X X X o - |
| - o o x o o - |
-----------------
1 2 3 4 5 6 7
| - - - - - - - |
| - - - - X - - |
| - - - o X x - |
| - - o x X o - |
| - - x x X o - |
| - o o x o o - |
-----------------
1 2 3 4 5 6 7
| - - - - - - - |
| - - - - o - - |
| - - - o X x - |
| - - o X x o - |
| - - X x x o - |
| - X o x o o - |
-----------------
1 2 3 4 5 6 7
| x o x o x o x |
| o x o x o x o |
| x o x o x o x |
| x o x o x o x |
| o x o x o x o |
| x o x o x o x |
-----------------
1 2 3 4 5 6 7
horizontal
winvertical
windiagonal
windraw
Really Pretty Online Example: Here is an online game with six rows and seven columns. The opponent is quite tough but beatable.
Requirements: Here's What will Get You Full Credit.
The Players Statistics File
Saved Games FilesHere is an example of stored information from a hypothetical a statistics file:
statistics.txt
--------------------
| |
| Ellen|13|6|2| |
| Marie|2|21|6| |
| Thomas|0|1|0| |
| |
--------------------
Here is an example of what could work:
myFirstGame.cnc4
----------------------
| |
| Ellen|*|turn| |
| Marie|&| |
| 6|7| |
| -|-|-|-|-|-|-| |
| -|-|-|-|-|-|-| |
| -|-|-|&|-|-|-| |
| -|-|-|*|*|-|-| |
| -|-|-|&|*|&|-| |
| -|*|-|&|&|*|-| |
| |
----------------------
Program Start
The Main Menu
Display Player Statistics
Start New Game
Continue Saved Game
Exit
Normal Game Play
| - - - - - - - |
| - - - - - - - |
| - - - - - - - |
| - - - - - - - |
| - - - - - - - |
| - - - - - - - |
-----------------
1 2 3 4 5 6 7
Style
Useful Classes: What you will and won't need.
Useful classes in the Java I/O package (import java.io.*):
One of the goals of this assignment
is for you to learn how to do console-based input/output.
One of the goals of this assignment
is for you to learn how to do basic array operations.Coding
Testing
At Home
Hints:
Hand-in Requirements:
Solution
arman@cs.wisc.edu
blbowers@cs.wisc.edu
seabold@cs.wisc.edu
thien@cs.wisc.edu
votruba@cs.wisc.edu
skrentny@cs.wisc.edu