Repository navigation
Expand file tree
/
Copy pathDisplay.cpp
More file actions
143 lines (125 loc) · 5.01 KB
/
Copy pathDisplay.cpp
File metadata and controls
143 lines (125 loc) · 5.01 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
135
136
137
138
139
140
141
142
143
#include "Display.h"
void colorSetting() {
start_color();
init_pair(1, COLOR_WHITE, COLOR_WHITE);
init_pair(2, COLOR_BLACK, COLOR_BLACK);
init_pair(3, COLOR_YELLOW, COLOR_YELLOW);
init_color(COLOR_CYAN, 1000, 500, 0);
init_pair(4, COLOR_CYAN, COLOR_CYAN);
init_pair(5, COLOR_GREEN, COLOR_GREEN);
init_pair(6, COLOR_RED, COLOR_RED);
init_pair(7, COLOR_MAGENTA, COLOR_MAGENTA);
init_pair(8, COLOR_BLACK, COLOR_WHITE);
init_pair(9, COLOR_BLACK, COLOR_YELLOW);
init_pair(10, COLOR_BLACK, COLOR_GREEN);
init_pair(11, COLOR_BLACK, COLOR_RED);
init_color(COLOR_BLUE, 500, 500, 500);
init_pair(12, COLOR_BLUE, COLOR_BLUE);
init_pair(15, COLOR_BLACK, COLOR_BLACK);
}
void time_wait(float time){
clock_t startClock = clock();
clock_t stageWait = clock();
while ((float)(stageWait - startClock) / CLOCKS_PER_SEC < time) {
stageWait = clock();
}
}
void draw_snakewindow(WINDOW* snake_win) {
for (int i = 4; i < MAP_SIZE + 4; i++) {
for (int j = 4; j < MAP_SIZE + 4; j++) {
if (map[i - 4][j - 4] == 0) { //white(빈칸)
wattron(snake_win, COLOR_PAIR(1));
mvwprintw(snake_win, i, j * 2, " ");
}
else if (map[i - 4][j - 4] == 1) { //Immune wall
wattron(snake_win, COLOR_PAIR(2));
mvwprintw(snake_win, i, j * 2, " ");
}
else if (map[i - 4][j - 4] == WALL) { //wall
wattron(snake_win, COLOR_PAIR(12));
mvwprintw(snake_win, i, j * 2, " ");
}
else if (map[i - 4][j - 4] == SNAKE_HEAD) { //head of snake
wattron(snake_win, COLOR_PAIR(SNAKE_HEAD));
mvwprintw(snake_win, i, j * 2, " ");
}
else if (map[i - 4][j - 4] == SNAKE_BODY) { //body of snake
wattron(snake_win, COLOR_PAIR(SNAKE_BODY));
mvwprintw(snake_win, i, j * 2, " ");
}
else if (map[i - 4][j - 4] == GROWTH_ITEM) { // growth item
wattron(snake_win, COLOR_PAIR(GROWTH_ITEM));
mvwprintw(snake_win, i, j * 2, " ");
}
else if (map[i - 4][j - 4] == POISON_ITEM) { //posion item
wattron(snake_win, COLOR_PAIR(POISON_ITEM));
mvwprintw(snake_win, i, j * 2, " ");
}
else if (map[i - 4][j - 4] == GATE) { //Gate
wattron(snake_win, COLOR_PAIR(GATE));
mvwprintw(snake_win, i, j * 2, " ");
}
else if (map[i - 4][j - 4] == X_ITEM) { // new item
wattron(snake_win, COLOR_PAIR(2));
mvwprintw(snake_win, i, j * 2, " ");
}
}
}
wrefresh(snake_win);
}
void updatePoint(WINDOW* point_win, Point* p) {
for (int i = 2; i <= 5; i++) {
mvwprintw(point_win, i, 1, " ");
}
p->updateMaxLength();
mvwprintw(point_win, 2, 1, "B: %d / %d", p->getCurrentLength(), p->getMaxLength());
mvwprintw(point_win, 3, 1, "+: %d", p->getGrowItem());
mvwprintw(point_win, 4, 1, "-: %d", p->getPoisonItem());
mvwprintw(point_win, 5, 1, "G: %d", p->getUseGate());
wrefresh(point_win);
}
void updateMission(WINDOW* mission_win, Mission* m, Point* p) {
for (int i = 2; i <= 5; i++) {
mvwprintw(mission_win, i, 1, " ");
}
m->updateAll(p);
mvwprintw(mission_win, 2, 1, "B: %d (%c)", m->getB(), (m->getBflag() ? 'V' : ' '));
mvwprintw(mission_win, 3, 1, "+: %d (%c)", m->getGrowItem(), (m->getGrowItemFlag() ? 'V' : ' '));
mvwprintw(mission_win, 4, 1, "-: %d (%c)", m->getPoisonItem(), (m->getPoisonItemFlag() ? 'V' : ' '));
mvwprintw(mission_win, 5, 1, "G: %d (%c)", m->getUseGate(), (m->getUseGateFlag() ? 'V' : ' '));
wrefresh(mission_win);
}
void displayDead(WINDOW* notice_win) {
notice_win = newwin(8, 20, 15,22);
wbkgd(notice_win, COLOR_PAIR(11));
wattron(notice_win, COLOR_PAIR(11));
mvwprintw(notice_win, 3, 3, "Snake is Dead!");
mvwprintw(notice_win, 4, 5, "Game End!");
wborder(notice_win, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(notice_win);
time_wait(3);
delwin(notice_win);
}
void displayNext(WINDOW* notice_win) {
notice_win = newwin(8, 20, 15,22);
wbkgd(notice_win, COLOR_PAIR(7));
wattron(notice_win, COLOR_PAIR(9));
mvwprintw(notice_win, 3, 5, "Next_Stage!");
mvwprintw(notice_win, 4, 3, "Press Any Key!");
wborder(notice_win, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(notice_win);
time_wait(2);
delwin(notice_win);
}
void displayGameClear(WINDOW* notice_win) {
notice_win = newwin(8, 20, 15,22);
wbkgd(notice_win, COLOR_PAIR(10));
wattron(notice_win, COLOR_PAIR(10));
mvwprintw(notice_win, 2, 2, "Congratulations!");
mvwprintw(notice_win, 3, 2, "ALL Stage Clear!");
mvwprintw(notice_win, 4, 4, "Game End!");
wborder(notice_win, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(notice_win);
time_wait(3);
delwin(notice_win);
}