-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstats.c
130 lines (109 loc) · 3.61 KB
/
stats.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
/* -*- c -*-
* Copyright (C) 1999 Gus Hartmann & Peter Keller
* Copyright (C) 2024 Ron Wills <ron@digitalcombine.ca>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "sweep.h"
static WINDOW* stats_win;
/***************
* stats_clear *
***************/
static void stats_clear() {
if (stats_win) {
werase(stats_win);
}
}
/**************
* stats_init *
**************/
int stats_init() {
if ((stats_win = newwin(LINES - 3, INFO_W, 2, (COLS - INFO_W))) == NULL) {
log_error("Failed to create stats window");
return 0;
}
wbkgdset(stats_win, ' ' | COLOR_PAIR(CLR_STATBAR));
wclear(stats_win);
wrefresh(stats_win);
return 1;
}
/****************
* stats_resize *
****************/
void stats_resize() {
mvwin(stats_win, 6, (COLS - INFO_W));
wresize(stats_win, LINES - 7, INFO_W);
wnoutrefresh(stats_win);
}
/*****************
* stats_refresh *
*****************/
int stats_refresh() {
return wnoutrefresh(stats_win);
}
/*****************
* stats_display *
*****************/
void stats_display(game_stats_t *Game) {
float percentage = 0.0;
percentage = 100 * ((Game->MarkedMines + Game->BadMarkedMines) /
(Game->mines * 1.0));
wcolor_set(stats_win, CLR_STATBAR, NULL);
stats_clear();
// Format the time to something nicely readable.
if (Game->Time >= 86400) {
mvwprintw(stats_win, 0, 1, "Time: %d:%02d:%02d:%02ds", Game->Time / 86400,
(Game->Time % 86400) / 3600, (Game->Time % 3600) / 60,
Game->Time % 60);
} else if (Game->Time >= 3600) {
mvwprintw(stats_win, 0, 1, "Time: %d:%02d:%02ds", Game->Time / 3600,
(Game->Time % 3600) / 60 , Game->Time % 60 );
} else if (Game->Time >= 60) {
mvwprintw(stats_win, 0, 1, "Time: %d:%02ds", Game->Time / 60,
Game->Time % 60 );
} else {
mvwprintw(stats_win, 0, 1, "Time: %ds", Game->Time);
}
// Display the stats.
mvwprintw(stats_win, 1, 1, "Loc: %d, %d",
Game->CursorX + 1, Game->CursorY + 1);
mvwprintw(stats_win, 2, 1, "Mines: %d", Game->mines);
mvwprintw(stats_win, 3, 1, "Marks:");
mvwprintw(stats_win, 4, 1, "Percentage:");
// We warn the player if they have flagged to many or the incorrect mines.
if (percentage >= 100.0) {
if (has_colors() == TRUE) {
wcolor_set(stats_win, CLR_STATWARN, NULL);
} else {
wstandout(stats_win);
}
mvwprintw(stats_win, 3, 8, "%d", Game->MarkedMines + Game->BadMarkedMines);
mvwprintw(stats_win, 4, 13, "%3.1f%%", percentage);
if (has_colors() == TRUE) {
wcolor_set(stats_win, CLR_STATBAR, NULL);
} else {
wstandend(stats_win);
}
} else {
mvwprintw(stats_win, 3, 8, "%d", Game->MarkedMines + Game->BadMarkedMines);
mvwprintw(stats_win, 4, 13, "%3.2f%%", percentage);
}
// Flag the window to be refreshed.
wrefresh(stats_win);
//noutrefresh();
}
void stats_close() {
delwin(stats_win);
}