SlideShare ist ein Scribd-Unternehmen logo
1 von 6
Downloaden Sie, um offline zu lesen
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.

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Kürzlich hochgeladen

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
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Kürzlich hochgeladen (20)

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 ...
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
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"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

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.