Using c++ For this program, The objective of this program is to create a game ca
ID: 3876226 • Letter: U
Question
Using c++ For this program, The objective of this program is to create a game called war in which two players who draw the highest card wins. If the two players draw a cards that has the same, then it's a tie. Afterwards, announce who won the game. The program needs to look exactly like the sample provided below.
The program should have two classes. Deck.h, Deck.cpp Card.h, Card.cpp
Here is a sample of the program.
One for me... [10 [*10] You Win!!!! Wanna play again? (no) Goodbye You will need to provide a menu with the following choices 1) Get a new card deck 2) Show all remaining cards in the deck 3) Shuffle 4) Play WAR! 5) Exit Things to consider You cannot continue the game if there are not enough cards in the deck. How are you going to shuffle? * You must show nice cards - the cards I showed are examples. Feel free to make yours better.Explanation / Answer
Crd.h
#ifndef CRD_H
#define CRD_H
class Crd {
public:
Crd();
Crd(int suites, int ranking);
void setCrd(int suites, int ranking);
int getVal();
void disp();
private:
int ranking;
int suites;
};
#endif
Deckss.cpp
#include <iostream>
using namespace std;
#include "Deckss.h";
#include "Crd.h";
#include <ctime>;
#include <stdlib.h>
Deckss::Deckss()
{
sz = 52;
int cntr = 0;
for (int uu = 0; uu < 4; uu++) {
for (int qq = 1; qq < 14; qq++) {
arr[cntr].setCrd(uu, qq);
cntr++;
}
}
}
Crd Deckss::dealing()
{
sz--;
Crd crdss = arr[sz];
return crdss;
}
void Deckss::shuffling()
{
srand(time(0));
int xx, yy;
for (int uu = 0; uu < sz; uu++) {
xx = rand() % sz;
yy = rand() % sz;
Crd c1 = arr[xx];
arr[xx] = arr[yy];
arr[yy] = c1;
}
}
int Deckss::remainingCards()
{
return sz;
}
void Deckss::dispDeck()
{
for (int uu = 0; uu < sz; uu++) {
arr[uu].disp();
}
}
Deckss.h
#include "Crd.h";
#ifndef DECKSS_H
#define DECKSS_H
class Deckss {
public:
Deckss();
Crd dealing();
void shuffling();
int remainingCards();
void dispDeck();
private:
Crd arr[52];
int sz;
};
#endif
main.cpp
#include <iostream>
using namespace std;
#include "Crd.h";
#include "Deckss.h";
#include <string>
#include <algorithm>
#include <io.h>
#include <fcntl.h>
void startGame(Deckss decks1) {
cout << "Get ready to play WAR!!!" << endl;
bool tryGame = true;
while (tryGame) {
cout << "There are " << decks1.remainingCards() << " Crd in the Deckss." << endl;
cout << "...dealing..." << endl;
cout << "One for you..." << endl;
Crd playa1 = decks1.dealing();
playa1.disp();
cout << "One for me..." << endl;
Crd playa2 = decks1.dealing();
playa2.disp();
if (playa1.getVal() > playa2.getVal()) {
cout << "You Win!!!" << endl;
}
else if (playa1.getVal() < playa2.getVal()) {
cout << "uu Win!!!" << endl;
}
else {
cout << "It's xx Tie!!!" << endl;
}
cout << endl << "Wanna play again? (yes/no)" << endl;
string ch;
cin >> ch;
transform(ch.begin(), ch.end(), ch.begin(), ::tolower);
string aa = "yes";
string bb = "no";
if (ch == aa) {
tryGame = true;
if (decks1.remainingCards() == 0) {
cout << "startGame Over!!!" << endl
<< "Goodbye" << endl;
tryGame = false;
}
}
else if (ch == bb) {
tryGame = false;
cout << endl << "Goodbye" << endl;
}
else if (ch != aa || ch != bb) {
cout << "Invalid input" << endl;
bool invalid = true;
while (invalid) {
cin >> ch;
if (ch == aa) {
invalid = false;
}
else if (ch == bb) {
invalid = false;
tryGame = false;
cout << "Goodbye" << endl;
}
}
}
}
};
void dispMenu() {
cout << "1) Get xx new Crd Deckss" << endl;
cout << "2) Show all remaining cards in the Deckss" << endl;
cout << "3) shuffling" << endl;
cout << "4) Play WAR!" << endl;
cout << "5) Exit " << endl;
};
int main() {
int userCh;
bool wCh = true;
Deckss decks1;
while (wCh) {
dispMenu();
cin >> userCh;
switch (userCh) {
case 1:
cout << "New Crd Deckss created" << endl;
break;
case 2:
decks1.dispDeck();
break;
case 3:
decks1.shuffling();
decks1.dispDeck();
break;
case 4:
startGame(decks1);
break;
case 5:
cout << "Goodbye" << endl;
wCh = false;
break;
}
}
system("PAUSE");
return 0;
}
Crd.cpp
#include <iostream>
using namespace std;
#include "Crd.h";
#include <string>
Crd::Crd()
{
ranking;
suites;
}
Crd::Crd(int s, int r)
{
ranking = r;
suites = s;
}
void Crd::setCrd(int s, int r)
{
ranking = r;
suites = s;
}
int Crd::getVal()
{
return ranking;
}
void Crd::disp()
{
string dispStrings;
dispStrings.append(" ");
string dispDesign;
switch (ranking) {
case 11: dispStrings.append("Jack");
break;
case 12: dispStrings.append("Queen");
break;
case 13: dispStrings.append("King");
break;
case 1: dispStrings.append("Ace");
break;
default: dispStrings.append(to_string(ranking));
break;
}
dispStrings.append(" of ");
switch (suites) {
case 0: dispStrings.append("Spades");
switch (ranking) {
case 10:
dispDesign.append(" ------- [10 ] [ * ] [ * * ] [ * * ] [ * * ] [ * ] [ 10] ------- ");
break;
case 11:
dispDesign.append(" ------- [qq ] [ * ] [ * * ] [ ***** ] [* * *] [ * ] [ qq] ------- ");
break;
case 12:
dispDesign.append(" ------- [Q ] [ * ] [ * * ] [ ***** ] [* * *] [ * ] [ Q] ------- ");
break;
case 13:
dispDesign.append(" ------- [K ] [ * ] [ * * ] [ ***** ] [* * *] [ * ] [ K] ------- ");
break;
case 1:
dispDesign.append(" ------- [xx ] [ * ] [ * * ] [ ***** ] [* * *] [ * ] [ xx] ------- ");
break;
default:
dispDesign.append(" ------- [" + to_string(ranking) + " ] [ * ] [ * * ] [ ***** ] [* * *] [ * ] [ " + to_string(ranking) + "] ------- ");
break;
}
break;
case 1: dispStrings.append("Hearts");
switch (ranking) {
case 10: dispDesign.append(" ------- [" + to_string(ranking) + " ] [ ** ** ] [* * *] [ * * ] [ * * ] [ * ] [ " + to_string(ranking) + "] ------- ");
break;
case 11: dispDesign.append(" ------- [qq ] [ ** ** ] [* * *] [ * * ] [ * * ] [ * ] [ qq] ------- ");
break;
case 12: dispDesign.append(" ------- [Q ] [ ** ** ] [* * *] [ * * ] [ * * ] [ * ] [ Q] ------- ");
break;
case 13: dispDesign.append(" ------- [K ] [ ** ** ] [* * *] [ * * ] [ * * ] [ * ] [ K] ------- ");
break;
case 1: dispDesign.append(" ------- [xx ] [ ** ** ] [* * *] [ * * ] [ * * ] [ * ] [ xx] ------- ");
break;
default: dispDesign.append(" ------- [" + to_string(ranking) + " ] [ ** ** ] [* * *] [ * * ] [ * * ] [ * ] [ " + to_string(ranking) + "] ------- ");
break;
}
break;
case 2: dispStrings.append("Diamonds");
switch (ranking) {
case 10:
dispDesign.append(" ------- [10 ] [ * ] [ * * ] [ * * ] [ * * ] [ * ] [ 10] ------- ");
break;
case 11:
dispDesign.append(" ------- [qq ] [ * ] [ * * ] [ * * ] [ * * ] [ * ] [ qq] ------- ");
break;
case 12:
dispDesign.append(" ------- [Q ] [ * ] [ * * ] [ * * ] [ * * ] [ * ] [ Q] ------- ");
break;
case 13:
dispDesign.append(" ------- [K ] [ * ] [ * * ] [ * * ] [ * * ] [ * ] [ K] ------- ");
break;
case 1:
dispDesign.append(" ------- [xx ] [ * ] [ * * ] [ * * ] [ * * ] [ * ] [ xx] ------- ");
break;
default:
dispDesign.append(" ------- [" + to_string(ranking) + " ] [ * ] [ * * ] [ * * ] [ * * ] [ * ] [ " + to_string(ranking) + "] ------- ");
break;
}
break;
case 3: dispStrings.append("Clubs");
switch (ranking) {
case 10:
dispDesign.append(" ------- [10 ] [ * ] [* * *] [ *** ] [ * ] [ * ] [ * 10] ------- ");
break;
case 11:
dispDesign.append(" ------- [qq ] [ * ] [* * *] [ *** ] [ * ] [ * ] [ * qq] ------- ");
break;
case 12:
dispDesign.append(" ------- [Q ] [ * ] [* * *] [ *** ] [ * ] [ * ] [ * Q] ------- ");
break;
case 13:
dispDesign.append(" ------- [K ] [ * ] [* * *] [ *** ] [ * ] [ * ] [ * K] ------- ");
break;
case 1:
dispDesign.append(" ------- [xx ] [ * ] [* * *] [ *** ] [ * ] [ * ] [ * xx] ------- ");
break;
default:
dispDesign.append(" ------- [" + to_string(ranking) + " ] [ * ] [* * *] [ *** ] [ * ] [ * ] [ * " + to_string(ranking) + "] ------- ");
break;
}
break;
}
cout << dispStrings
<< dispDesign << endl;
}
Rate an upvote......Thankyou
Hope this helps.....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.