forked from jeongjye/OSS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilityfunctions.c
More file actions
76 lines (75 loc) · 1.85 KB
/
Copy pathutilityfunctions.c
File metadata and controls
76 lines (75 loc) · 1.85 KB
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
#include"Minesweeper.h"
#include <stdio.h>
int checkRows(int boardRows) {
return (boardRows >= MINBOARD && boardRows <= MAXBOARD);
}
int checkCols(int boardCols) {
return (boardCols >= MINBOARD && boardCols <= MAXBOARD);
}
int checkRowsinGame(int currentRow, int boardRows) {
return (currentRow >= 0 && currentRow < boardRows);
}
int checkColsinGame(int currentCol, int boardCols) {
return (currentCol >= 0 && currentCol < boardCols);
}
int IsRetry(char user){
return (user=='y' || user == 'Y');
}
int IsNotRetry(char user){
return (user=='n' || user=='N');
}
int IsGameReset(){
static int flag=0;
char user;
user=NULL;
if(flag==0){
flag=1;
return 1;
}
while(!IsRetry(user) && !IsNotRetry(user)){
getchar();
printf("Retry? (Y/N):");
scanf_s("%c",&user);
if(IsRetry(user)){return 1;}
else if(IsNotRetry(user)){return 0;}
}
}
int ActionInRange(int action) {
if (action == 1 || action == 2) {
return 1;
}
else
return 0;
}
void setCurrentCursorPos(int x, int y) {
COORD pos = { x, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
COORD getCurrentCursorPos(void) {
COORD curPoint;
CONSOLE_SCREEN_BUFFER_INFO curInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curInfo);
curPoint.X = curInfo.dwCursorPosition.X;
curPoint.Y = curInfo.dwCursorPosition.Y;
return curPoint;
}
void removeCursor(void) {
CONSOLE_CURSOR_INFO curInfo;
GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curInfo);
curInfo.bVisible = 0;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curInfo);
}
//Console COORD -> Array COORD
COORD computeArr(int x, int y) {
COORD computed;
computed.X = x / 2 - OFFSET_X;
computed.Y = y - OFFSET_Y;
return computed;
}
//Array COORD -> Console COORD
COORD computeArrReverse(int x, int y) {
COORD computed;
computed.X = (x + OFFSET_X) * 2;
computed.Y = y + OFFSET_Y;
return computed;
}