Homework 4, Concentration.
Short Description:
Write a program to play the concentration card game.
Goals
When you finish this homework, you should have:
- Written multiple templated classes and functions.
- Built a program that uses class composition.
Formal Description
Implement the game of concentration.
- The game should be implemented as a templated class and employ templated classes.
- I hate this style, but it should look something like this:
-
int main() {
ArrayT<BaseT> deck;
// note: row * col must be even
// note the deck must have an even number of each type of card.
// code to initialize a deck of row*col cards.
...
ConcentrationT game<BaseT>(rows, cols, players, deck);
game.Play();
game.Report();
return 0;
}
Your game should use:
- The ArrayT class from the lectures.
- I don't think that we have any bugs, but you should make sure that it is working well before the due date.
- It should use your 2d array class, Array2T (required class name)
- Is should be templated to hold any type of data
- It should have the following methods (note, some of the prototypes will need to be altered to use templates).
- Default constructor, copy constructor, overloaded assignment operator, and destruct.
- Parameterized constructor
Array2T(size_t rows, size_t cols)
-
size_t Rows() const;
that returns the number of rows.
-
size_t Cols() const;
that returns the number of columns.
-
T & operator[] (size_t r, size_t c)
that returns a reference to the item at position ary[r, c].
- A class
CardT
that is templated to hold any data type.
- This is essentially a card in the game.
- You should be able to set and get the value of the card
- You should be able to set and get if the card is face up or face down.
- You should make at least one game that uses each of the following data types (ie StringGame.cpp, IntGame.cpp, AbilityGame.cpp). But there should be very little variation in these games other than initializing the deck.
- String, with a list of words of your choice.
- AbilityT.
- Integers.
The game should begin by presenting the rows x columns matrix on the screen all cards face down. Assume the type is integer and the game is 3 rows by 2 columns
0 1
0 x x
1 x x
2 x x
In turn, each player should be asked for a valid row and column number, for the first and second card. Do not accept row and column numbers that are out of bounds and do not accept a combination for a card that is face up.
As a card is selected, "flip" it to display the value. Assume that the player selected 0,0, which has a value of 7
Enter a card: 0,0
0 1
0 7 x
1 x x
2 x x
A
If cards match in a turn, give the player a point and allow the player to continue until either they do not match a pair of cards or all cards are exposed. Assume the player selected 2,1 which also has a value of 7.
Enter a card: 2,1
0 1
0 7 x
1 x x
2 x 7
The cards match, you get a point.
If the cards do not match, turn the cards back over and pass control to the next player. Assume the player picked (0,1) and (1,1) which held a 4 and 2.
Enter a card: 0,1
0 1
0 7 4
1 x x
2 x 7
Enter a card: 1,1
0 1
0 7 4
1 x 2
2 x 7
The cards do not match.
0 1
0 7 x
1 x x
2 x 7
Enter a card:
If you wish, you may add additional parameters (such as display width to control the display of each card.) These should be controlled by appropriate getters and setters.
You may assume that the underlying data type has the following functions:
Discussion
- Everything should be performed in a object oriented manner with classes and compositions.
- I understand that you could do all of this without classes and templates, but that is the purpose of this exercise.
- Programs that do not use classes and templates are worth nothing and will be awarded corresponding credit without the possibility of redo.
- I have not written this code, so you should start early and look for specification problems.
- You should have a basic design within one week.
- You should work on the basic classes in parallel with design
- Templatize your 2d array class and test that.
- Make your card class work and test that.
- You should have test drivers for your classes as you develop them.
- You should develop the lowest level classes, test them, then develop the higher level classes.
- Your game should have sufficient verbiage to allow the player (or grader) to follow what is happening. There is no standard, but it should be informative.
Required Files
A single tar file containing the source code and makefile for this program.
Submission
Submit the assignment to the D2L folder homework 4 by the due date.