-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.e
70 lines (63 loc) · 1.4 KB
/
application.e
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
note
description: "project application root class"
date: "$Date$"
revision: "$Revision$"
class
APPLICATION
inherit
ARGUMENTS_32
create
make
feature {NONE} -- Initialization
board: BOARD
make
-- Run application.
local
c: CHARACTER
do
create board.make (25, 3, 5, 10)
board.display
game_loop
end
game_loop
local
c: CHARACTER
do
from
until
board.finished
loop
c := read_char
if c = 'a' then
board.move_cat_left
elseif c = 'd' then
board.move_cat_right
elseif c = 's' then
board.move_cat_down
elseif c = 'w' then
board.move_cat_up
end
board.updateGameStatus
board.display
end
io.put_string_32 ("Game over%NMice killed: ")
io.put_integer (board.getkilledmice)
io.put_string_32 ("%NMice that reached the final subway: ")
io.put_integer (board.getfinalmice)
end
read_char: CHARACTER
-- Read a character from a console without waiting for Enter.
external "C++ inline use <curses.h>, <iostream>, <termios.h>, <unistd.h> "
alias "{
struct termios oldSettings, newSettings;
tcgetattr(STDIN_FILENO, &oldSettings);
newSettings = oldSettings;
newSettings.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newSettings);
char ch;
read(STDIN_FILENO, &ch, 1);
tcsetattr(STDIN_FILENO, TCSANOW, &oldSettings);
return ch;
}"
end
end