-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.cpp
57 lines (50 loc) · 1.56 KB
/
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
////////////////////////////////////////////////////////////////////////////////
// Game Class //
// player clases data and actions //
////////////////////////////////////////////////////////////////////////////////
#include "game.h"
#include "player.h"
#include <memory>
#include <iostream>
#include <typeinfo>
using namespace std;
//constructor with args
//args:
//Player *p1 - first player
//Player *p2 - second player
Game::Game(Player* p1, Player* p2) {
SetPlayers(p1, p2);
}
//Sets the game players
void Game::SetPlayers(Player* p1, Player* p2) {
player1 = p1; //Associates the first player
player2 = p2; //Associates the second player
}
//Game Loop
//Asks for the moves from both players until there is a winner
//TODO: if there is a tie will never exits te loop
int Game::PlayGame() {
cout << "Let's play" << endl;
int col = 0;
bool valid = false;
while (true) {
while (!valid) {
col = player1->Play();
valid = board.Put(col, player1->GetPiecePattern());
}
valid = false;
if(board.Connected4(1)){
cout << "Ganó " << player1->GetName() << endl;
return 1;
}
while (!valid) {
col = player2->Play();
valid = board.Put(col, player2->GetPiecePattern());
}
valid = false;
if(board.Connected4(2)){
cout << "Ganó " << player2->GetName() << endl;
return 2;
}
}
}