-
Notifications
You must be signed in to change notification settings - Fork 0
/
look.c
91 lines (83 loc) · 1.38 KB
/
look.c
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
/* look.c
**********
* help the player identity things
*/
#include <ncurses.h>
#include "sskk.h"
#include "look.h"
static void look_move(int x, int y);
static void look_refresh(void);
const char *look_check(char c) {
switch (c) {
case '@':
return "you";
case '.':
return "floor";
case '|':
case '-':
return "wall";
case 'o':
return "object";
case '+':
return "door";
case 'k':
return "keys";
case '=':
return "note";
case 'u':
return "button";
default:
return "something";
}
write_message("how did you get here??");
return "nothing";
}
static void look_move(int x, int y) {
move(y, x);
write_message(look_check(inch() & A_CHARTEXT));
move(y, x);
}
static void look_refresh(void) {
refresh();
}
//main loop for look functionality.
//takes starting x and y position as input.
void look_around(int inx, int iny) {
int x = inx;
int y = iny;
move(y, x);
curs_set(1); //make cursor visible
int c;
while (1) {
look_refresh();
c = getch();
switch (c) {
case 'h':
case KEY_LEFT:
look_move(x - 1, y);
x--;
break;
case 'j':
case KEY_DOWN:
look_move(x, y + 1);
y++;
break;
case 'k':
case KEY_UP:
look_move(x, y - 1);
y--;
break;
case 'l':
case KEY_RIGHT:
look_move(x + 1, y);
x++;
break;
case 'q':
case 27:
curs_set(0);
return;
default:
break;
}
}
}