Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help creating the card game WAR in C++, with two players using Deck.h, main

ID: 3826105 • Letter: N

Question

Need help creating the card game WAR in C++, with two players using Deck.h, main.cpp, Card.cpp, Card.h, Deck.cpp: The rules are below and so are the source files:

The goal is to be the first player to win all 52 cards

The Deal: The deck is divided evenly, with each player receiving 26 cards, dealt one at a time, face down. Anyone may deal first. Each player places his stack of cards face down, in front of him.

The Play:Each player turns up a card at the same time and the player with the higher card takes both cards and puts them, face down, on the bottom of his stack.

If the cards are the same rank, it is War. Each player turns up one card face down and one card face up. The player with the higher cards takes both piles (six cards). If the turned-up cards are again the same rank, each player places another card face down and turns another card face up. The player with the higher card takes all 10 cards, and so on.

How to Keep Score: The game ends when one player has won all the cards.

Deck.cpp

Card.h

Card.cpp

main.cpp

Explanation / Answer

#include "card_games.h"

#include <iostream>

#include <ctime>

#include <cstdlib>

#include <cstdio>

#include <string>

using std::cin;

using std::cout;

using std::endl;

string StudPoker::deckFunction () {

srand(time(0));

struct card deck[52];

const string ranks[ ] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",

        "Nine", "Ten", "Jack", "Queen", "King" };

const string suits[ ] = { "Diamonds", "Hearts", "Spades", "Clubs" };

int k = 0;

for ( int i = 0; i < 13; i++)

{

for ( int j = 0; j < 4; j++)

{

deck[ k ].rank = ranks[ i ];

deck[ k ].suit = suits[ j ];

k++;

}

}

int RandIndex = rand() % 13;

int RandIndex2 = rand() % 4;

return ranks[RandIndex] + " of " + suits[RandIndex2];

}

void StudPoker::player1hand() {

}

main.cpp

#include <iostream>

#include "card_games.h"

using std::cin;

using std::cout;

using std::endl;

int main(int argc, char **argv)

{

StudPoker deckF;

cout << deckF.deckFunction() << endl;

return 0;

}

               

card_games.h

#ifndef HEADER_H

#define HEADER_H

#include <string>

using namespace std;

class StudPoker{

public:

string deckFunction();

void player1hand();

struct card{

string rank;

string suit;

int value;

};

private:

string ranks;

string suits;

};

#endif

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote