diff --git a/b.txt b/b.txt index 70b65ad..d458515 100644 --- a/b.txt +++ b/b.txt @@ -1,5 +1,4 @@ game_status(1). -game_status(0). tinggiPeta(13). lebarPeta(10). ctrheal(0). @@ -36,8 +35,6 @@ digym(0). udahheal(0). udahheal(0). lagi_ketemu(0). -lagi_ketemu(0). -battle_status(0). battle_status(0). finish_battle(0). finish_battle(0). diff --git a/main.pl b/main.pl index ecc79e9..ada9f66 100644 --- a/main.pl +++ b/main.pl @@ -44,11 +44,7 @@ (udahheal(_)->retractall(udahheal(_))),assert(udahheal(0)),retract(tangkaptime(_)),assert(tangkaptime(0)), retract(pick_time(_)),assert(pick_time(0)), (lebarPeta(_)->retract(lebarPeta(_))),(tinggiPeta(_)->retract(tinggiPeta(_))),(posisiGym(_,_)->retractall(posisiGym(_,_))),(rintangan(_,_)->retractall(rintangan(_,_))),(ctrheal(_)->retractall(ctrheal(_))), - /*(posisiLegendary(_,_,_)->retractall(posisiLegendary(_,_,_))),*/ - /*(udah_lari(_) -> retract(udah_lari(_))), (lagi_ketemu(_) -> retract(lagi_ketemu(_))),(battle_status(_) -> retract(battle_status(_))), - (digym(_)->retract(digym(_))),(maucapture(_)->retractall(maucapture(_))),(lagi_pick(_)->retractall(lagi_pick(_))),(finish_battle(_)->retractall(finish_battle(_))), - (current_tokemon1(_,_,_,_)-> retract(current_tokemon1(_,_,_,_))),(current_tokemon2(_,_,_,_) -> retract(current_tokemon2(_,_,_,_))), - (player_status(_)->retract(player_status(_))),*/ (player_position(_,_)->retract(player_position(_,_))),(inventory(_,_,_,_,_,_,_,_)->retractall(inventory(_,_,_,_,_,_,_,_))),(maxInventory(_)->retract(maxInventory(_))),(gameMain(_)->retractall(gameMain(_))), + (player_position(_,_)->retract(player_position(_,_))),(inventory(_,_,_,_,_,_,_,_)->retractall(inventory(_,_,_,_,_,_,_,_))),(maxInventory(_)->retract(maxInventory(_))),(gameMain(_)->retractall(gameMain(_))), write('Terima Kasih telah bermain!'),nl, write('Sampai jumpa lagi!'),nl,!. @@ -112,20 +108,6 @@ printLegendaryKosong, !. - -% printListLegendaryTokemon:- -% forall(tokemon(Tokemon,A,B,C,D,E,X), -% forall(X > 12,forall(posisiLegendary(Tokemon,XX,YY),forall(\+inventory(Tokemon,_,_,_,_,_,_,_),( -% write('Tokemon: '), writeln(Tokemon), -% write(' Health: '),writeln(A), -% write(' Normal attack: '),writeln(B), -% write(' Special attack: '),writeln(C), -% write(' Nama special attack: '),writeln(D), -% write(' Type: '),writeln(E), -% write(' ID: '),writeln(X), -% write(' Posisi: '),write(XX),write(','),write(YY),nl) -% )) -% )),!. printLegendaryKosong :- findall(Tokemon,(tokemon(Tokemon,_,_,_,_,_,X), X > 12,inventory(Tokemon,_,_,_,_,_,_,_)),ListLegendary), @@ -218,17 +200,29 @@ ( at_end_of_stream(Stream) -> Lines = [] ; Lines = [Line|NewLines], read_file(Stream, NewLines)). -/*loads(_) :- - game_status(1), - write('Kamu tidak bisa memulai game lainnya ketika ada game yang sudah dimulai.'), nl, !. - -loads(FileName):- - \+file_exists(FileName), - write('File tersebut tidak ada.'), nl, !. +/*source: + load file : https://stackoverflow.com/questions/37573618/how-to-read-a-file-in-prolog/37574687#37574687 +*/ + + +/* Dump File : */ + +/*(posisiLegendary(_,_,_)->retractall(posisiLegendary(_,_,_))),*/ + /*(udah_lari(_) -> retract(udah_lari(_))), (lagi_ketemu(_) -> retract(lagi_ketemu(_))),(battle_status(_) -> retract(battle_status(_))), + (digym(_)->retract(digym(_))),(maucapture(_)->retractall(maucapture(_))),(lagi_pick(_)->retractall(lagi_pick(_))),(finish_battle(_)->retractall(finish_battle(_))), + (current_tokemon1(_,_,_,_)-> retract(current_tokemon1(_,_,_,_))),(current_tokemon2(_,_,_,_) -> retract(current_tokemon2(_,_,_,_))), + (player_status(_)->retract(player_status(_))),*/ -loads(FileName):- - open(FileName, read, Str), - read_file_lines(Str,Lines), - close(Str), - assertaList(Lines), !. -*/ \ No newline at end of file +% printListLegendaryTokemon:- +% forall(tokemon(Tokemon,A,B,C,D,E,X), +% forall(X > 12,forall(posisiLegendary(Tokemon,XX,YY),forall(\+inventory(Tokemon,_,_,_,_,_,_,_),( +% write('Tokemon: '), writeln(Tokemon), +% write(' Health: '),writeln(A), +% write(' Normal attack: '),writeln(B), +% write(' Special attack: '),writeln(C), +% write(' Nama special attack: '),writeln(D), +% write(' Type: '),writeln(E), +% write(' ID: '),writeln(X), +% write(' Posisi: '),write(XX),write(','),write(YY),nl) +% )) +% )),!. \ No newline at end of file diff --git a/map.pl b/map.pl index 91da822..a4b2280 100644 --- a/map.pl +++ b/map.pl @@ -8,11 +8,6 @@ :- include('battle.pl'). /*UNTUK DEBUG*/ -posisiLegendary(inkmon,10,10). -posisiLegendary(yorikomon,20,20). -posisiLegendary(iqbalmon,11,11). -posisiLegendary(malmon,21,21). -posisiLegendary(ascalon,22,22). init_map :- random(10,20,X), @@ -21,6 +16,7 @@ asserta(lebarPeta(X)), asserta(tinggiPeta(Y)), asserta(player_position(1,1)), + generateLegendary, generateGym, generateRintangan, !. @@ -107,6 +103,8 @@ printMap(X,Y) :- player_position(X,Y), !, write('P'). +printMap(X,Y) :- + legendary_place(X,Y,_), !, write('L'). printMap(X,Y) :- isGym(X,Y), !, write('G'). printMap(X,Y) :- @@ -122,36 +120,60 @@ printMap(_,_) :- write('-'). -generateRintangan :- +isLegendary(A,B):- + legendary_place(A,B,_). + +generateLegendary:- lebarPeta(X), tinggiPeta(Y), XMin is 2, XMax is X, YMin is 2, YMax is Y, - Sum is round(X*Y/10), - - forall(between(1,Sum,_), ( + + forall(between(13,17,R), ( random(XMin,XMax, A), random(YMin,YMax, B), - asserta(rintangan(A,B)) + assert(legendary_place(A,B,R)) )), !. -generateGym :- + +generateGym:- lebarPeta(X), tinggiPeta(Y), XMin is 2, - XMax is X, - YMin is 2, + XMax is X, + YMin is 2, YMax is Y, Sum is round(X*Y/100), - - forall(between(1,Sum,_),( - random(XMin,XMax,A), - random(YMin,YMax,B), + + forall(between(1,Sum,_), ( + random(XMin,XMax, A), + random(YMin,YMax, B), + not(isLegendary(A,B)), asserta(posisiGym(A,B)) - )), + )), !. + + +generateRintangan :- + lebarPeta(X), + tinggiPeta(Y), + XMin is 2, + XMax is X, + YMin is 2, + YMax is Y, + Sum is round(X*Y/10), + + forall(between(1,Sum,_), ( + random(XMin,XMax, A), + random(YMin,YMax, B), + not(isLegendary(A,B)), + not(posisiGym(A,B)), + asserta(rintangan(A,B)) + )), + !. + map :- lebarPeta(X), tinggiPeta(Y),