This repository was archived by the owner on Feb 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmessages.c
More file actions
98 lines (75 loc) · 2.43 KB
/
messages.c
File metadata and controls
98 lines (75 loc) · 2.43 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
#include "messages.h" // header
#include "types.h" // global variables
#include <ncurses.h>
#include <string.h> // strlen
void simple_offset(const char* message) {
int offset = (int)strlen(message);
int start = size.x / 2 - offset / 2;
for (int i = 0; i < start; i++)
addch(' ');
}
void offset_by_whitespace(const char* message) {
// average character has length of 2 -> size.x * 2 / 2
int field_half = size.x;
int offset = (int)strlen(message);
int start = field_half - offset /2;
for (int i = 0; i < start; i++)
addch(' ');
}
void controls_message(void) {
addch('\n');
offset_by_whitespace("q : quit | r : reset | wsad or ijkl : movement");
addch('q' | A_BOLD | COLOR_PAIR(1)); printw("%s", " : quit | ");
addch('r' | A_BOLD | COLOR_PAIR(1)); printw("%s", " : reset | ");
addch('w' | A_BOLD | COLOR_PAIR(1));
addch('s' | A_BOLD | COLOR_PAIR(1));
addch('a' | A_BOLD | COLOR_PAIR(1));
addch('d' | A_BOLD | COLOR_PAIR(1)); printw("%s", " or ");
addch('i' | A_BOLD | COLOR_PAIR(1));
addch('j' | A_BOLD | COLOR_PAIR(1));
addch('k' | A_BOLD | COLOR_PAIR(1));
addch('l' | A_BOLD | COLOR_PAIR(1)); printw("%s", " : movement");
}
void win_message(void) {
clear();
move(0, 0);
// offset by height
int half = size.y / 2 - 3;
for (int i = 0; i < half; i++)
addch('\n');
attron(A_BOLD | COLOR_PAIR(1));
offset_by_whitespace("You Won!");
printw("You Won!");
attroff(A_BOLD | COLOR_PAIR(1));
}
void lost_message(void) {
clear();
move(0, 0);
// offset by height
int half = size.y / 2 - (size.y % 2);
for (int i = 0; i < half-2; i++)
addch('\n');
attron(A_BOLD | COLOR_PAIR(2));
offset_by_whitespace("You Lost :(");
printw("You Lost :(");
attroff(A_BOLD | COLOR_PAIR(2));
}
void score_message(void) {
printw("\n\n");
offset_by_whitespace("wins : 0 loses : 0");
printw("wins: ");
attron(A_BOLD | COLOR_PAIR(1)); printw("%d", wins); attroff(A_BOLD | COLOR_PAIR(1));
printw(" loses : ");
attron(A_BOLD | COLOR_PAIR(2)); printw("%d", loses); attroff(A_BOLD | COLOR_PAIR(2));
}
int reset_message(void) {
score_message();
printw("\n\n");
offset_by_whitespace("Do you want to reset? [y/n]");
printw("Do you want to reset? ["); addch('y' | A_BOLD | COLOR_PAIR(1));
addch('/'); addch('n' | A_BOLD | COLOR_PAIR(2)); addch(']');
timeout(-1);
int result = getch();
timeout(TIMEOUT);
return result;
}