Back to 111 Main Page

Mobius strip

Assignment 16

Task

Bring together everything you've learned this semester into a final project: write a simple two-player game.

Requirements

You may pick which game you write. However, it needs to meet these requirements:

  • 2-player. The game must involve only two players, and one of those players must be the computer. This means your program must make all the second player's moves. You may make these moves randomly if necessary.
  • Standard rules. The game should be some semi-standard/traditional, recognizable card game, pen-and-paper game, simple board game, or playground game, not some game you just made up. Your game might follow certain variant rules, however.
  • Significant user choices. Your game should require input from the user, and this input should have an impact on the outcome on the game. The choice may be as simple as picking a number between 1 and 10 though.
  • Game mechanics handled appropriately. Your game needs to set everything up correctly, get the input from the user, etc. Most importantly, it needs to recognize when the game has concluded and declare who won. Ideally, it will then ask the user if they want to play again.

Keep in mind you will probably only have text output to work with. (If you want, you can construct a GUI interface, but there will be no extra credit for it. See EC1 if you want extra credit for making a GUI.)

Internally, your program needs to also include the following:

  • At least one loop and one conditional.
  • User input.
  • At least 3 different methods. Constructors and main count as methods for this purpose. (Ideally, your program will include multiple classes as well. Some games are not as good candidates for this as others, though, so multiple files are not required.)
  • A collection. That is, you need to use at least one array or ArrayList.
  • No runtime crashes. This means you need to handle any kind of input. Your program should probably loop until it gets the correct info it needs, though it may quit gracefully if necessary.

Your game should also (briefly) explain to the user how to play when it starts.

Possible Games

Some games are harder than others so, before you pick one, spend some time sketching out the steps you're going to need to implement to get the job done.

Here are most of the games people are doing:

Steps for Old Maid

If you're stuck, consider the following design for Old Maid.

PlayingCard

Write a PlayingCard class that holds a value and suit. (Based on the suit, you can also determine the color.) You will need the appropriate constructor, accessor and mutator methods, and toString.

Deck (Optional)

If you wanted to reused your Deck class from A13, you could.

OldMaid

In main: First, explain the rules to the player.

Create a new Deck of 52 shuffled cards. (If you're not using Deck, then just create an ArrayList of cards instead.)

Deal the cards out into two hands (that is, into two ArrayList<PlayingCards>s). You don't need to alternate between hands as you deal; you can just draw 26 cards for one hand, and then 26 for the other. While dealing, if you draw the Queen of Clubs, discard it. (This technique means you don't need to go find the Queen before dealing, and that each hand has an equal chance of being the smaller hand.)

Now go through both hands and remove all pairs--cards with the same value and same color. (This is the hardest part.) Let the user know which pairs were discarded from both hands by this process.

Now the game can start. Show the player their hand. (There's not much they can do with it, though, so you might just want some sort of one-line representation.) Tell them how many cards their opponent has, and let them pick a number between 1 and that number. (This is the card they are drawing from their opponent's hand.) Match and discard the pair this forms.

Then have the computer player randomly pick a card from the player's hand. Again, report what card this was and what discarded pair was formed.

Repeat the previous two blocks--the player drawing and then the computer drawing--until one of the players runs out of cards. The other player should then be holding the Queen of Spades (the Old Maid) and is the loser.

Note: Though possible, this program will be tricky to write if all of this is main. Try to look for things you could break out into methods. For instance, you could write a private static method that takes an ArrayList hand and a PlayingCard to match, and then finds, removes, and returns the matching card (if any) found in the hand.

Design Summary

By noon on 29 Apr 2008, send me a summary of what game you're planning to implement. Include:

  • Name of the game
  • Clear description/rules of the game (a link is preferred)

If you'd also like to include more information--such as what collections you're planning to use, how you plan to break the problem down into classes and methods, etc--I will try to give you some feedback on your design or what problems might be tricky to handle. Don't send me code at this point though.

If you're doing Old Maid as described above, then you just need to send me the name of the game.

Sending me this information before the deadline will get you 1 point of extra credit.

What to submit

Attach all files needed to run your program to an email. This will be a studio project, so please include your name as part of all class names.

FAQs

For some of these card games, it'd be nice to have a working PlayingCard and Deck. Can we see a solution for Assignment 13?
Okay. My solution to A13 is now posted.
For games like Old Maid and Go Fish, how do you find all the pairs in a hand?
I would first write a method that takes a hand and a card to match. Something like this:
  private static PlayingCard findMatch(ArrayList<PlayingCard> hand,
                                       PlayingCard toMatch) {
In this method, you would loop through the hand, looking for a card that forms a pair with toMatch. If you find such a card, remove it from the hand and return it. If you can't find any matching card, return null instead. This method can now be used everytime a player draws a card to check if that card matches anything already in their hand.

At the start of the game, you need to find all pairs already in the player's opening hand. To do that, I would loop card-by-card through their hand. Temporarily remove the current card, and call the above method with the rest of the hand and the removed card to see if there's a matching card somewhere else in the hand. If not, put the card back in the hand and remove the next card. Basically, you're going card-by-card through the player's hand to see if there is a matching card somewhere else in the hand.

Grading

Out of 20 points:

% - Game choice
2 player game, computer is a player, game with established rules, significant user choices. (-25% of your final grade for each one missing.)
2 - Submission and Coding Standards
Follows required submission policies and coding standards.
2 - Compiles
1 - Instructions
It is clear how to play the game.
4 - Required components
At least one loop and conditional, some collection (array or ArrayList), user input, and at least 3 different methods.
6 - Completeness
The game is finished and all parts work. Output is clear and understandable.
3 - Correctness
The game performs correctly (when given correct input).
2 - Robustness
The program does not crash or misbehave if given incorrect input.
+1 - Design summary
Due by noon on 29 Apr 2008.


~ztomasze Index : TA Details: ICS111: Assignment 16
http://www2.hawaii.edu/~ztomasze
Last Edited: 22 May 2008
©2008 by Z. Tomaszewski.