-
Notifications
You must be signed in to change notification settings - Fork 0
/
end of game.c
185 lines (153 loc) · 2.7 KB
/
end of game.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/***
*void End_Of_Game
*
*Purpose:
* show the scoore of the player,
* and insert it to the high score(write to score.bin file) if it fit.
* show high score.
*Entry:
*
*
*Exit:
*
*******************************************************************************/
#include "atari.h"
void End_Of_Game (
short BackGround[][ROW + 1],
SCORE High_Score[],
char New_Player[],
int counter
)
{
char ch[] = {"YOUR SCORE IS :"};
char num[5] = {'\0'};
int size = 8;
int i;
int j;
int count;
FILE* SC;
clock_t time;
sndPlaySound ("space2.wav", SND_ASYNC);
system ("cls");
// print the last back ground agine.
for (i =0; i < ROW + 1; i++)
{
for (j = 0; j< COL; j++)
{
SetColor(0,BackGround[j][i]);
putch(SPACE);
}
}
//print the player ending score.
Move_Object(
BackGround,
New_Player,
PINK,
30,
15,
strlen(New_Player) - 1,
0
);
Move_Object (
BackGround,
ch,
PINK,
30,
16,
15, 0
);
Move_Object (
BackGround,
itoa(counter, num, 10),
PINK,
50,
16,
5, 0
);
// sort high score list by.
for (i = 0; i < size && (counter < High_Score[i].score); i++);
if (counter > High_Score[i].score)
{
for (j = size - 1; j >= i ;j--)
{
High_Score[j].score = High_Score[j - 1].score;
strcpy (
High_Score[j].name,
High_Score[j - 1].name
);
}
High_Score[i].score = counter;
strcpy (
High_Score[i].name,
New_Player);
}
// write to scores file.
SC = fopen("scores.bin", "wb");
fwrite (
High_Score,
sizeof(SCORE),
8,
SC);
fclose(SC);
// read from scores file.
SC = fopen("scores.bin", "rb");
fread (
High_Score,
sizeof(SCORE),
8,
SC
);
fclose(SC);
//move data.
for (count = 1; count <= 16; count++)
{
while (time > clock());
TIMER(time, 20);
Move_Object(
BackGround,
(" "),
PINK,
0, (count - 1),
14, 0
);
//print names & scores.
for (j = 0; j < 8 ;j ++)
{
Move_Object(
BackGround,
(" "),
PINK,
0, (count + j),
14, 0
);
Move_Object(
BackGround,
High_Score[j].name,
PINK,
0, (count + j ),
strlen(High_Score[j].name) - 1, 0
);
itoa(
High_Score[j].score,
num,
10
);
i = strlen(num) ;
Move_Object(
BackGround,
num,
PINK,
9, (count + j ),
i, 0
);
}
//new game option.
Move_Object(
BackGround,
("NEW GAME ? (Y / N)"),
PINK,
30, (18),
18, 0
);
}
}