forked from skyhong2002/Big-Bang-Simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
85 lines (78 loc) · 2.63 KB
/
main.c
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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include "code/bang.h"
int main(int32_t argc, char *argv[])
{
char yourname[50] = "Joker";
char logfile_name[FILENAME_MAX] = "log.txt";
int32_t playercnt = 4;
int c;
const char *short_opt = "o:p:n:h";
struct option long_opt[] = {
{"output", required_argument, NULL, 'o'},
{"player", required_argument, NULL, 'p'},
{"name", required_argument, NULL, 'n'},
{"help", no_argument, NULL, 'h'},
{0, 0, NULL, 0} /* end-of-array marker */
};
while ((c = getopt_long(argc, argv, short_opt, long_opt, NULL)) != -1)
{
char *endp = NULL;
long l = -1;
switch (c)
{
case 'o':
strcpy(logfile_name, optarg);
break;
case 'n':
strcpy(yourname, optarg);
break;
case 'p':
if (!optarg || ((l = strtol(optarg, &endp, 10)), (endp && *endp)))
{
fprintf(stderr, "invalid p option %s - expecting a number\n", optarg ? optarg : "");
exit(EXIT_FAILURE);
};
if (l < 4 || l > 7)
{
fprintf(stderr, "invalid p option %s - number should between 4~7\n", optarg ? optarg : "");
exit(EXIT_FAILURE);
};
playercnt = l;
break;
case 'h':
default:
fprintf(stderr,
"Usage:\n"
" %s [options]\n"
" -o, --output: Output file name. default: log.txt\n"
" -n, --name : Your name. default: Joker\n"
" -p, --player: Number of Player. default: 4 (4~7)\n"
" -h, --help : This description\n"
"\n",
argv[0]);
exit(0);
}
}
// option
printf("\033[H\033[J");
printf("==========================\n"
" Big Bang Simulator \n"
MAG "(う-`)づ" YEL "︻╦̵̵̿╤──" BLU " \\(˚☐˚」)/\n" RESET
" Created by Team 10 \n"
"==========================\n\n");
game bang;
printf("Game log will be stored in %s\n",logfile_name);
printf("More option see \"./main -h\"\n\n");
gameInit(&bang, playercnt, yourname, logfile_name);
char *winner = gameloop(&bang);
char *yourid = bang._player[0]->_identity;
printf("==========================\n");
printf("You are: %s\n", yourid);
printf("Winner: %s\n", winner);
printf("==========================\n");
return 0;
}