forked from ChicoState/SportStats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
96 lines (80 loc) · 1.77 KB
/
main.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
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
#include <iostream>
#include <string>
#include "Game.h"
#include "Player.h"
#include "Score_Summary.h"
#include "Scoreboard.h"
#include <cstdlib>
using std::string;
using std::cout;
using std::cin;
const char GOAL_CHOICE = 'g';
const char PERIOD_CHOICE = 'n';
const char QUIT_CHOICE = 'q';
char promptMenu();
int main()
{
Game *game_data = NULL;
Scoreboard *board = NULL;
Score_Summary *summary = NULL;
string file1 ="", file2="";
cout<<"Enter two roster files: ";
cin>>file1>>file2;
try{
game_data = new Game(file1,file2);
}
catch(...){
cout<<"Something went wrong (besides this message).\n";
std::exit(1);
}
//connect different displays with game data
board = new Scoreboard(game_data);
summary = new Score_Summary(game_data);
char choice = QUIT_CHOICE;
do{
choice = promptMenu();
if( choice == GOAL_CHOICE ){
string player;
cout<<"Scoring Player: ";
cin>>player;
game_data->add_goal(player);
}
else if( choice == PERIOD_CHOICE ){
game_data->next_period();
}
}while( choice != QUIT_CHOICE );
cout<<"\n===FINAL SCORE===\n";
board->display();
cout<<"\n---By Period---\n";
summary->display();
return 0;
}
char promptMenu(){
char response, choice;
bool valid = false;
do{
cout<<"Menu\n====\n(G)oal\n(N)ext Period\n(Q)uit\n> ";
cin>>response;
switch(response){
case 'G':
case 'g':
choice = GOAL_CHOICE;
valid = true;
break;
case 'N':
case 'n':
choice = PERIOD_CHOICE;
valid = true;
break;
case 'Q':
case 'q':
choice = QUIT_CHOICE;
valid = true;
break;
default:
cout<<"Choose from G, N, or Q.\n";
break;
}
}while( !valid );
return choice;
}