-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cc
70 lines (66 loc) · 1.46 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
#include <iostream>
#include <stdexcept>
#include <memory>
#include "board.h"
using namespace std;
int main(int argc, char* argv[]){
cout << "Welcome to Watopoly" << endl;
Board game{};
string load_file = "";
bool testing = false;
for (int i=0; i < argc; i++){
string command = argv[i];
if (command=="-testing"){
testing=true;
}
else if (command=="-load"){
if ((i+1)<argc){
load_file = argv[i+1];
}
}
}
if (testing){
cout << "You have started Watopoly in Testing Mode." << endl;
game.setTesting();
}
bool error=false;
if (load_file!=""){
try{
cout << "You have loaded the file: " << load_file << endl;
game.loadGame(load_file);
cout << "Successfully loaded the file: " << load_file << endl;
}
catch(const std::invalid_argument& ia){
error = true;
cerr << ia.what() << endl;
cout << "Error with loading, play will now resume normally" << endl;
}
}
if (load_file!=""&&!error){
game.play();
}
else{
cout << "How many players will be playing today?" << endl;
int count_players = 0;
string num = "";
while(true){
cin>>num;
try{
stoi(num);
count_players = stoi(num);
}
catch(const invalid_argument& ia){
cout << "Enter a number." << endl;
continue;
}
if (count_players<2 || count_players>8){
cout << "This is an invalid number of players. Their must be 2-8 players playing." << endl;
continue;
}
break;
}
game.initialize(count_players);
game.play();
}
return 0;
}