-
Notifications
You must be signed in to change notification settings - Fork 0
/
meniu3.c
293 lines (272 loc) · 8.95 KB
/
meniu3.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#include<ncurses.h>
#include <stdlib.h>
#include <string.h>
#include"declaration.h"
// coloreaza matricea din centru pentru atunci cand
// playerul trebuie sa isi aleaga configuratia
void coloreaza_centru(int culoare, int x, int y, WINDOW * local_win) {
int i, j;
i = x;
j = y;
wattron(local_win, COLOR_PAIR(culoare));
mvwprintw(local_win, i * 2 + 15, j * 4 + 30, "%d%d%d%d", i, j, i, j);
mvwprintw(local_win, i * 2 + 15 + 1, j * 4 + 30, "%d%d%d%d", i, j, i, j);
attroff(COLOR_PAIR(culoare));
}
// afiseaza matricea din centru pentru cand isi alege
// jucatorul configuratia
void afis_tabla(int matr[10][10], WINDOW * local_win) {
int j, k;
for (j = 0; j < 10; j++) {
for (k = 0; k < 10; k++) {
if (k % 2 < 1) {
if (j % 2 < 1) {
coloreaza_centru(1, j, k, local_win);
} else {
coloreaza_centru(2, j, k, local_win);
}
} else {
if (j % 2 > 0) {
coloreaza_centru(1, j, k, local_win);
} else {
coloreaza_centru(2, j, k, local_win);
}
}
if (matr[j][k] == 1) {
coloreaza_centru(6, j, k, local_win);
}
}
}
}
// se afiseaza optinile de nave pe rand
// la apasarea sagetilor de navigatie iar
// playerul apase pe enter ca sa isi selecteze matricea
// cu care va juca jocul
WINDOW * alegere(int x, int y, int width, int height,
int matr[10][10], int argc, char ** argv) {
WINDOW * local_win;
local_win = newwin(height, width, y, x);
init_pair(1, COLOR_YELLOW, COLOR_YELLOW);
init_pair(2, COLOR_WHITE, COLOR_WHITE);
init_pair(3, COLOR_YELLOW, COLOR_WHITE);
init_pair(4, COLOR_CYAN, COLOR_WHITE);
init_pair(5, COLOR_RED, COLOR_RED);
init_pair(6, COLOR_GREEN, COLOR_GREEN);
init_pair(7, COLOR_MAGENTA, COLOR_MAGENTA);
int i, ch;
noecho();
keypad(local_win, TRUE);
curs_set(0);
mvwprintw(local_win, 3, 45, "Alege-ti configuratia");
i = 1;
citire_fisier(matr, argv[i]);
afis_tabla(matr, local_win);
while ((ch = wgetch(local_win))) {
switch (ch) {
case KEY_RIGHT:
i = i + 1;
i = (i == argc) ? 1 : i;
wattron(local_win, COLOR_PAIR(3));
citire_fisier(matr, argv[i]);
afis_tabla(matr, local_win);
break;
case KEY_LEFT:
i = i - 1;
i = (i == 0) ? argc - 1 : i;
wattron(local_win, COLOR_PAIR(3));
citire_fisier(matr, argv[i]);
afis_tabla(matr, local_win);
break;
case 10:
wrefresh(local_win);
wclear(local_win);
endwin();
return 0;
break;
}
}
return local_win;
}
// afiseaza meniul alocat cu sirulrile de caractere alocate dinamic
// navigheaza prin meniu iar daca butonul de iesire este apasat
// se iese din meniu iar daca se poate da resume game optiunea este
// activa si se poate apasa pe ea iar daca nu atunci se trece peste ea
// iar daca se apasa new game se trece mai intai in functia de selectat
// matricea jucatorului si dupa in joc efectiv
WINDOW * menu(int x, int y, int width, int height, int * resume,
int matr[10][10], int eu[10][10], int argc, char ** argv) {
WINDOW * local_win;
local_win = newwin(height, width, y, x);
init_pair(1, COLOR_YELLOW, COLOR_YELLOW);
init_pair(2, COLOR_CYAN, COLOR_CYAN);
init_pair(3, COLOR_YELLOW, COLOR_WHITE);
init_pair(4, COLOR_CYAN, COLOR_WHITE);
char * item = (char * ) calloc(13, sizeof(char));
char ** list = (char ** ) calloc(3, sizeof(char * ));
list[0] = (char * ) calloc(9, sizeof(char));
list[1] = (char * ) calloc(12, sizeof(char));
list[2] = (char * ) calloc(5, sizeof(char));
// char list[3][13] = { "New Game", "Resume Game", "Quit"};
strcpy(list[0], "New Game");
strcpy(list[1], "Resume Game");
strcpy(list[2], "Quit");
int ch, i = 0, nave_sparte[2], nimerite, nimeritecalc;
initscr();
local_win = newwin(height, width, y, x);
box(local_win, 0, 0);
wrefresh(local_win);
refresh();
wclear(local_win);
wrefresh(local_win);
nave_sparte[0] = 0;
nave_sparte[1] = 0;
nimerite = 0;
nimeritecalc = 0;
for (i = 0; i < 3; i++) {
if (i == 0)
wattron(local_win, A_STANDOUT);
else
wattroff(local_win, A_STANDOUT);
sprintf(item, "%s", list[i]);
mvwprintw(local_win, i + 27, 40, "%s", item);
}
wrefresh(local_win);
i = 0;
noecho();
keypad(local_win, TRUE);
curs_set(0);
while ((ch = wgetch(local_win))) {
sprintf(item, "%s", list[i]);
mvwprintw(local_win, i + 27, 40, "%s", item);
switch (ch) {
case KEY_UP:
i--;
i = (i < 0) ? 2 : i;
i = (i == 1 && !*resume) ? 0 : i;
break;
case KEY_DOWN:
i++;
i = (i > 2) ? 0 : i;
i = (i == 1 && !*resume) ? 2 : i;
break;
case 10:
// create a new window
sprintf(item, "%s", list[i]);
wrefresh(local_win);
wclear(local_win);
wrefresh(local_win);
start_color();
if (i == 0) {
* resume = 0;
nave_sparte[0] = 0;
nave_sparte[1] = 0;
nimerite = 0;
nimeritecalc = 0;
alegere(0, 0, 120, 50, eu, argc, argv);
wrefresh(local_win);
wclear(local_win);
refresh();
clear();
wrefresh(local_win);
wclear(local_win);
create_board(0, 0, 120, 50, resume, matr,
eu, nave_sparte, & nimerite, & nimeritecalc);
wrefresh(local_win);
wclear(local_win);
refresh();
clear();
wrefresh(local_win);
wclear(local_win);
for (i = 0; i < 3; i++) {
if (i == 0)
wattron(local_win, A_STANDOUT);
else
wattroff(local_win, A_STANDOUT);
sprintf(item, "%s", list[i]);
mvwprintw(local_win, i + 27, 40, "%s", item);
}
wrefresh(local_win);
i = 0;
} else if (i == 1) {
create_board(0, 0, 120, 50, resume, matr, eu, nave_sparte,
& nimerite, & nimeritecalc);
wrefresh(local_win);
wclear(local_win);
refresh();
clear();
wrefresh(local_win);
wclear(local_win);
for (i = 0; i < 3; i++) {
if (i == 1)
wattron(local_win, A_STANDOUT);
else
wattroff(local_win, A_STANDOUT);
sprintf(item, "%s", list[i]);
mvwprintw(local_win, i + 27, 40, "%s", item);
}
i = 1;
wrefresh(local_win);
} else if (i == 2) {
free(item);
for (i = 0; i < 3; i++) {
free(list[i]);
}
free(list);
endwin();
return 0;
}
}
wattron(local_win, A_STANDOUT);
sprintf(item, "%s", list[i]);
mvwprintw(local_win, i + 27, 40, "%s", item);
wattroff(local_win, A_STANDOUT);
}
return local_win;
}
int main(int argc, char * argv[]) {
initscr();
if (has_colors() == false) {
endwin();
printf("No color support!\n");
return -1;
}
start_color();
int resume, matr[10][10], eu[10][10], i;
// int **matr = (int **)calloc(10 , sizeof(int*));
// int **eu = (int **)calloc(10 , sizeof(int*));
// for(i = 0; i < 10; i++){
// eu[i] = (int *)calloc(10 , sizeof(int));
// matr[i] = (int *)calloc(10 , sizeof(int));
// }
resume = 0;
// daca nu s-au dat argumente se returneaza eroare
if (argc == 1) {
printf("[Eroare]: Nu s-au dat argumente de comanda.");
return 1;
}
//daca nu s-a dat vreo configuratie buna se returneaza eroare
for (i = 1; i < argc; i++) {
if (verificare_fisier(argv[i]) == 1) {
return 1;
}
}
flames(); // se afiseaza ecranul de inceput
//se curata dupa el
refresh();
clear();
refresh();
// init_pair(1, COLOR_RED, COLOR_BLACK);
// attron(COLOR_PAIR(1));
// printw("This is a test!");
// attroff(COLOR_PAIR(1));
//se afiseaza meniul
menu(0, 0, 120, 50, & resume, matr, eu, argc, argv);
// for(i = 0; i < 10; i++){
// free(eu[i]);
// free(matr[i]);
// }
// free(matr);
// free(eu);
endwin();
return 1;
}