-
Notifications
You must be signed in to change notification settings - Fork 0
/
testProgram.c
83 lines (69 loc) · 1.79 KB
/
testProgram.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
#include "table.h"
/* This is a extra function in order to count passed time */
void count_time(time_t *fin, time_t init){
time(fin);
printf("%d seconds\n", (int) difftime(*fin, init));
}
void print_tablex(){ // only for testing!!
int i, j, value;
for(i = 0; i < MAX; i++){
printf("|%d", i+1);
}
printf("|\n");
for(i = 0; i < MAX; i++){
for(j = 0; j < MAX; j++){
value = table.array[i][j];
if(value == 99)
printf("|m");
else
printf("|%d",value);
}
printf("| %d\n", i+1);
}
}
int main(void){
time_t init, fin; // we need start time and end time
char ch;
time(&init); // set current time in seconds
initialize_table();
while(table.nMines != 0){ // when nMines becomes 0 you will win the game
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
print_table();
count_time(&fin, init); // every time which count_time is called passed time is updated
printf("cell values: 'X' unknown, '0' no mines close, '1-8' number of near mines, 'F' flag in cell\n");
printf("push t (see Time), f (put/remove Flag in cell), c (Check cell), n (New game), e (Exit game): ");
#ifdef _WIN32
ch = getche(); putchar('\n');
#endif
#ifdef linux
ch = getchar(); putchar(ch); putchar('\n');
#endif
switch (ch){
case 't': // just update the time in the next loop
break;
case 'f': // Flag
put_flag();
break;
case 'c': // check cell
look_cell();
break;
case 'n': // new game
count_time(&fin, init);
initialize_table();
time(&init);
break;
case 'e': // exit
game_over();
count_time(&fin, init);
default: // whatever other key is the same that 't' option
break;
}
}
game_over(); // on this point means that all mines were found
count_time(&fin, init);
return 0;
}