Skrip Game DesFight Menggunakan Strawberry Prolog

* Judul Game            : DesFight(Despicable Fight)

* Bahasa Pemrograman    : Strawberry Prolog

* Modifier              : Andi Sanjaya

* NPM                   : 50412771

* Kelas                 : 3IA12

===============================================

?-

Red_and_Bold is font_mask(_,rgb(255,0,0),_,_,_,bold,_,_),

set_default(font_mask(default,_,”Algerian”,50,_,_,_,_)),

write(“Dobleh”),

write(“Corp”, Red_and_Bold), nl,

set_default(font_mask(default,_,”Times New Roman”,18,_,_,_,_)),

write(“Greetings from “),

write(“Strawberry Prolog”, Red_and_Bold), nl,

%==================  memberi nilai awal =====================

G_Comp_First=0,

G_Take_Last=0,

G_waktu:=10,

%—————- memasukkan alamat gambar ————–

G_gambar is bitmap_image(“Gambar\\splashsc.bmp”,_),

G_background is bitmap_image(“Gambar\\background.bmp”,_),

G_star is bitmap_image(“Gambar\\star.bmp”,_),

G_menu is bitmap_image(“Gambar\\starmenu.bmp”,_),

window(G_Splash, _, windowS(_),”Dobleh Corp”,400,200,673,280).

%=============================================================

windowS(init):-  % set timer

G_batas := 0,

G_waktu is set_timer(_,0.10,fungsi_timer).

windowS(paint):- %memberi Background

draw_bitmap(0,0,G_gambar,_,_).

fungsi_timer(end):-  %fungsi timer

text_out(270,200,print(“Please wait..” + G_batas)),

G_batas := G_batas +10,

(G_batas >= 130 -> close_window(G_Splash),

execute(“clip\\play1.exe”),

window(G_screen,_,win_menu(_),”DesFight”,390,50,620,665)).

win_menu(paint):-

draw_bitmap(0,0,G_menu,_,_).

win_menu(close):-

execute(“clip\\gg.bat”),

close_window(G_screen),write(“close G_scren “).

%————-pembuatan button pada window utama———–

win_menu(init):-

button(_,_,start(_),”Fight Now”,263,200,90,45),

button(_,_,how(_),”How to Play”,263,250,90,45),

button(_,_,about(_),”About”,263,300,90,45),

button(_,_,exit(_),”Exit”,263,350,90,45).

%==========================================================

start(press):-

close_window(G_screen),

update_window(_),

pen(0,0),

execute(“clip\\gg.bat”),

execute(“sound\\play.exe”),

menu_new(_),

window(G_game, _,win_game(_), “DesFight”, (390,50,620,680)).

%=========================================================

%————–tampilan jika mengklik button how to play—-

how(press):-

message(“Aturan game”,”Player akan mengambil bintang terlebih dahulu.

Boleh mengambil berapapun dengan syarat bintang  yang di ambil hanya satu kolom.

Jika player mengambil bintang yang terakhir maka player akan kalah.

Ayo kalahkan evil-minion”,i),

update_window(_).

%———-tampilan jika mengklik button about———-

about(press):-

message(“About me”,”Andi Sanjaya

50412771

3IA12

Gunadarma University”,i),

update_window(_).

%=======================================================

%————–tampilan jika mengklik button exit———–

exit(press):-

execute(“clip\\gg.bat”),

close_window(G_screen),write(“close G_scren “).

%=============================================================

%———————function utama dari game—————-

win_game(init) :-

menu( normal, _, _, menu_home(_), “Home”),

menu( normal, _, _, menu_new(_), “New Game”),

menu( pop_up, _, _, menu_level(_), “Change Level”),

menu( right, _,_, menu_help(_), “Help”),

menu( right, _, _, menu_exit(_), “Exit”).

%=============================================================

menu_home(press):-

close_window(G_game),window(G_screen,_,win_menu(_),”DesFight”,(390,50,620,665)),

execute(“clip\\play1.exe”).

%————– ketika menekan menu new game —————–

menu_new(press) :-

set(pos([5,4,2,2,4,5])),

set(lose_flag(false)),

update_window(_),

(G_Comp_First=0->

set(pos([5,4,2,2,4,5]))

else

Pos=[5,4,2,2,4,5],

N is 2*random(3),

el(Pos,A, N),

A2 is A – 2,

replace(Pos2, Pos, A2, N),

set(pos(Pos2))),

update_window(_).

%======================================================

%=================== Change Level =====================

menu_level(init):-

menu( normal, _, _, level1(_), “Level Easy”),

menu( normal, _, _, level2(_), “Level Medium”),

menu( normal, _, _, level3(_), “Level Hard”).

%============= Level 1,2,3 ==================

level1(press):-

set(pos([5,4,2,2,4,5])),

set(lose_flag(false)),

update_window(_).

level2(press):-

set(pos([3,4,5,5,4,3])),

set(lose_flag(false)),

update_window(_).

level3(press):-

set(pos([5,4,5,5,4,5])),

set(lose_flag(false)),

update_window(_).

%==========================================

menu_help(press) :-

message(“Help me”,”Ayo gunakan keahlianmu untuk kalahkan evil-minion!”,i),

update_window(_).

%————— ketika menekan menu exit —————

menu_exit(press) :-

beep,

write(“menu exit press”),nl,

execute(“sound\\gg.bat”),

close_window(_).

%======================================================

win_game(close) :-

execute(“sound\\gg.bat”),

write(“close win_game “),nl,

close_window(G_game).

win_game(paint):-

draw_bitmap(0,0,G_background,_,_),

pos(Pos),

el(Pos,El,N),

for(I,1,El),

%=======================================================

% Jarak antara masing-masing item

X is 120+60*N,

Y is 335- 40*I,

% Untuk bentuk item

draw_bitmap(X,Y,G_star,_,_),fail.

%=======================================================

%——————Deklarasi Area Mouse Klik———–

win_game(mouse_click(X,Y)):-

beep,

X1 is (X- 120)//60,

Y1 is (335-Y)//40,

X1=<5,X>=40,

pos(Pos),

el(Pos,El,X1),

El>Y1,

replace(Pos2, Pos, Y1, X1),

(Pos2=[0,0,0,0,0,0]->

set(pos(Pos2)),

end(0)

else

wait(0.5),

play(Pos3, Pos2),

(Pos3=[0,0,0,0,0,0]->

end(1)),

set(pos(Pos3))),

update_window(_).

win_game(mouse_click(X,Y)):-

beep(“sound\\katok.wav”).

%=============================================================

%—————-AI dari game Des fight itu sendiri———–

play(Pos3, Pos2):-

G_Take_Last=0,

write(“komputer ngambil”),nl,

count_successes(not_trivial(Pos2))<4, find_max(Pos2,Max,N), New is (Max>1,count_successes(not_empty(Pos2)) mod 2=:=1 -> 1 else 0),

replace(Pos3, Pos2, New, N).

play(Pos3, Pos2):-

el(Pos2,A, N),

R:=0,

add_xor(R,Pos2,N),

R<A, replace(Pos3, Pos2, R, N),update_window(_). play(Pos3, Pos2):- find_max(Pos2,Max,N), Max2 is (Max>1, random(2)=:=0 ->

Max – 2

else

Max – 1),

replace(Pos3, Pos2, Max2, N).

not_empty(Pos):-

el(Pos,A, _),

A>1.

not_trivial(Pos):-

el(Pos,A, _),

A<0.

el([H|T],H,0).

el([H|T],El,N):-

el(T,El,N1),

N is N1+1.

replace([H|T],[_|T],H,0).

replace([H|T2],[H|T],El,N):-

replace(T2,T,El,N1),

N is N1+1.

find_max([H],H,0).

find_max([H|T],A, N) :-

find_max(T,A1,N1),

(A1

A is H,

N is 0

else

A is A1,

N is N1+1).

add_xor(_,[],_):-!.

add_xor(R,[H|T],0):- !,

add_xor(R, T, -1).

add_xor(R,[H|T],N):-

N1 is N- 1,

R:=R xor H,

add_xor(R, T, N1).

%=============================================================

%——————- notif menang atau kalah —————–

end(Flag):-

Flag=G_Take_Last->

beep(“Sound\\gameover.wav”),

message(“Yeahh…”,”You lose , I’m sorry”,i),menu_new(_)

else

beep(“Sound\\winner.wav”),

message(“Yeahh…”,”You are the winner!”,i),

set(lose_flag(false)),

update_window(_).

Selamat menggali ilmu semoga bermanfaat
Untuk pertanyaan, Saran dan kritik silahkan tinggalkan balasan di kolom komentar.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s