-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.c
71 lines (63 loc) · 1.48 KB
/
utility.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
#include "utility.h"
void clamp(double* value_to_clamp, float min, float max){//min and max are inclusive
if(*value_to_clamp < min)
*value_to_clamp = min;
else if(*value_to_clamp > max)
*value_to_clamp = max;
}
void fullscreen()
{
keybd_event(VK_MENU,0x38,0,0);
keybd_event(VK_RETURN,0x1c,0,0);
keybd_event(VK_RETURN,0x1c,KEYEVENTF_KEYUP,0);
keybd_event(VK_MENU,0x38,KEYEVENTF_KEYUP,0);
}
double random(double min,double max){
srand(time(0));
rand();
double random = ((double)rand()/(RAND_MAX));
double range =((double) random)*max;
double num = range + min;
return num;
}
bool keydown(int key)
{
return (GetAsyncKeyState(key) & 0x8000) != 0;
}
void setColor(int c)
{
SetConsoleTextAttribute(output, c);
}
void gotoxy(int x, int y) {
if(x>=0 && y>=0 && x<WIDTH && y<HEIGHT){
COORD pos = {x, y};
SetConsoleCursorPosition(output, pos);
}
}
void setScreenSize(int length, int height)
{
COORD c;
c.X = length;
c.Y= height;
SMALL_RECT s;
s.Left = 0;
s.Top = 0;
s.Right = length;
s.Bottom = height;
SetConsoleWindowInfo(output, TRUE, &s);
SetConsoleScreenBufferSize(output, c);
}
void hideCursor()
{
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(output, &info);
}
void openFile(FILE** fp, char* filename, char* Mode){
*fp = fopen(filename, Mode);
if(fp == NULL){
printf("Failed to open the file. Closing");
exit(EXIT_FAILURE);
}
}