how to create a card pack.

hey guys. i'm new to c++. i've only learned about the basics of c++. so i've been given the task of creating a card game. the card consists of 55 cards that has 1x1s, 2x2s, 3x3s up to 10x10s. where and how should i create it?

game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  #include<iostream>
#include <string>
#include<vector>
#include <fstream>
#include "Player.h"
#include "Card.h"
using namespace std;

void gameMenu();
void gameRules();
void gameStart();
void gamePlay(vector <Player>& );
void printPlayers(vector <Player>&);


int main()
{
	gameMenu();

	return 0;
}

void gameMenu()
{
	cout << "Welcome to Pairs " << endl;
	cout << "Select Menu Option " << endl;
	cout << "1. Game Rules" << endl;
	cout << "2. Play Game " << endl;

	int num;
	cin >> num;

	switch (num)
	{
	case 1:
		gameRules();
		break;
	case 2:
		gameStart();
		break;
	default:
		cout << "invalid " << endl;
	}

	system("pause");
	system("CLS");
}

void gameRules()
{
	cout << "Here are the basic rules of the game" << endl;

	string line;
	fstream rulesFile;
	rulesFile.open("Gamerules.txt");

	if (rulesFile.is_open())
	{
		{
			while (getline(rulesFile, line))
			{
				cout << line << endl;
			}
		}
	}
	rulesFile.close();

	system("pause");
	system("CLS");

	gameMenu();
}

void gameStart() {
	vector <Player> playerclass;
	gamePlay (playerclass);
	printPlayers(playerclass);
}
void gamePlay(vector <Player>& newPlayerclass)
{
	cout << "How many players in the game?" << endl;
	int x;
	cin >> x;

	for (int i = 0; i < x; i++) {
		string n;
		int p=0;
		cout << "Enter name: " << endl;
		cin >> n;

		Player newPlayers(n,p);
		newPlayerclass.push_back(newPlayers);
	}
	
	system("pause");
	system("CLS");

}

void printPlayers(vector <Player>& newPlayerclass) {
	
	unsigned int y = newPlayerclass.size();
	for (unsigned int i = 0; i < y; i++) {
		cout << newPlayerclass[i].getName() << "      " <<newPlayerclass[i].getPoints() << endl;
	}

	system("pause");
	system("CLS");
}

void gameRound(vector <Player>& newPlayerclass, int value) {

	int sum = value;


}


player.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include<iostream>
#include "Player.h"
using namespace std;

Player::Player(){
}

Player::Player(string name , int points) {
	playerName = name;
	playerPoints = points;
}

string Player::getName(){
	return playerName;
}

void Player::setName(string name){
	playerName = name;
}

int Player::getPoints(){
	return playerPoints;
}

void Player::setPoints(int points){
	playerPoints = points;
}


player.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef PLAYER_H
#define PLAYER_H

#include<string>
using namespace std;

class Player
{
private:
	string playerName;
	int playerPoints;

public:
	Player();
	Player(string name, int points);
	string getName();
	void setName(string name);
	int getPoints();
	void setPoints(int points);
}; 


#endif 
Last edited on
You have
- a card, which has a value 1 to 10

- a deck of cards, 55 in total, with varying face values

- a hand, some small set of the deck

- a player, each of whom has say a name (Bob) and a hand

- a game, some group of players, and a deck of cards.

So somewhat tersely
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Card {
  int value;
};

class Deck {
  vector<Card> deck(55);
  Deck(); // consists of 55 cards that has 1x1s, 2x2s, 3x3s up to 10x10s
  void Shuffle();  // randomise order of deck
  Card Deal(); // return next card from deck
}

class Hand {
  vector<Card> cards(3);  // how many can each player have?
};

class Player {
  string name;  // Bob
  Hand hand;  // has some cards to play
  void takeCard(Card);  // adds a card to their hand
};

class Game {
  Deck deck;  // the cards
  vector<Player> players(6);  // how many players?
  void PlayTheGame();
};


Eg, shuffling the deck and dealing cards to each player.
1
2
3
4
5
6
7
8
void PlayTheGame() {
  deck.shuffle();
  for ( p : players ) {
    for ( c = 0 ; c < 3 ; c++ ) {
      p.takeCard(deck.Deal());
    }
  }
}


You can use a vector to create the card deck like
 
vector<int> deck = {1,2,2,3,3... etc up to 10} 

and use the functions of the vector to burn the cards and rest of the requirements :)
You can check out my card class here. https://www.cplusplus.com/forum/beginner/270551/

It creates a shuffled deck of regular 52 card deck. Maybe give you some ideas. Not exactly noob friendly but not too bad.
Topic archived. No new replies allowed.