-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab4_final.cpp
95 lines (78 loc) · 1.67 KB
/
Lab4_final.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
// Lab3_Murray_Garza.cpp : Defines the entry point for the console application.
//John Garza and Nicholas Murray
#include "stdafx.h"
#include "GameBase.h"
#include "NineAlmonds.h"
#include "Reversi.h"
using namespace std;
int main(int argc, char * argv[])
{
try {
GameBase::arguments(argc, argv);
}
catch (int e)
{
if (e == (int)result::wrong_argc) {
return usage(argv[(int)indices::program_name], (int)indices::game_name);
}
else if (e == (int)exceptions::game_set) {
cout << "Game is already set" << endl;
return e;
}
else if (e == (int)result::extraction_fail) {
cout << "A system error occurred, please try again" << endl;
return e;
}
else if (e == (int)result::unrecognized_arg) {
cout << "Unrecognized argument" << endl;
return usage(argv[(int)indices::program_name], (int)indices::game_name);
}
}
shared_ptr<GameBase> get_game;
int result = 0;
try {
get_game = GameBase::instance();
}
catch (int e)
{
if (e == (int)result::extraction_fail) {
return e;
}
else if (e == (int)exceptions::game_not_set) {
cout << "Game is not set" << endl;
return e;
}
else {
return e;
}
}
try {
result = get_game->play();
}
catch (int e)
{
if (e == (int)result::extraction_fail) {
return e;
}
else if (e == (int)exceptions::game_not_set) {
cout << "Game is not set" << endl;
return e;
}
else if (e == (int)result::fail_open_file) {
return e;
}
else if (e == (int)result::file_write_fail) {
return e;
}
else if (e == (int)result::fail_close_file) {
return e;
}
else {
return e;
}
}
if (result != (int)result::success) {
return result;
}
return (int)result::success;
}