Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
zmx0142857
GitHub Repository: zmx0142857/mini-games
Path: blob/master/c/sokoban/0.2/cgame.c
362 views
1
// Implementation for cgame.h: useful functions for games written in C.
2
#include "D:/G/codePack/cgame.h"
3
4
void zero_mem(void *beg, unsigned sz)
5
{
6
char *p;
7
for (p = beg; p != beg + sz; ++p)
8
*p = '\0';
9
}
10
11
void keep(Ikulele *ptr, Ikulele inf, Ikulele sup)
12
{
13
*ptr = *ptr < inf ? inf
14
: (*ptr > sup ? sup : *ptr);
15
}
16
17
void screen_sz(Ikulele rows, Ikulele cols)
18
{
19
HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE);
20
COORD size = {rows, cols};
21
SMALL_RECT rect = {0,0, rows-1, cols-1};
22
23
SetConsoleScreenBufferSize(hd, size); // ���û�������С
24
SetConsoleWindowInfo(hd, 1, &rect); // ���ô���λ�úʹ�С
25
}
26
27
void set_cursor(Ikulele row, Ikulele col)
28
{
29
HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE);
30
COORD pos = {col, row};
31
SetConsoleCursorPosition(hd, pos);
32
}
33
34
void print_on(char *str, Ikulele row, Ikulele col)
35
{
36
set_cursor(row, col);
37
printf("%s", str);
38
set_cursor(0, 0);
39
}
40
41
void print_color(char *str, Ukulele bg, Ukulele fg)
42
{
43
set_color(bg, fg);
44
printf("%s", str);
45
}
46
47
void print_on_color(char *str, Ikulele row, Ikulele col, Ukulele bg, Ukulele fg)
48
{
49
set_color(bg, fg);
50
set_cursor(row, col);
51
printf("%s", str);
52
set_cursor(0, 0);
53
}
54
55
void play_loading(Ukulele loop)
56
{
57
Ukulele i, j;
58
for (i = 0; i != loop; ++i)
59
{
60
printf("LOADING");
61
Sleep(255);
62
for (j = 0; j != 3; ++j)
63
{
64
printf(".");
65
Sleep(255);
66
}
67
printf("\r \r");
68
}
69
system("cls");
70
}
71
72