-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.cc
More file actions
75 lines (66 loc) · 1.93 KB
/
view.cc
File metadata and controls
75 lines (66 loc) · 1.93 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
// References MVC lecture code example
#include "observer.h"
#include "view.h"
#include "controller.h"
#include "model.h"
#include "subject.h"
#include <iostream>
#include <string>
View::View(int s, Controller *c, Model *m) : model{m}, controller{c}, seed{s}{
std::cout << "Is Player1 a human (h) or a computer (c)?" << std::endl;
char c1;
std::cin >> c1;
controller->player1Type(c1);
std::cout << "Is Player2 a human (h) or a computer (c)?" << std::endl;
char c2;
std::cin >> c2;
controller->player2Type(c2);
std::cout << "Is Player3 a human (h) or a computer (c)?" << std::endl;
char c3;
std::cin >> c3;
controller->player3Type(c3);
std::cout << "Is Player4 a human (h) or a computer (c)?" << std::endl;
char c4;
std::cin >> c4;
controller->player4Type(c4);
controller->newGame(seed);
model->subscribe(this);
update();
}
View::~View() {}
void View::update() {
std::cout << "Cards on the table:" << std::endl;
std::cout << "Clubs: ";
controller->displayClubs();
std::cout << "Diamonds: ";
controller->displayDiamonds();
std::cout << "Hearts: ";
controller->displayHearts();
std::cout << "Spades: ";
controller->displaySpades();
std::cout << "Your hand: ";
controller->displayHand();
std::cout << "Legal plays: ";
controller->displayLegalPlays();
nextCommand();
}
void View::nextCommand() {
std::string cmd;
std::string card;
bool quit = false;
while (!quit && std::cin >> cmd ) {
if (cmd == "deck") {
controller->displayDeck();
} else if (cmd == "play") {
std::cin >> card;
controller->play(card);
} else if (cmd == "discard") {
std::cin >> card;
controller->discard(card);
} else if (cmd == "ragequit") {
controller->rageQuit();
} else if (cmd == "quit") {
quit = true;
}
}
}