-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.c
76 lines (55 loc) · 1.48 KB
/
tools.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
#include "head.h"
void split(char entry[32], int pos[2]){
char c = 'A';
char temp[32];
strcpy(temp, entry);
sscanf(temp, "%s %c%d", entry, &c, pos);
pos[1] = (int)(c - 'A');
pos[0] -= 1;
}
int valid_pos(int size, int pos[2]){
return (pos[0] >= 0 && pos[0] < size && pos[1] >= 0 && pos[1] < size);
}
char case2char(CASE * this_case, int reveal){
/*
* How to show different cases
*
* dug : bomb : 'X'
* else : number of neighbors ('0'..'8')
* not d : marked : '+'
* else : ' '
*/
if (!reveal){ // Still in game
if (this_case->marked)
return '+'; // Marked cases
else if (!this_case->dug)
return ' '; // Not dug nor marked yet
}
else if (this_case->bomb){ // Game over, show the bombs
if (this_case->dug)
return 'X'; // The bomb that exploded
else
return '@'; // Bombs that didn't explode
}
return this_case->neighbors + '0'; // Dug safe case, show the neighbors
}
struct tm * duration(time_t s_time){
time_t e_time;
time(&e_time);
int time_t_duration = (int)difftime(e_time, s_time);
int h = time_t_duration / 3600;
int m = (time_t_duration -= h * 3600) / 60;
int s = (time_t_duration -= m * 60);
h = h > 23 ? 23 : h; // In case some cave geek falls asleep
static struct tm tm_duration;
tm_duration.tm_sec = s;
tm_duration.tm_min = m;
tm_duration.tm_hour = h;
return &tm_duration;
}
int player_gt(PLAYER * p1, PLAYER * p2){
int diff = difftime(mktime(&(p1->time)), mktime(&(p2->time)));
if (diff < 0)
return 1;
return 0;
}