-
Notifications
You must be signed in to change notification settings - Fork 2
/
peta.pl
177 lines (168 loc) · 4.28 KB
/
peta.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
:- include('file_eksternal.pl').
:- include('musuh.pl').
/* Deadzone, terrain dll */
:- dynamic(deadzone/1).
:- dynamic(lebarPeta/1).
:- dynamic(tinggiPeta/1).
:- dynamic(tick/1).
:- dynamic(terrain/3).
init_map :-
asserta(deadzone(0)),
asserta(tick(0)),
random(10,20,X),
random(10,20,Y),
asserta(lebarPeta(X)),asserta(tinggiPeta(Y)),
generateTerrain,!.
isBorderAtas(_,Y) :-
Y=:=0
,!.
isBorderKiri(X,_) :-
X=:=0,
!.
isBorderBawah(_,Y) :-
tinggiPeta(T),
YMax is T+1,
Y=:=YMax,
!.
isBorderKanan(X,_) :-
lebarPeta(L),
XMax is L+1,
X=:=XMax,
!.
isDeadzone(X,Y) :-
deadzone(DZ),
lebarPeta(L),
tinggiPeta(T),
NotDZXMin is DZ+1,
NotDZYMin is DZ+1,
NotDZXMax is L-DZ,
NotDZYMax is T-DZ,
(
Y < NotDZYMin;
Y > NotDZYMax;
X < NotDZXMin;
X > NotDZXMax
),
!.
incDeadzone :-
retract(deadzone(DZ)),
DZBaru is DZ+1,
asserta(deadzone(DZBaru)),!.
deadzoneDeadCheck :-
healthpoint(HP),
HP=<0->(
write('Di saat-saat terakhirmu,'), nl,
write('Hal yang paling kau sesali adalah...'), nl,
write('"Kenapa aku tidak mendengarkan suara-suara itu..."'), nl,
kalah
);
(
write('Kamu merasa mendengar suara dari bawah, "Cepat kabur dari sini!"'), nl,
write('Haruskah kamu menaati suara tersebut?'), nl,
write('Semua tergantung kepadamu.'), nl
),!.
deadzoneDamage :-
player(X,Y),
isDeadzone(X,Y), !,
write('Kamu merasa daerah sekitarmu mengurangi kehidupanmu sedikit demi sedikit.'), nl,
healthpoint(HP),
NewHP is HP-3,
retract(healthpoint(_)), asserta(healthpoint(NewHP)),
write('HP kamu berkurang menjadi '),write(NewHP),write('.'),nl,
deadzoneDeadCheck,
!.
deadzoneDamage :-
!.
deadzoneDamageEnemy :-
forall(musuh(Id,X,Y,_,HP,_),(
isDeadzone(X,Y),
NewHP is HP-1,
deadzoneEnemyDeadCheck(Id,NewHP)
)),
deadzoneWinCheck, !.
deadzoneDamageEnemy :-
!.
deadzoneEnemyDeadCheck(Id,NewHP) :-
NewHP>0->(
retract(musuh(Id,X,Y,Dam,_,Drop)),
asserta(musuh(Id,X,Y,Dam,NewHP,Drop))
);
(
retract(musuh(Id,Xm,Ym,Damage,_,Senjata)),
between(1,500,IdB),\+barang(IdB,_,_,_,_),
Times2 is (Damage * 2),
random(Damage,Times2,DamageSenjata),
asserta(barang(Id,Senjata,Xm,Ym,DamageSenjata)),
write('Kamu merasakan seperti ada orang yang mati tidak jauh.'), nl,
write('Mungkin dia meninggalkan sesuatu sebelum pergi.'), nl
), !.
deadzoneWinCheck :-
\+musuh(_,_,_,_,_,_),
update, !.
deadzoneWinCheck :-
!.
printPrio(X,Y) :-
isBorderKanan(X,Y), !, write('+').
printPrio(X,Y) :-
isBorderKiri(X,Y), !, write('+').
printPrio(X,Y) :-
isBorderAtas(X,Y), !, write('+').
printPrio(X,Y) :-
isBorderBawah(X,Y), !, write('+').
printPrio(X,Y) :-
musuh(_,X,Y,_,_,_),!, write('E').
printPrio(X,Y) :-
isMedicine(Nama,_), barang(_,Nama,X,Y,_), !, write('O').
printPrio(X,Y) :-
isSenjata(Nama,_), barang(_,Nama,X,Y,_), !, write('S').
printPrio(X,Y) :-
isArmor(Nama,_), barang(_,Nama,X,Y,_), !, write('A').
printPrio(X,Y) :-
isAmmo(Nama,_,_), barang(_,Nama,X,Y,_), !, write('M').
printPrio(X,Y) :-
isBag(Nama,_), barang(_,Nama,X,Y,_), !, write('B').
printPrio(X,Y) :-
player(X,Y), !, write('P').
printPrio(X,Y) :-
isDeadzone(X,Y), !, write('X').
printPrio(_,_) :-
write('-').
printMap(X,Y) :-
isBorderKanan(X,Y), !, write('+').
printMap(X,Y) :-
isBorderKiri(X,Y), !, write('+').
printMap(X,Y) :-
isBorderAtas(X,Y), !, write('+').
printMap(X,Y) :-
isBorderBawah(X,Y), !, write('+').
printMap(X,Y) :-
player(X,Y), !, write('P').
printMap(X,Y) :-
isDeadzone(X,Y), !, write('X').
printMap(_,_) :-
write('-').
/* terrain(X,Y,nama) */
isTerrain(bukit).
isTerrain(hutan).
isTerrain(gunung).
isTerrain(padang_rumput).
isTerrain(padang_pasir).
isTerrain(kota).
isTerrain(desa).
generateTerrain:-
lebarPeta(L),
tinggiPeta(T),
XMin is 1,
XMax is L,
YMin is 1,
YMax is T,
forall(between(YMin,YMax,J), (
forall(between(XMin,XMax,I), (
findall(Ter,isTerrain(Ter),ListTerrain),
length(ListTerrain, Panjang),
random(0,Panjang,NoTerrain),
ambil(ListTerrain, NoTerrain, Terrain),
asserta(terrain(I,J,Terrain))
))
)),
!.