-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsnake.hpp
83 lines (75 loc) · 3.01 KB
/
tsnake.hpp
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
#pragma once
#include <ncurses.h>
#define height 25
#define width (height * 2)
void printScore(WINDOW *win, int score) {
mvwprintw(win, 0, width / 2 - 6, " SCORE : %d ", score);
}
void redraw(WINDOW *win) {
wclear(win);
box(win, 0, 0);
wrefresh(win);
}
void printHomeScreen(WINDOW *win, int highscore) {
redraw(win);
mvwprintw(win, height / 2 - 7, width / 2 - 24,
R"( _____ ____ _ __ ___ __ ___ )");
mvwprintw(win, height / 2 - 6, width / 2 - 24,
R"( /_ _/ / _/ / |/ // # \ / //7/ _/ )");
mvwprintw(win, height / 2 - 5, width / 2 - 24,
R"( / /___ _\ \ / | // _ // ,'/ _/ )");
mvwprintw(win, height / 2 - 4, width / 2 - 24,
R"( /_//__//___/ /_/|_//_//_//_/\\/___/ )");
mvwprintw(win, height / 2 - 3, width / 2 - 24,
R"( __ __ __ __ )");
mvwprintw(win, height / 2 - 2, width / 2 - 24,
R"( / \ / \ / \ / \ )");
mvwprintw(win, height / 2 - 1, width / 2 - 24,
R"(__________/ __\/ __\/ __\/ __\______________)");
mvwprintw(win, height / 2 - 0, width / 2 - 24,
R"(_________/ /__/ /__/ /__/ /_________________)");
mvwprintw(win, height / 2 + 1, width / 2 - 24,
R"( | / \ / \ / \ / \ \____ )");
mvwprintw(win, height / 2 + 2, width / 2 - 24,
R"( |/ \_/ \_/ \_/ \ o \ )");
mvwprintw(win, height / 2 + 3, width / 2 - 24,
R"( \_____/--< )");
mvwprintw(win, height / 2 + 5, width / 2 - 7, "HIGHSCORE : %d", highscore);
mvwprintw(win, height - 4, width / 2 - 11, R"(Press any key to start)");
wrefresh(win);
}
void printEndScreen(WINDOW *win, int highscore, int score) {
redraw(win);
printScore(win, score);
mvwprintw(win, height / 2 - 5, width / 2 - 10, R"( ____ )");
mvwprintw(win, height / 2 - 4, width / 2 - 10, R"( / . .\ )");
mvwprintw(win, height / 2 - 3, width / 2 - 10, R"( GAME \ ---<)");
mvwprintw(win, height / 2 - 2, width / 2 - 10, R"( OVER \ / )");
mvwprintw(win, height / 2 - 1, width / 2 - 10, R"( __________/ / )");
mvwprintw(win, height / 2 - 0, width / 2 - 10, R"(-=:___________/ )");
if (highscore == score) {
mvwprintw(win, height / 2 + 3, width / 2 - 9, "NEW HIGHSCORE : %d",
highscore);
}
mvwprintw(win, height - 6, width / 2 - 13, R"(press 'ENTER' to play again)");
mvwprintw(win, height - 4, width / 2 - 8, R"(press 'Q' to quit)");
wrefresh(win);
}
int getInput(WINDOW *platform) {
wtimeout(platform, 100);
int direction = wgetch(platform);
return direction;
}
WINDOW *createWin() {
WINDOW *win =
newwin(height, width, (LINES / 2 - (height / 2)), (COLS / 2 - height));
box(win, 0, 0);
keypad(win, TRUE);
wrefresh(win);
return win;
}
void destroy_win(WINDOW *win) {
wborder(win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
wrefresh(win);
delwin(win);
}