File: stats.c

package info (click to toggle)
freesweep 0.88-4.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 404 kB
  • ctags: 267
  • sloc: ansic: 3,813; sh: 2,460; makefile: 112
file content (104 lines) | stat: -rw-r--r-- 2,877 bytes parent folder | download | duplicates (2)
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
/**********************************************************************
*  This source code is copyright 1999 by Gus Hartmann & Peter Keller  *
*  It may be distributed under the terms of the GNU General Purpose   *
*  License, version 2 or above; see the file COPYING for more         *
*  information.                                                       *
*                                                                     *
*  $Id: stats.c,v 1.9 2000/08/05 07:13:47 hartmann Exp $
*                                                                     *
**********************************************************************/

#include "sweep.h"

static WINDOW* StatsFrame;
static WINDOW* StatsWin;

static void ClearStats(void);

int InitStatsWin(void)
{
	if ((StatsFrame=newwin(7,INFO_W,6,(COLS-INFO_W)))==NULL)
	{ 
		return 1;
	}
	else if ((StatsWin=derwin(StatsFrame,5,19,1,1))==NULL)
	{
		return 1;
	}
	wborder(StatsFrame,CharSet.VLine,CharSet.VLine,CharSet.HLine,CharSet.HLine,
		CharSet.ULCorner, CharSet.URCorner,CharSet.LLCorner,CharSet.LRCorner); 
	wnoutrefresh(StatsFrame);
	wnoutrefresh(StatsWin);
	return 0;
}

void ClearStats()
{
	werase(StatsWin);
	wnoutrefresh(StatsWin);
	move(0,0);
	noutrefresh();
	return;
}

int RedrawStatsWin(void)
{
	return ((wborder(StatsFrame,CharSet.VLine,CharSet.VLine,CharSet.HLine,
		CharSet.HLine,CharSet.ULCorner,CharSet.URCorner,CharSet.LLCorner,
		CharSet.LRCorner)!=OK)?ERR:wnoutrefresh(StatsFrame));
}

void PrintStats(GameStats *Game)
{
	float percentage=0.0;
	percentage=100 * ((Game->MarkedMines + Game->BadMarkedMines) / (Game->NumMines * 1.0));

	ClearStats();

/*	mvwprintw(StatsWin, 0, 0, "Time: %ds", Game->Time);*/
	/*
		Put better clock here.
	*/
	if ( Game->Time >= 86400 )
	{
		mvwprintw(StatsWin, 0, 0, "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(StatsWin, 0, 0, "Time: %d:%02d:%02ds", Game->Time / 3600, ( Game->Time % 3600 ) / 60 , Game->Time % 60 );
	}
	else if ( Game->Time >= 60 )
	{
		mvwprintw(StatsWin, 0, 0, "Time: %d:%02ds", Game->Time / 60 , Game->Time % 60 );
	}
	else
	{
		mvwprintw(StatsWin, 0, 0, "Time: %ds", Game->Time);
	}




	mvwprintw(StatsWin, 1, 0, "Loc: %d, %d", Game->CursorX, Game->CursorY);
	mvwprintw(StatsWin, 2, 0, "Mines: %d", Game->NumMines);
	mvwprintw(StatsWin, 3, 0, "Marks:");
	mvwprintw(StatsWin, 4, 0, "Percentage:");
	
	if ( percentage > 100.0)
	{
		wstandout(StatsWin);
		mvwprintw(StatsWin, 3, 7, "%d", Game->MarkedMines + Game->BadMarkedMines);
		mvwprintw(StatsWin, 4, 12, "%3.2f%%", percentage);
		wstandend(StatsWin);
	}
	else
	{
		mvwprintw(StatsWin, 3, 7, "%d", Game->MarkedMines + Game->BadMarkedMines);
		mvwprintw(StatsWin, 4, 12, "%3.2f%%", percentage);
	}

	wnoutrefresh(StatsWin);
	move(0,0);
	noutrefresh();
	return;
}