SlideShare a Scribd company logo
1 of 6
Download to read offline
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
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.
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
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"
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.

More Related Content

Similar to Card Games in C++

Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdffeelinggifts
 
project 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docxproject 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docxbriancrawford30935
 
Here is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdfHere is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdftrishulinoverseas1
 
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdfHere is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdftrishulinoverseas1
 
FaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdfFaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdfabifancystore
 
Goal- Your goal in this assignment is to write a Java program that sim.pdf
Goal- Your goal in this assignment is to write a Java program that sim.pdfGoal- Your goal in this assignment is to write a Java program that sim.pdf
Goal- Your goal in this assignment is to write a Java program that sim.pdfaaicommunication34
 
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdfExercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdffms12345
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxamit657720
 
COMP 220 HELP Lessons in Excellence--comp220help.com
COMP 220 HELP Lessons in Excellence--comp220help.comCOMP 220 HELP Lessons in Excellence--comp220help.com
COMP 220 HELP Lessons in Excellence--comp220help.comthomashard85
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfeyelineoptics
 
Please use java to write the program that simulates the card game!!! T (1).pdf
Please use java to write the program that simulates the card game!!! T (1).pdfPlease use java to write the program that simulates the card game!!! T (1).pdf
Please use java to write the program that simulates the card game!!! T (1).pdfadmin463580
 
Introduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdfIntroduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdfcharanjit1717
 
COMP 220 Entire Course NEW
COMP 220 Entire Course NEWCOMP 220 Entire Course NEW
COMP 220 Entire Course NEWshyamuopeight
 
Description For this part of the assignment, you will create a Grid .pdf
Description For this part of the assignment, you will create a Grid .pdfDescription For this part of the assignment, you will create a Grid .pdf
Description For this part of the assignment, you will create a Grid .pdfformicreation
 
I received answers to 2 App requests and paid. The JAVA Apps are not.docx
I received answers to 2 App requests and paid. The JAVA Apps are not.docxI received answers to 2 App requests and paid. The JAVA Apps are not.docx
I received answers to 2 App requests and paid. The JAVA Apps are not.docxwalthamcoretta
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfanjandavid
 

Similar to Card Games in C++ (17)

Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
 
project 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docxproject 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docx
 
Here is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdfHere is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdf
 
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdfHere is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
 
FaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdfFaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdf
 
Goal- Your goal in this assignment is to write a Java program that sim.pdf
Goal- Your goal in this assignment is to write a Java program that sim.pdfGoal- Your goal in this assignment is to write a Java program that sim.pdf
Goal- Your goal in this assignment is to write a Java program that sim.pdf
 
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdfExercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
 
COMP 220 HELP Lessons in Excellence--comp220help.com
COMP 220 HELP Lessons in Excellence--comp220help.comCOMP 220 HELP Lessons in Excellence--comp220help.com
COMP 220 HELP Lessons in Excellence--comp220help.com
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
 
Please use java to write the program that simulates the card game!!! T (1).pdf
Please use java to write the program that simulates the card game!!! T (1).pdfPlease use java to write the program that simulates the card game!!! T (1).pdf
Please use java to write the program that simulates the card game!!! T (1).pdf
 
Introduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdfIntroduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdf
 
COMP 220 Entire Course NEW
COMP 220 Entire Course NEWCOMP 220 Entire Course NEW
COMP 220 Entire Course NEW
 
Description For this part of the assignment, you will create a Grid .pdf
Description For this part of the assignment, you will create a Grid .pdfDescription For this part of the assignment, you will create a Grid .pdf
Description For this part of the assignment, you will create a Grid .pdf
 
I received answers to 2 App requests and paid. The JAVA Apps are not.docx
I received answers to 2 App requests and paid. The JAVA Apps are not.docxI received answers to 2 App requests and paid. The JAVA Apps are not.docx
I received answers to 2 App requests and paid. The JAVA Apps are not.docx
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
 
quarto
quartoquarto
quarto
 

More from Programming Homework Help (8)

Java Assignment Help
Java  Assignment  HelpJava  Assignment  Help
Java Assignment Help
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
Family tree in java
Family tree in javaFamily tree in java
Family tree in java
 
Binary tree in java
Binary tree in javaBinary tree in java
Binary tree in java
 
Bank account in java
Bank account in javaBank account in java
Bank account in java
 
Mouse and Cat Game In C++
Mouse and Cat Game In C++Mouse and Cat Game In C++
Mouse and Cat Game In C++
 
Word games in c
Word games in cWord games in c
Word games in c
 

Recently uploaded

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Recently uploaded (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Card Games in C++

  • 1.
  • 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.