Repository navigation
Expand file tree
/
Copy pathPhaseView.cpp
More file actions
90 lines (79 loc) · 2.7 KB
/
Copy pathPhaseView.cpp
File metadata and controls
90 lines (79 loc) · 2.7 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
//
// Created by Pablo Arevalo on 16/04/2021.
//
#include "PhaseView.h"
PhaseView::PhaseView(GameEngine *s) {
subject = s;
subject->attach(this);
for (int i=0;i<subject->getNumberOfPlayers();i++) {
subject->players[i]->attach(this);
}
}
PhaseView::~PhaseView() {
subject->detach(this);
for (int i=0;i<subject->getNumberOfPlayers();i++) {
subject->players[i]->detach(this);
}
}
void PhaseView::update() {
if(subject->players[subject->getCurrentPlayer()]->refreshPhaseVP){
displayVP();
}
if(subject->refreshPhaseCard){
displayCard();
}
if(subject->refreshPhase){
displayTurn();
}
}
void PhaseView::displayCard() {
Player* player = subject->players[subject->getCurrentPlayer()];
cout<< ANSI_YELLOW_ON_BLACK;
if(subject->getCurrentCard() != nullptr){
cout << player->getName() <<" has picked up " << *subject->getCurrentCard() << '\n';
}
cout<< ANSI_COLOR_RESET;
}
void PhaseView::displayVP(){
cout<< ANSI_YELLOW_ON_BLACK;
Player* player = subject->players[subject->getCurrentPlayer()];
cout << player->getName() << " has gained VP\n" << player->getName() << " now has " << player->getVictoryPoints() << " VP" << endl;
cout<< ANSI_COLOR_RESET;
}
void PhaseView::displayTurn() {
Player* player = subject->players[subject->getCurrentPlayer()];
cout<< ANSI_YELLOW_ON_BLACK;
//Printing bot type if player is bot
if(player->getPlayerStrategy()->isBot()){
string strategy;
if(player->getPlayerStrategy()->botType == 2){
strategy = "GREEDY";
}
else if(player->getPlayerStrategy()->botType == 3){
strategy = "MODERATE";
}
cout << strategy << " Computer:" << endl;
}
//Printing player name, card, and VP
cout << "Player " << subject->getCurrentPlayer()<< " : " << player->getName() << " turn: " << ANSI_COLOR_RESET << endl;
}
void ass3Part2Demo(){
cout << "Welcome to the Part2 Demo" << endl;
cout << "We feel the normal game is sufficient for the Demo, but just in case we created a mini-driver that shows the part2 observers." << endl;
cout << "It creates 2 bots and lets them play to completion" << endl;
cout << "The yellow on black writing is the phase observer" << endl;
cout << "Press Enter to start" << endl;
cin.get();
mainGame=new GameEngine();
mainGame->createTestObjects();
PhaseView *phaseView = new PhaseView(mainGame);
while (!mainGame->isGameOver()) {
mainGame->mainMap->showMapASCIIonScreen();
mainGame->takeTurn();
}
cout << "End of Part 2 Demo" << endl;
delete phaseView;
delete mainGame;
phaseView= nullptr;
mainGame= nullptr;
}