-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsnakeMap.h
More file actions
134 lines (115 loc) · 4.09 KB
/
snakeMap.h
File metadata and controls
134 lines (115 loc) · 4.09 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
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
#pragma once
// size of gameboard
#define GBOARD_WIDTH 26
#define GBOARD_HEIGHT 18
// starting point of gameboard
#define GBOARD_ORIGIN_X 14
#define GBOARD_ORIGIN_Y 5
// size of controls board
#define CBOARD_WIDTH 8
#define CBOARD_HEIGHT 8
// starting point of controls board
#define CBOARD_ORIGIN_X 71
#define CBOARD_ORIGIN_Y 13
void printStage();
void printScore();
void printHighscore();
void drawLife();
void drawControls();
void drawKeys();
void clearScreen();
int gameBoardInfo[GBOARD_HEIGHT + 1][GBOARD_WIDTH + 2];
int heart = 3; // maximum num of lives
int currentScore = 0;
int stageBestScore = 0;
char* snakeGameName = "SNAKE";
void initGameBoardInfo() { // setting up boundaries
for (int y = 0; y < GBOARD_HEIGHT; y++) {
gameBoardInfo[y][0] = 1;
gameBoardInfo[y][GBOARD_WIDTH + 1] = 1;
}
for (int x = 0; x < GBOARD_WIDTH + 2; x++) {
gameBoardInfo[0][x] = 1;
gameBoardInfo[GBOARD_HEIGHT][x] = 1;
}
}
void resetGameBoardInfo() { // resetting boundaries
for (int y = 1; y < GBOARD_HEIGHT; y++) {
for (int x = 1; x < GBOARD_WIDTH; x++) {
gameBoardInfo[y][x] = 0;
}
}
}
void drawBoard() {
// game title
gotoxycol(38, 2, 14, "SNAKE GAME");
initGameBoardInfo();
// draw game board
for (int y = 0; y <= GBOARD_HEIGHT; y++) {
if (y == 0) gotoxycol(GBOARD_ORIGIN_X, GBOARD_ORIGIN_Y + y, 14, "¢Ê");
else if (y == GBOARD_HEIGHT) gotoxycol(GBOARD_ORIGIN_X, GBOARD_ORIGIN_Y + y, 14, "¢Ê");
else gotoxycol(GBOARD_ORIGIN_X, GBOARD_ORIGIN_Y + y, 14, "¢Ê");
if (y == 0) gotoxycol(GBOARD_ORIGIN_X + (GBOARD_WIDTH + 1) * 2, GBOARD_ORIGIN_Y + y, 14, "¢Ê");
else if (y == GBOARD_HEIGHT) gotoxycol(GBOARD_ORIGIN_X + (GBOARD_WIDTH + 1) * 2, GBOARD_ORIGIN_Y + y, 14, "¢Ê");
else gotoxycol(GBOARD_ORIGIN_X + (GBOARD_WIDTH + 1) * 2, GBOARD_ORIGIN_Y + y, 14, "¢Ê");
}
for (int x = 1; x < GBOARD_WIDTH + 1; x++) {
gotoxycol(GBOARD_ORIGIN_X + x * 2, GBOARD_ORIGIN_Y, 14, "¢Ê");
gotoxycol(GBOARD_ORIGIN_X + x * 2, GBOARD_ORIGIN_Y + GBOARD_HEIGHT, 14, "¢Ê");
}
printStage();
printScore();
printHighscore();
drawLife();
drawControls();
drawKeys();
}
void printStage() {
gotoxycol(72, 5, 15, "Stage: Classic");
}
void printHighscore() {
gotoxycol(72, 7, 15, "Highscore: ");
setCurrentCursorPos(83, 7);
printf("%5d", stageBestScore);
// print Highscore after setting cursor position and calling from text file
}
void printScore() {
gotoxycol(72, 9, 15, "Score: ");
setCurrentCursorPos(83, 9);
printf("%5d", currentScore);
// print Score after setting cursor position
}
void drawLife() {
gotoxycol(72, 11, 15, "Life:");
gotoxycol(79, 11, 12, "");
for (int i = 0; i < heart; i++) printf(" ¢¾");
for (int i = heart; i < 3; i++) printf(" ¢½");
}
void drawControls() { // draw controls board
for (int y = 0; y <= CBOARD_HEIGHT; y++) {
if (y == 0) gotoxycol(CBOARD_ORIGIN_X, CBOARD_ORIGIN_Y + y, 14, "¦®");
else if (y == CBOARD_HEIGHT) gotoxycol(CBOARD_ORIGIN_X, CBOARD_ORIGIN_Y + y, 14, "¦±");
else gotoxycol(CBOARD_ORIGIN_X, CBOARD_ORIGIN_Y + y, 14, "¦");
if (y == 0) gotoxycol(CBOARD_ORIGIN_X + (CBOARD_WIDTH + 1) * 2, CBOARD_ORIGIN_Y + y, 14, "¦¯");
else if (y == CBOARD_HEIGHT) gotoxycol(CBOARD_ORIGIN_X + (CBOARD_WIDTH + 1) * 2, CBOARD_ORIGIN_Y + y, 14, "¦°");
else gotoxycol(CBOARD_ORIGIN_X + (CBOARD_WIDTH + 1) * 2, CBOARD_ORIGIN_Y + y, 14, "¦");
}
for (int x = 1; x < CBOARD_WIDTH + 1; x++) {
gotoxycol(CBOARD_ORIGIN_X + x * 2, CBOARD_ORIGIN_Y, 14, "¦¬");
gotoxycol(CBOARD_ORIGIN_X + x * 2, CBOARD_ORIGIN_Y + CBOARD_HEIGHT, 14, "¦¬");
}
}
void drawKeys() {
gotoxycol(77, 14, 14, "CONTROLS");
gotoxycol(80, 16, 7, "¡è");
gotoxycol(78, 17, 7, "¡ç ¡æ");
gotoxycol(80, 18, 7, "¡é");
gotoxycol(73, 20, 7, "[SPACE] to STOP");
}
void clearScreen() {
for (int y = 1; y <= GBOARD_HEIGHT - 1; y++) {
for (int x = 1; x <= GBOARD_WIDTH; x++) {
gotoxy(GBOARD_ORIGIN_X + x * 2, GBOARD_ORIGIN_Y + y, " ");
}
}
}