This repository has been archived by the owner on Oct 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhiscore.cpp
97 lines (75 loc) · 1.92 KB
/
hiscore.cpp
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
#include "hugo.h"
Hiscore::Hiscore()
{
hientry he={0,0,"The Hugo"};
for(int i=0;i<10;i++) hlist[i]=he;
HANDLE h=OpenFile("Hiscores.dat");
ReadFile(h,hlist,sizeof(hlist));
CloseFile(h);
}
Hiscore::~Hiscore()
{
}
void Hiscore::Draw()
{
HDC hDC;
HFONT hf1=CreateFont(-8,8,0,0,FW_BOLD,FALSE,FALSE,FALSE,ANSI_CHARSET,0,0,0,0,"MS SANS SERIF");
HFONT hf2=CreateFont(16,8,0,0,FW_NORMAL,FALSE,FALSE,FALSE,ANSI_CHARSET,0,0,0,0,"COURIER NEW");
HFONT hf;
int i,l;
char buffer[50];
hDC = offscreen.GetDC();
PatBlt(hDC,0,0,320,200,BLACKNESS);
SetBkMode(hDC,TRANSPARENT);
SetTextColor(hDC,PALETTERGB(255,128,0));
hf=SelectFont(hDC,hf1);
TextOut(hDC,4,4,"The ten best players:",21);
SetTextColor(hDC,PALETTERGB(255,0,0));
TextOut(hDC,8,180,"Press a key to return to the menu",33);
SelectFont(hDC,hf2);
SetTextColor(hDC,PALETTERGB(255,255,0));
for(i=0;i<10;i++)
{
l=wsprintf(buffer,"%2d. %8d %3d %s",i+1,hlist[i].score,hlist[i].level,hlist[i].name);
TextOut(hDC,0,33+i*14,buffer,l);
}
SelectFont(hDC,hf);
offscreen.ReleaseDC(hDC);
DeleteObject(hf1);
DeleteObject(hf2);
}
void Hiscore::OnKey(HWND hwnd,UINT vk,BOOL fDown,int cRepeat,UINT flags)
{
PostMessage(hGameWindow,WM_COMMAND,HHC_MENU,0);
}
void Hiscore::OnLButtonUp(HWND hwnd, int x, int y, UINT keyFlags)
{
PostMessage(hGameWindow,WM_COMMAND,HHC_MENU,0);
}
BOOL Hiscore::CheckScore(int score,int level)
{
return (level>hlist[9].level || (level==hlist[9].level && score>hlist[9].score));
}
void Hiscore::InsertScore(int score,int level,char * name)
{
hientry he;
int i=9;
hlist[9].score=score;
hlist[9].level=level;
lstrcpy(hlist[9].name,name);
while (i && (hlist[i].level>hlist[i-1].level ||
(hlist[i].level==hlist[i-1].level && hlist[i].score>hlist[i-1].score)))
{
he=hlist[i];
hlist[i]=hlist[i-1];
hlist[i-1]=he;
i--;
}
Save();
}
void Hiscore::Save()
{
HANDLE h=CreateFile("Hiscores.dat");
WriteFile(h,hlist,sizeof(hlist));
CloseFile(h);
}