-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cc
122 lines (110 loc) · 4 KB
/
main.cc
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
#include "commandInput.h"
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <fstream>
#include <sstream>
void usage() {
std::cerr << "Too many arguments!" << std::endl;
std::cerr << "Command Line Options:" << std::endl;
std::cerr << "A: -load file" << std::endl;
std::cerr << "B: -testing" << std::endl;
} // usage
int main(int argc, char ** argv) {
std::map<std::string, std::string> players;
/*players["Andrew"] = "A";
players["Ivan"] = "I";
players["Fatday"] = "F";
players["Klaus"] = "K";
players["Lingwei"] = "L";
players["Steven"] = "S";*/
if (argc > 4) {
usage();
return 1;
} else if ((argc == 1) && (strcmp(argv[0], "./Watopoly"))) {
int numPlayers;
std::string line;
std::cout << "Welcome to Watopoly! Please type \"add Player_name Player_symbol\" to add an player. After adding players, type begin to begin the game.\n";
while (getline(std::cin, line)) {
std::istringstream ss1{line};
std::string command;
std::string name;
std::string symbol;
ss1 >> command;
if (command == "add") {
ss1 >> name;
if (ss1.fail()) {
std::cout << "Please type \"add Player_name Player_symbol\" to add an player.\n";
continue;
}
ss1 >> symbol;
if (ss1.fail()) {
std::cout << "Please type \"add Player_name Player_symbol\" to add an player.\n";
continue;
}
players[name] = symbol;
} else if (command == "begin") {
break;
} else {
std::cout << "Invalid command. Please type \"add Player_name Player_symbol\" to add an player. After adding players, type begin to begin the game.\n";
continue;
}
}
CommandInput input{std::make_shared<Game>(players)};
input.readInput(std::cin, false);
return 0;
} else if (argc == 3) {
std::ifstream infile{argv[2]};
CommandInput input{std::make_shared<Game>(infile)};
input.readInput(std::cin, false);
return 0;
} else if (argc == 2) {
//testing mode
int numPlayers;
std::string line;
std::cout << "Welcome to Watopoly! Please type \"add Player_name Player_symbol\" to add an player. After adding players, type begin to begin the game.\n";
while (getline(std::cin, line)) {
std::istringstream ss1{line};
std::string command;
std::string name;
std::string symbol;
ss1 >> command;
if (command == "add") {
ss1 >> name;
if (ss1.fail()) {
std::cout << "Please type \"add Player_name Player_symbol\" to add an player.\n";
continue;
}
ss1 >> symbol;
if (ss1.fail()) {
std::cout << "Please type \"add Player_name Player_symbol\" to add an player.\n";
continue;
}
players[name] = symbol;
} else if (command == "begin") {
break;
} else {
std::cout << "Invalid command. Please type \"add Player_name Player_symbol\" to add an player. After adding players, type begin to begin the game.\n";
continue;
}
}
CommandInput input{std::make_shared<Game>(players)};
input.readInput(std::cin, true);
return 0;
} else {
std::string command1 = argv[1];
if (command1 == "-load") {
std::string fileName = argv[2];
std::ifstream infile{fileName};
CommandInput input{std::make_shared<Game>(infile)};
input.readInput(std::cin, true);
} else {
std::string fileName = argv[3];
std::ifstream infile{fileName};
CommandInput input{std::make_shared<Game>(infile)};
input.readInput(std::cin, true);
}
return 0;
}
}