-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.pl
75 lines (65 loc) · 2.39 KB
/
map.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
64
65
66
67
68
69
70
71
72
73
74
75
:- dynamic(playerLoc/2).
:- dynamic(enemyLoc/2).
/* Map 10x10, indeks dari 0 dan 11 sebagai border, indeks 1 sampai 10 active Area */
border(0,Y) :- Y>(-1),Y<12.
border(11,Y) :- Y>(-1),Y<12.
border(X,0) :- X>(-1),X<12.
border(X,11) :- X>(-1),X<12.
activeArea(X,Y) :- X>(0),X<11,Y>(0),Y<11.
/*Fakta*/
healLoc(5,5).
/* Inisialisasi awal */
init :- asserta(playerLoc(1,1)),
asserta(healStatus(0)),
asserta(currHP([350])),
asserta(skillStatusE(0)),
asserta(skillStatusP(0)).
/* Print Legend Map */
printmap(X,Y) :- playerLoc(X,Y),write('P').
printmap(X,Y) :- border(X,Y),write('X').
printmap(X,Y) :- healLoc(X,Y),write('H').
printmap(X,Y) :- activeArea(X,Y),write('-').
/*Move*/
east :- playerLoc(10,_),printInvalidMove,!.
east :- playerLoc(X,Y),NewX is X+1,retract(playerLoc(X,Y)),asserta(playerLoc(NewX,Y)),msgAfterMove,!.
west :- playerLoc(1,_),printInvalidMove,!.
west :- playerLoc(X,Y),NewX is X-1,retract(playerLoc(X,Y)),asserta(playerLoc(NewX,Y)),msgAfterMove,!.
north :- playerLoc(_,1),printInvalidMove,!.
north :- playerLoc(X,Y),NewY is Y-1,retract(playerLoc(X,Y)),asserta(playerLoc(X,NewY)),msgAfterMove,!.
south :- playerLoc(_,10),printInvalidMove,!.
south :- playerLoc(X,Y),NewY is Y+1,retract(playerLoc(X,Y)),asserta(playerLoc(X,NewY)),msgAfterMove,!.
w :- north, move_Player.
a :- west, move_Player.
s :- south, move_Player.
d :- east, move_Player.
/* Collision terjadi jika ada 2 huruf di satu koordinat peta*/
/* Tambahin aksi setelah collision*/
collision(X,Y) :-
playerLoc(X,Y),
healLoc(X,Y),
print_Heal,!.
collision(X,Y) :-
playerLoc(X,Y),
enemyLocX(X1),
enemyLocY(Y1),
enemyName(ListEnemy),
checkKoordinat(X,Y,Name,X1,Y1,ListEnemy),
enemy_appear(ListOfEnemyAppear),
check(ListOfEnemyAppear,Name),
assign_Enemy(X,Y,Name),nl,
print_FoundEnemy,nl,
enemystatus,nl,
write('Pilih bertarung atau lari ? (run / attack)'),nl,
repeat,
read(Input),
print_Invalid_Collision(Input),
(Input==run;Input==attack),
call(Input),
!.
collision(_,_).
/*Logic ketika player ketemu friend, enemy, atau berada di health center */
msgAfterMove :- playerLoc(X,Y),write('Sekarang Player berada pada ('),print(X),write(','),print(Y),write(')'),nl,collision(X,Y).
/* Rules Print Map */
map:-
write('----------------MAP-----------------'),nl,
forall(between(0,11,Y),(forall(between(0,11,X),printmap(X,Y)),nl)),nl.