-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
145 lines (141 loc) · 4.98 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* @file main.c
* @brief - Implementacije funkcija za pokretanje i upravljanje ostalim delovima igrice.
*/
#include "global.h"
int gameOver;
int demo;
int gameDifficulty;
char characterMap[] = { '.', 'B', 'S', 'W', 'G', 'X', 'T' };
char map[MAP_SIZE][MAP_SIZE], editor[MAP_SIZE][MAP_SIZE];
int mapUsed[MAP_SIZE][MAP_SIZE];
int tank_x, tank_y, base_x, base_y, editor_cursor_x, editor_cursor_y, editor_cursor_id, editor_cursor_size;
int totalSpawned, cntKilled, score;
int power_indexes[] = {4, 11, 18};
Power power_up;
//configuration for difficulty
const Difficulty confDiff[3] = {{SPAWNSPEED_EASY,ENEMYSHOOTSPEED_EASY,get_decision_easy,ENEMYMOVESPEED_EASY},{SPAWNSPEED_MEDIUM,ENEMYSHOOTSPEED_MEDIUM,get_decision_medium,ENEMYMOVESPEED_MEDIUM},{SPAWNSPEED_HARD,ENEMYSHOOTSPEED_HARD,get_decision_hard,ENEMYMOVESPEED_HARD}};
char mainMenu[][100] = {{"Start Game"}, {"Edit Level"}, {"Start DEMO"}, {"Show High Scores"}, {"Clear High Scores"}, {"Exit Game"}};
char levels[][100] = {{"Level 1"}, {"Level 2"}, {"Level 3"}, {"Level 4"}, {"Level 5"},
{"Level 6"}, {"Level 7"}, {"Level 8"}, {"Level 9"}, {"Level 10"},
{"Level 11"}, {"Level 12"}, {"Level 13"}, {"Level 14"}, {"Level 15"},
{"Level 16"}, {"Level 17"}, {"Level 18"}, {"Level 19"}, {"Level 20"},
{"Level 21"}, {"Level 22"}, {"Level 23"}, {"Level 24"}, {"Level 25"},
{"Level 26"}, {"Level 27"}, {"Level 28"}, {"Level 29"}, {"Level 30"},
{"Level 31"}, {"Level 32"}, {"Level 33"}, {"Level 34"}, {"Level 35"}};
char difficulties[][100] = {{"Easy"}, {"Medium"}, {"Hard"}};
char highScores[20][100];
char levelName[100], buffer[100];
int CNT_KILLED[] = { 0, 0, 0, 0 };
int read_input(){
#ifdef _WIN32
return getch();
#else
return getchar();
#endif // _WIN32
}
int main(int argc, char **argv)
{
int menu_choice, level, i, difficulty = 0;
char temp[20];
setlocale (LC_CTYPE, "");
srand(time(NULL));
init_curses();
resize_term(80,80);
while ( 1 )
{
check_high_scores ( );
erase ( );
menu_choice = print_menu (2, 5, 6, 15, "Battle Tank - MAIN MENU", mainMenu, 1);
if (menu_choice == 0)
{
erase();
gameDifficulty = print_menu(2, 5, 3, 15, "SELECT DIFFICULTY", difficulties, 1);
if ( gameDifficulty >= INF ) continue;
erase();
demo = 0;
startGame();
}
if (menu_choice == 1)
{
erase();
level = print_menu (2, 5, 35, 15, "SELECT LEVEL", levels, 1) + 1;
if ( level >= INF ) continue;
erase();
load_editor(level);
}
if ( menu_choice == 2 )
{
erase();
gameDifficulty = print_menu(2, 5, 3, 15, "SELECT DIFFICULTY", difficulties, 1);
if ( gameDifficulty >= INF ) continue;
demo = 1;
startGame();
}
if (menu_choice == 3)
{
erase();
difficulty = print_menu(2, 5, 3, 15, "SELECT DIFFICULTY", difficulties, 1);
if ( difficulty >= INF ) continue;
check_high_scores ( );
strcpy(temp, "high_scores");
switch ( difficulty )
{
case 0:
strcat(temp, "_easy.txt");
break;
case 1:
strcat(temp, "_medium.txt");
break;
case 2:
strcat(temp, "_hard.txt");
break;
}
erase();
int i;
char ch;
FILE * high_scores_file = fopen ( temp, "r" );
if ( high_scores_file == NULL )
{
clear_high_scores ( difficulty );
high_scores_file = fopen ( temp, "r" );
}
for (i = 0; i < 20; i++)
{
fgets(highScores[i], 100, high_scores_file);
ch = highScores[i][strlen(highScores[i]) - 1];
if (ch == '\n' || ch == '\r') highScores[i][strlen(highScores[i]) - 1] = '\0';
}
fclose ( high_scores_file );
erase();
i = print_menu (2, 5, 20, 15, "PRESS ENTER TO RETURN", highScores, 1);
}
if (menu_choice == 4)
{
erase();
difficulty = print_menu(2, 5, 3, 15, "SELECT DIFFICULTY", difficulties, 1);
if ( difficulty >= INF ) continue;
strcpy(temp, "high_scores");
switch ( difficulty )
{
case 0:
strcat(temp, "_easy.txt");
break;
case 1:
strcat(temp, "_medium.txt");
break;
case 2:
strcat(temp, "_hard.txt");
break;
}
clear_high_scores ( difficulty );
}
if (menu_choice == 5)
{
kill_curses();
return 0;
}
erase();
}
return 0;
}