-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.lgt
67 lines (56 loc) · 1.66 KB
/
game.lgt
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
:- object(game,
imports(view_category)).
:- uses(logtalk, [
print_message/3
]).
:- public(start/0).
start :-
bedsit::do(reset),
apple::do(place),
print_message(information, snake, 'GameOver'-false), !.
start :-
\+ bedsit::do(reset),
board::size(S),
HS is S//2,
bedsit::init([ snake_direction(up)
, snake_head(coord(HS, HS))
, snake_body(DL-DL)
]),
apple::do(place),
print_message(information, snake, 'GameOver'-false).
:- public(turn/0).
turn :-
( snake::do(eat), apple::do(place)
; snake::do(move)
).
render(Sit) :-
snake::whole_body(Snake, Sit),
apple::location(Apple, Sit),
print_message(information, snake, 'Snake'::Snake),
print_message(information, snake, 'Apple'-Apple),
( is_gameover(Sit),
print_message(information, snake, 'GameOver'-true)
; true).
:- public(is_gameover/1).
is_gameover(Sit) :-
snake::head(Head, Sit),
snake::body(Body, Sit),
list::memberchk(Head, Body).
:- end_object.
:- object(reset,
imports(action)).
poss(Sit) :-
game::is_gameover(Sit).
retract_assert([ snake_head(_)
, snake_body(_)
, snake_direction(_)
, apple_location(_)
]
,
[ snake_direction(up)
, snake_head(coord(HS, HS))
, snake_body(DL-DL)
]) :-
board::size(S),
HS is S//2.
:- end_object.