-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
114 lines (91 loc) · 2.19 KB
/
main.cpp
File metadata and controls
114 lines (91 loc) · 2.19 KB
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
#include "func.h"
int main()
{
int row,
col,
p1Score = 0,
p2Score = 0,
scorePool = 0;
std::string player1, player2, turn;
std::map<int, int> gameboardMap; // Used to map card position to a gameboard index
std::vector<int> indexV;
indexV.push_back(-1);
indexV.push_back(-1);
char gameboard[20];
bool cardPickedState = true;
// Maps the board to index
fillMap(gameboardMap);
// Shuffle function, fills gameboard with random characters
shuffleBoard(gameboard);
// Asking for player names
std::cout << "Name of player 1:";
std::cin >> player1;
std::cout << "Name of player 2:";
std::cin >> player2;
// Set turn to player1
turn = player1;
// Gameloop keeps game running
while (true)
{
// Render gameboard
renderGameboard(gameboard, indexV);
// Asks for first card
std::cout << "\n"
<< turn
<< ", first card flip: ";
std::cin >> row >> col;
// Flips card
flipCard(row,
col,
gameboardMap,
indexV,
cardPickedState);
// Render gameboard with asked position
renderGameboard(gameboard, indexV);
std::cout << "\n"
<< turn
<< ", second card flip: ";
std::cin >> row >> col;
// Flips the second card
flipCard(row,
col,
gameboardMap,
indexV,
cardPickedState);
// Render gameboard with second asked position
renderGameboard(gameboard, indexV);
// If the characters are matching
if (gameboard[indexV[0]] == gameboard[indexV[1]])
{
std::cout << "\nPOINT FOR " << turn << "\n";
// Remove picked cards from gameboard
gameboard[indexV[0]] = 32;
gameboard[indexV[1]] = 32;
checkPoints(p1Score,
p2Score,
player1,
player2,
scorePool,
turn);
// Prints current player points
std::cout << player1 << ": " << p1Score << " pts\n"
<< player2 << ": " << p2Score << " pts\n";
pauseAndClear();
}
else
{
std::cout << "\nNO POINT FOR " << turn << "\n";
std::cout << player1 << ": " << p1Score << " pts\n"
<< player2 << ": " << p2Score << " pts\n";
// Changes player turn
if (turn == player1)
turn = player2;
else if (turn == player2)
turn = player1;
pauseAndClear();
}
indexV[0] = -1;
indexV[1] = -1;
}
return 0;
}