I have a code. It's a code for a card game. The problem is that cards should be distributed to game players, but they are not duplicated.
If it's possible, I need your help. Thank you.
#include<iostream>
#include<array>
#include<string>
#include<ctime>
using namespace std;
class Card {
public:
static const size_t card1{ 4 };
static const size_t card2{ 13 };
Card(const array<string, card1>& card1n,
const array<string, card2>& card2n)
: arr1{ card1n }, arr2{ card2n } {}
void disPlay() {
for (int x = 0; x < arr2.size(); x++) {
int i = rand() % 4;
int j = rand() % 13;
cout << arr1[i] + arr2[j] << " ";
}
}
private:
array<string, card1> arr1;
array<string, card2> arr2;
};
int main() {
array<string, Card::card1> arr1{ "♥","◆","♠","♣" };
array<string, Card::card2> arr2{ "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king" };
Card p1(arr1, arr2);
Card p2(arr1, arr2);
srand(static_cast<unsigned int>(time(0)));
cout << "player1's deck : ";
p1.disPlay();
cout << "\nplayer2's deck : ";
p2.disPlay();
}
I predict players with overlapping cards
Aucun commentaire:
Enregistrer un commentaire