This is a programshowing the use of a card game in which player’s place cards in a grid on
the table.The cards show different animals in between 1 to 4, where each quarter of the card
can have a different animal. Each player gets a secret animal. The secret animal is a
player's favorite.Theplayer's goal is to getseven animal cards showing this player's secret
animal connected on the table.
2. A Cardgame
This is a programshowing the use of a card game in which player’s place cards in a grid on
the table.The cards show different animals in between 1 to 4, where each quarter of the card
can have a different animal. Each player gets a secret animal. The secret animal is a
player's favorite.Theplayer's goal is to getseven animal cards showing this player's secret
animal connected on the table. There is a joker and the start card that may replace any
animal card. There are five different animals like bear, deer, hare, moose, and wolf. These
cards can only be placed if atleast one match exists. The cards needsto be arrangedin rows
and columns and no offsets are allowed. The cards may be turned 180 degrees but not 90
degrees. For a card to place legally at least one quarterhas to match with one of the
neighboring cards.Thereis also a joker, besides the 50 animal cards in the game, which
matches any animal card. There is also a start card. Thereare 15 action cards in
addition,which shows a single animal but also trigger an action. Action cards shouldbeplaced
on top or the bottom of the stack at the start card.
Initially when the game starts, the start card is placed on the table as the only card and each
player is givena secret animal (bear, deer, hare, moose or wolf) at random, along with three
animal cards, includingaction cards and joker. The players take turns. At each turn, a player
draws a card from the deck of theremaining animal cards. Then the player places a card on
the table. If the player plays an action card and places it at the bottom of the stack, the
action isperformed next. An animal card on the table can be matched with each of its
quarters with a horizontal orvertical neighbor, but diagonally matches are not allowed.
The implementation of the game is in a console mode, which requires the following container
classes: Table, Deck,Hand and StartStack. The code is as follows:
1)
#include <iostream>
class Table {
intaddAt(std::shared_ptr<AnimalCard>, int row, int col);
Table& operator+=(std::shared_ptr<ActionCard> );
Table& operator-=(std::shared_ptr<ActionCard> );
std::shared_ptr<AnimalCard>pickAt(int row, int col);
bool win( std::string& animal );
};
The class Table implements a four-connected graph holding each
AnimalCardwithstd::shared_ptr. The graph will be stored in a two-dimensional array of a
std::shared_ptrto the AnimalCardat thelocation of a given row and column.
intaddAt(std::shared_ptr<AnimalCard>, int row, int col)adds anAnimalCardat a given
row, column index if it is a legal placement. It will return an integer between 1and 4 indicating
3. how many different animals can be matched between the current card and its neighbors.It
will return 0 and if no valid match is found it will not add the card to the Table.
Table& operator+=(std::shared_ptr<ActionCard> )places a copy of the action card on the
top of the StartStackin Table.
Table& operator-=(std::shared_ptr<ActionCard> )places a copy of the action cardon the
bottom of the StartStackin Table.
std::shared_ptr<AnimalCard>pickAt(int row, int col)removes an AnimalCardat a given
row, column index from the table.
bool win( std::string& animal )Returns true if the animal in the string has won. Ananimal
wins as soon as there are seven matching animal cards including the joker and action cards.
2)
#include <iostream>
#include <vector>
class Deck : std::vector<int> {
std::shared_ptr<T>draw();
};
Deck is simple derived class from std::vector and is atemplate by type.
std::shared_ptr<T>draw()returns and removes the top card from the deck.
3)
#include <iostream>
#include <list>
class Hand : std::list<int> {
Hand& operator+=(std::shared_ptr<AnimalCard>);
Hand& operator-=(std::shared_ptr<AnimalCard>);
std::shared_ptr<AnimalCard>operator[](int);
intnoCards();
};
Hand& operator+=(std::shared_ptr<AnimalCard>)adds a pointer to the AnimalCard to the
hand.
Hand& operator-=(std::shared_ptr<AnimalCard>) removes a card equivalent to the
argument from the Hand. Anexception MissingCardis thrown if the card does not exist.
std::shared_ptr<AnimalCard>operator[](int)returns the AnimalCardat a givenindex.
intnoCards()returns the number of cards in the hand.
4)
#include <iostream>
#include <deque>
classStartStack : std::deque<int> {
StartStack& operator+=(std::shared_ptr<ActionCard> );
StartStack& operator-=(std::shared_ptr<ActionCard> );
std::shared_ptr<StartCard>getStartCard();
};
The StartStackis derived from AnimalCard. The card on the top of the aggregated std::deque
determines the behavior of the card. The class has the following functions.
StartStack& operator+=(std::shared_ptr<ActionCard> )places a copy of the action card
on top and implicitly changes theStartStackbehaviour as an AnimalCard.
StartStack& operator-=(std::shared_ptr<ActionCard> )places a copy of theaction card on
the bottom which does not change how StartStackbehaves as an AnimalCard.
std::shared_ptr<StartCard>getStartCard()returns a shared pointer to the start card.
4. The default constructor should create a StartStackthat holds only the StartCard.
Inheritance concept is used with the animal cards with an abstract base class AnimalCard.
#include <iostream>
classAnimalCard {
virtual void setOrientation( Orientation );
virtual void setRow( EvenOdd );
virtualEvenOddgetRow();
virtual void printRow( EvenOdd );
};
In this class the working functions for the above class is as follows.
virtual void setOrientation( Orientation )is responsible for changing the orientation of the
animal card.Orientation is an enumeration with two values UP and DOWN, effectively
rotating the card by 180 degrees.
virtual void setRow( EvenOdd )changes the print state for the current card. EvenOddis
a scoped enumeration with the three values EVEN, ODD and DEFAULT. EVEN should set
the next row tobe printed the top row while ODD means the next row to be printed will be the
bottom row. DEFAULT will keep the state unchanged.
virtualEvenOddgetRow()returns the state of the next row to be printed.
virtual void printRow( EvenOdd )prints two characters for the specified row. An argument
ofDEFAULT will use the state of the AnimalCard.
Fourdifferent derived classes NoSplit, SplitTwo, SplitThreeand SplitFourrepresenting the
corresponding number of animals on the card. The code is as follows:
1) No Split
#include <iostream>
#include "AnimalCard.cpp"
classNoSplit : public AnimalCard{
};
2) Split Two
#include <iostream>
#include "AnimalCard.cpp"
classSplitTwo : AnimalCard{
};
3) Split Three
#include <iostream>
#include "AnimalCard.cpp"
classSplitThree : AnimalCard{
};
4) Split Four
#include <iostream>
#include "AnimalCard.cpp"
classSplitFour : AnimalCard{
};
The derived classes NoSplit, SplitTwo, SplitThreeand SplitFourwill have to be concrete
5. classes.
A separate Joker and StartCardclass will need to be be created. They are:
1) Joker class
#include <iostream>
#include "NoSplit.cpp"
class Joker : public NoSplit{
};
2) StartCard class
#include <iostream>
classStartCard {
};
The derived classes Joker and StartCardwill have to be concrete classes derived from
NoSplit.
The abstract ActionCardclass will have to be derived from StartCard. The class adds the
pure virtual function.
#include <iostream>
#include "StartCard.cpp"
classActionCard : public StartCard{
virtualQueryResult query();
virtual void perfom( Table&, Player*, QueryResult );
};
virtualQueryResult query()will display the action on the console and query the player for
input if needed. Returns a QueryResult object storing the result.
virtual void perfom( Table&, Player*, QueryResult )will perform theaction with the user
input stored in QueryResult.
The classes BearAction, DeerAction, HareAction, MooseActionand WolfActionwill implement
this function. Action cards print themselves in capital letters.
The abstract ActionCardclass will have five concrete children: BearAction,DeerAction,
HareAction, MooseActionand WolfAction. They are as:
1) BearAction
#include <iostream>
#include "ActionCard.cpp"
classBearAction : ActionCard{
};
2) DeerAction
#include <iostream>
#include "ActionCard.cpp"
classDeerAction : ActionCard{
};
3) HareAction
#include <iostream>
#include "ActionCard.cpp"
6. classHareAction : ActionCard{
};
4) MooseAction
#include <iostream>
#include "ActionCard.cpp"
classMooseAction : ActionCard{
};
5) WolfAction
#include <iostream>
#include "ActionCard.cpp"
classWolfAction : ActionCard{
};
This is one of our samples coding from our experts at programming homework help. We also
provide solutions of several such assignments coding to the students meeting the deadline.
Our experts are the most qualified and experienced in their respective field that are capable
to provide assignment solutions as per the need of the problems.