-
Notifications
You must be signed in to change notification settings - Fork 1
/
display.pl
63 lines (54 loc) · 2.61 KB
/
display.pl
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
:- module(display, [display/1,
playerWinDisplay/1,
drawDisplay/0,
roundDisplay/0,
playerDisplay/1,
shotDisplay/2,
displayMoves/2,
displayActions/1,
outOfBoundaryDisplay/1,
deathDisplay/1,
collisionDisplay/0,
roundLimitDisplay/0,
displayEndOfGame/1]).
:- use_module('Game/plane').
:- use_module('game').
% Stop condition for displaying the board
display([]).
% Displays each row, and then displays the rest of the board by recursion.
display([Row|B]) :- displayRow(Row), display(B).
% Ends a row display (if row is empty)
displayRow([]) :- nl.
% Displays one element of the row and calls recursively for the rest of the row.
displayRow([Element|Row]) :- Element == '.', write(' '), write(Element), write('|'), displayRow(Row).
displayRow([Element|Row]) :- write(Element), write('|'), displayRow(Row).
% Gameover displays
playerWinDisplay(Idx) :- write('Player '), write(Idx), write(' wins!'), nl.
drawDisplay :- write('Draw!'), nl.
% Game status display
roundDisplay :- write('Round : '), round(NB), write(NB), nl.
playerDisplay(Idx) :- plane(Idx, X, Y, Life, Orientation),
write('--- Player '), write(Idx), write(' ---'), nl,
write('Remaining life : '), write(Life), nl,
write('Position : X:'), write(X), write(' Y:'), write(Y), write('. Orientation:'), write(Orientation), nl.
shotDisplay(SrcIdx, DestIdx) :- write('Player '),
write(SrcIdx),
write(' shot at player '),
write(DestIdx),
write('!'),
nl.
displayMoves(ActionsP1, ActionsP2) :- displayPlayerMoves(1, ActionsP1), displayPlayerMoves(2, ActionsP2).
displayPlayerMoves(Idx, Actions) :- write('Moves P'), write(Idx), write(' : ['), displayActions(Actions), write('].'), nl.
displayActions([]).
displayActions([FirstAction|Rest]) :- write(FirstAction), write(', '), displayActions(Rest).
% Gameover reasons display
outOfBoundaryDisplay(Idx) :- write('Player '), write(Idx), write(' out of board.'), nl.
deathDisplay(Idx) :- write('Player '), write(Idx), write(' has been killed!'), nl.
collisionDisplay :- write('Both players are at the same coordinates. Collision!'), nl.
roundLimitDisplay :- write('The round limit has been reached.'), nl.
displayEndOfGame(0) :- roundLimitDisplay, drawDisplay.
displayEndOfGame(1) :- playerWinDisplay(1).
displayEndOfGame(2) :- playerWinDisplay(2).
displayEndOfGame(3) :- collisionDisplay, drawDisplay.
displayEndOfGame(4) :- deathDisplay(1), deathDisplay(2), drawDisplay.
displayEndOfGame(5) :- outOfBoundaryDisplay(1), outOfBoundaryDisplay(2), drawDisplay.