Homework 4, Concentration.
Short Description:
Implement the support classes for a game project.
Goals
When you finish this homework, you should have:
- Worked with smart pointers.
- Worked with various advanced aspects of classes.
Formal Description
Create the code to support a game board class.
For this project, we will implement a non-templated game board. While templating is probably the way to go, I would like to keep this stage more simple. We will modify this game board in the last assignment.
In general we will be implementing a Concentration style card game. In this game, 2n cards are placed face down in a rectangular pattern. Players take turns "flipping" two cards. If the cards match, the player removes the cards, scores a point and takes another turn. The game continues until all pairs of cards are removed. In the sample implementation, there is no scoring or record of turns. If you wish, you may add this aspect to the game.
You are to implement the following classes. You should use the header files provided. You may not change these files.
- SuiteT as defined in SquareT.h
- This is a strongly typed enumeration
- It represents the suites of a card.
- Implement the functions
- SuiteTToString Converts a SuiteT to a string, as named in SUITE_NAMES
- StringToSuiteT Converts a string, as named in SUITE_NAMES to a SuitT. Case should not matter.
- CardT as defined in SquareT.h
- This represents the cards in the game. It has no game logic, it is just a card.
- The constructor can take parameters, the valures of card you want to build.
- But there are default parameters.
- Do not declare these in the implementation header.
- Random will set the card to a random value.
- Again, a default parameter is given.
- Do not list this in the implementation file.
- == must be implemented.
- Value returns the value of the card
- Suite returns the suite of the card.
- SquareT as defined in SquareT.h
- SquareT represents a square in the board game.
- It contains logic for playing the game
- Ie flipping cards, checking to see if cards are present.
- SetCard places a card in the square.
- Flip changes the card from face up to face down or face down to face up.
- IsFaceUp reports the state of the card.
- HasCard reports if a card is present or not.
- GetCard returns the card stored in the square
- RemoveCard marks the card as not present.
- DirT is defined in CoordT.h
- This is a way to indicate the direction something on the board wishes to move.
- This is a structured enumerated type.
- DirTToString converts a DirT to the corresponding String in DIRECTION_NAMES
- StringToDirT converts a string, regardless of case to a corresponding DirT
- NextDir steps through the DirT, up is followed by down, down is followed by left, ... back is followed by none, none is followed by none.
- CoordT is defined in CoordT.h
- This class represents the coordinates on a board.
- Note the BoardT reference as member data.
- You need to be careful with this.
- Assign on construction.
- Does not get copied, so =, copy constructor and others must be implemented or dealt with carefully.
- Implement a constructor and a copy constructor and assignment operator.
- X and Y return the corresponding width and height.
- Change and set allow the user to change the coordinate.
- These should call the underlying board functions. The coordinate class SHOULD NOT implement any board logic.
- SuccessfulChange should be true if the change was successful or false if not.
- This should be set by the board class, not by the Coordinate class.
- Note, the board class is listed as a friend of this class.
- This means that instances of the board class can change values in this class.
- IE correctly set x, y and error.
- As well as create instances of this class.
- BoardT is defined in BoardT.h
- This is the game board.
- Note, this is implemented as a dynamic one dimensional array
- Which is stored in a unique pointer.
- It has a constructor. Again, don't repeat the default parameters in the implementation file.
- The constructor is used to set the width and height of a board.
- The assignment operator and the copy constructor have been disabled.
- It has both versions of the [] operator.
- It has a Width and Height function that return the width and height of the board.
- It has two functions for creating a coordinate
- NewCoord sets the coordinate, to a given value, but only if the given values are valid.
- ChangeCoord moves the coordinate in the given direction, but only if valid.
- Both set the success value of the coordinate
- Both return a coordinate
- CoordToPos is a private member function that converts the two dimensional coordinate to a one dimensional index in the array.
The following files are also supplied
Notes
- You must use the supplied header files.
- You must use the compile flags specified in the makefile
- You must make extensive use of ctor initializers.
- Your code must compile without errors or warnings with the supplied header files and game implementation.
- I have not tested the implementation as much as I should. There may be errors. Please let me know if you discover any.
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.