-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
100 lines (100 loc) · 3.14 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include "functions.h"
#include "colors.h"
int main(int argc, char const *argv[])
{
bool running = TRUE;
PLAYER player1;
PLAYER player2;
char **board;
int rows = 3, columns = 3;
FILE *recordFile;
while (running)
{
switch (startMenu())
{
case 1:
board = malloc(rows * sizeof(unsigned char *));
if (!board)
{
fprintf(stderr, RED_BOLD);
fprintf(stderr, "Error allocating memory!\n");
exit(EXIT_FAILURE);
}
for (int row = 0; row < rows; row++)
{
board[row] = malloc(columns * sizeof(unsigned char));
if (!board[row])
{
fprintf(stderr, RED_BOLD);
fprintf(stderr, "Error allocating memory!\n");
exit(EXIT_FAILURE);
}
}
switch (gameMenu()) {
case 1:
initPlayers(&player1, &player2);
gameloop(&player1, &player2, board, rows, columns);
recordFile = fopen(RECORD_FILENAME, "ab");
recordWrite(&recordFile, player1, player2);
fclose(recordFile);
break;
case 2:
initPlayer(&player1, &player2);
gameBotloop(&player1, &player2, board, rows, columns);
break;
default:
break;
}
for (int row = 0; row < rows; row++)
{
free(board[row]);
}
free(board);
break;
case 2:
if (fileExists(RECORD_FILENAME))
{
recordFile = fopen(RECORD_FILENAME, "rb");
while (TRUE)
{
recordRead(recordFile, &player1, &player2);
if (feof(recordFile))
{
break;
}
printf("%s%s %s(%s%c%s) %sVS %s%s %s(%s%c%s) | %s%d : %s%d\n", GREEN_BOLD,player1.name, RESET_COLORS, PURPLE_BOLD,player1.weapon, RESET_COLORS, YELLOW_BOLD, GREEN_BOLD, player2.name, RESET_COLORS, PURPLE_BOLD, player2.weapon, RESET_COLORS, RED_BOLD, player1.score, RED_BOLD, player2.score);
printf(YELLOW_BOLD_INTENSE);
printLine(LINE_SIZE);
}
fclose(recordFile);
printf(RESET_COLORS);
pauseTerm();
}
else
{
printf(RED_BOLD);
printf("No records found!\n");
printf(RESET_COLORS);
pauseTerm();
}
break;
case 3:
system(web);
break;
case 4:
printf(CYAN_BOLD);
printf("See ya!\n");
printf(RESET_COLORS);
running = FALSE;
break;
default:
break;
}
}
return EXIT_SUCCESS;
}