-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManager.cpp
More file actions
91 lines (72 loc) · 1.54 KB
/
Copy pathGameManager.cpp
File metadata and controls
91 lines (72 loc) · 1.54 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
#include "GameManager.h"
#include <algorithm>
#include <random>
GameManager::GameManager() {
}
void GameManager::shuffleCardsId(int arr[], int size) {
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(arr, arr + size, g);
}
void GameManager::checkIfPair() {
if (card1Ref->getId() == card2Ref->getId()) {
//cout << "ITS A PAIR" << endl;
totalPairs++;
if (totalPairs == 8) {
gameOver();
}
}
else {
//cout << "ITS NOT A PAIR" << endl;
notPair = true;
}
}
void GameManager::flipCard(CardScript* cscr) {
if (cardsFlipped == 0 && notPair) {
card1Ref->unflipCard();
card2Ref->unflipCard();
}
if (cardsFlipped == 0) {
notPair = false;
setCard1ScriptRef(cscr);
cardsFlipped += 1;
}
else {
setCard2ScriptRef(cscr);
checkIfPair();
cardsFlipped = 0;
}
}
void GameManager::setCard1ScriptRef(CardScript* cscr) {
card1Ref = cscr;
}
void GameManager::setCard2ScriptRef(CardScript* cscr) {
card2Ref = cscr;
}
void GameManager::setTextScriptRef(TextScript* wins, TextScript* mems, TextScript* pros) {
winRef = wins;
memRef = mems;
proRef = pros;
}
void GameManager::gameOver() {
//cout << "You WIN" << endl;
memRef->turnVisible(false);
int i = 0;
while (i < 16) {
cardsListRef[i]->turnVisible(false);
i++;
}
winRef->turnVisible(true);
proRef->turnVisible(true);
}
void GameManager::startGame() {
memRef->turnVisible(true);
int i = 0;
while (i<16) {
cardsListRef[i]->turnVisible(true);
i++;
}
}
void GameManager::setCardsScriptListRef(CardScript* cscrl, int place) {
cardsListRef[place] = cscrl;
}