-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManager.cpp
More file actions
149 lines (117 loc) · 3.71 KB
/
Copy pathGameManager.cpp
File metadata and controls
149 lines (117 loc) · 3.71 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "GameManager.h"
#include "Input.h"
#include <SFML/Graphics.hpp>
GameManager::GameManager(sf::Texture& texture) {
this->white = new WhiteTeam(texture);
this->black = new BlackTeam(texture);
}
void GameManager::InitialPrompt(){
cout<<"Follow the instructions and enter the position of piece you want to move,"
<<"then enter the position of where you would like to place that Piece." << endl;
}
void GameManager::promptUserInput(){
tuple<int,int> initialPosition;
tuple<int,int> finalPosition;
cout << "\n";
if (this->currTurn == 1) {
cout << "White's turn" << endl;
} else {
cout << "Black's turn" << endl;
}
Input I;
I.move();
get<0>(initialPosition) = I.initialX;
get<1>(initialPosition) = I.initialY;
get<0>(finalPosition) = I.finalX;
get<1>(finalPosition) = I.finalY;
this->usersMove.push_back(initialPosition);
this->usersMove.push_back(finalPosition);
// cout<<"( ";
// cout << get<0>(initialPosition)<< " , ";
// cout << get<1>(initialPosition)<< " ) -> ";
// cout<<"( ";
// cout << get<0>(finalPosition) << " , ";
// cout << get<1>(finalPosition)<<" )"<< endl;
++count;
TurnTracker();
}
tuple<int, int> GameManager::getUserInput() {
return this->usersMove[1];
}
void GameManager::PrintUsersMove(){
cout<<"( "<< get<0>(usersMove[0])<<", ";
cout<<get<1>(usersMove[0]) << " )";
cout<<" -> "<< "( "<< get<0>(usersMove[1]) <<" , "<< get<1>(usersMove[1]) << " )"<<endl;
}
bool GameManager::TurnTracker() {
//true = white
//false = black
if (count / 2 == 0) {
color = true;
}
else {
color = false;
}
return color;
}
void GameManager::CapturePiece(){
int xf = get<0>(usersMove[1]);
int yf = get<1>(usersMove[1]);
this->currPiece->move(xf, yf);
this->enemyPtr->notInPlay();
}
void GameManager::movePiece(int x, int y){
tuple<int,int> pos = make_tuple(x,y);
if(isSpaceFree(pos)){
this->currPiece->move(x,y);
}
}
void GameManager::getPiece(int x, int y){
tuple<int,int> coord = make_tuple(x,y);
if(this->currTurn == 1){
for(int i = 0; i < white->set.size(); i++){
if(white->set[i].getPosition() == coord){
currPiece = &white->set[i];
}
}
}else{
for(int i = 0; i < black->set.size(); i++){
if(black->set[i].getPosition() == coord){
currPiece = &black->set[i];
}
}
}
}
bool GameManager::isSpaceFree(tuple<int,int> usersInput){
for(int i = 0; i < white->set.size(); i++){
if(white->set[i].getPosition() == usersInput){
// cout<<"whitePiece found at ";
// cout << "space. ("<< get<0>(usersInput) << " , " << get<1>(usersInput) << ") is not free" << endl;
if(currTurn == 2){
this->enemyFound = true;
this->enemyPtr = &white->set[i];
} else{
this->enemyFound = false;
this->enemyPtr = nullptr;
return false;
}
return false;
}
}
for(int i = 0; i < black->set.size(); i++){
if(black->set[i].getPosition() == usersInput){
// cout<<"Black Piece found at ";
// cout << "space. ("<< get<0>(usersInput) << " , " << get<1>(usersInput) << ") is not free." << endl;
if(currTurn == 1){
this->enemyFound = true;
this->enemyPtr = &black->set[i];
} else{
this->enemyFound = false;
this->enemyPtr = nullptr;
return false;
}
return false;
}
}
return true;
}