% This program is created by Nayden NachevGame berikut telah dimodifikasi dengan menambahkan menu New Game, Petunjuk, serta Menu Exit.
% from University of Sofia
?-
pen(0,0),
G_R:=brush(rgb(0,0,1)),
G_X:=brush(rgb(255,255,255)),
G_B:=brush(rgb(255,255,0)),
G_O:=brush(rgb(255,0,0)),
set(pos([ [x,b,x,b,x,b,x,b],
[b,r,b,r,b,r,b,r],
[r,b,r,b,r,b,r,b],
[b,r,b,r,b,r,b,r],
[r,b,r,b,r,b,r,b],
[b,r,b,r,b,r,b,r],
[r,b,r,b,r,b,r,b],
[b,r,b,r,b,r,b,o] ])),
G_Br=4,
G_I =0,
G_J =0,
G_K =0,
G_think1=0,
G_think2=0,
window(_,_,win_func(_),"Try Your Luck",100,100,450,485).
chetno(0).
chetno(X) :-
X>0, Y := (X - 2),chetno(Y).
win_func(init) :-
menu( normal, _, _, menu_new(_), "&New Game"),
menu( normal, _, _, menu_Petunjuk(_), "&Petunjuk"),
menu( normal, _, _, menu_exit(_), "&Exit").
win_func(paint) :-
text_out(5,37,"1"),
text_out(5,87,"2"),
text_out(5,137,"3"),
text_out(5,187,"4"),
text_out(5,237,"5"),
text_out(5,287,"6"),
text_out(5,337,"7"),
text_out(5,387,"8"),
text_out(37,0,"A"),
text_out(87,0,"B"),
text_out(137,0,"C"),
text_out(187,0,"D"),
text_out(237,0,"E"),
text_out(287,0,"F"),
text_out(337,0,"G"),
text_out(387,0,"H"),
for(I,0,7),
for(J,0,7),
X is 20 + 50 * I,
Y is 20 + 50 * J,
X1 is X + 50,
Y1 is Y + 50,
Z is I + J,
(chetno(Z) ->
color(r) ;
color(b)
),
rect(X,Y,X1,Y1),
fail.
win_func(paint):-
drawing(I,J),
fail.
drawing(I,J):-
pos(Table),
member(Table,El,I,J),
color(El),
calculate(I,J,A,B,C,D),
ellipse(A,B,C,D).
calculate(X,Y,X1,Y1,X2,Y2):-
X1 is 30 + X*50,
Y1 is 30 + Y*50,
X2 is X1 +30,
Y2 is Y1 +30.
convert(I,J,X,Y):-
X>20, Y>20,Y<420, X<420,
A is X - 20,
B is Y - 20,
I is A// 50,
J is B// 50.
win():-
pos(Table),
member(Table,o,_,Yo),
member(Table,x,_,Yx),!,
(Yx>=Yo ,G_Br=4->
message("","Anda Kalah...",!);
X :=5
),
Yo>0.
move(Table,X,Y,Deep):-
nolose(Table,X,Y,_,_),
think1(Table,X,Y,Deep),
think2(Table,X,Y,Deep),
(G_think1 > G_think2->
nolose(Table,X,Y,I,J);
(G_think1 < G_think2->
nolose1(Table,X,Y,I,J);
think(Table,X,Y,I,J)
)
),
promqna(X,Y,o),
promqna(I,J,o).
nolose(Table,X,Y,A,B):-
A is X - 1,
B is Y - 1,
proverka(Table,A,B).
nolose(Table,X,Y,A,B):-
A is X + 1,
B is Y - 1,
proverka(Table,A,B).
nolose(Table,X,Y,A,B):-
A is X - 1,
B is Y + 1,
proverka(Table,A,B).
nolose(Table,X,Y,A,B):-
A is X + 1,
B is Y + 1,
proverka(Table,A,B).
nolose1(Table,X,Y,A,B):-
A is X + 1,
B is Y - 1,
proverka(Table,A,B).
nolose1(Table,X,Y,A,B):-
A is X - 1,
B is Y - 1,
proverka(Table,A,B).
nolose1(Table,X,Y,A,B):-
A is X + 1,
B is Y + 1,
proverka(Table,A,B).
nolose1(Table,X,Y,A,B):-
A is X - 1,
B is Y + 1,
proverka(Table,A,B).
proverka(Table,X,Y):-
X<8, Y<8, X>=0, Y>=0,
member(Table,Element,X,Y),
Element=r.
think(Table,X,Y,K,L):-
(X < 4->
nolose1(Table,X,Y,K,L);
nolose(Table,X,Y,K,L)
).
think1(Table,X,Y,0):-
G_think1 := Y.
think2(Table,X,Y,0):-
G_think2 := Y.
think2(Table,X,Y,Deep):-
Deep1 is Deep - 1,
nolose(Table,X,Y,K,L),
think2(Table,K,L,Deep1).
think1(Table,X,Y,Deep):-
Deep1 is Deep - 1,
nolose1(Table,X,Y,K,L),
think1(Table,K,L,Deep1).
promqna(I,J,El):-
pos(Table),
member(Table,Element,I,J),
(Element =r , G_Br=3 ,I> G_I - 2 ,IG_J - G_K ->
replace(Table,NewTable,El,I,J),
G_Br := 4
else (Element =El , G_Br=4->
replace(Table,NewTable,r,I,J) ,
G_Br :=3,
G_I :=I,
G_J :=J,
( Element =x->
G_K :=0;
G_K :=2
)
else
fail
)
),
set(pos(NewTable)),
drawing(I,J).
/*lose(Table):-
member(Table,o,X,Y),
not(nolose(Table,X,Y,_,_).
*/
win_func(mouse_click(X, Y)) :-
win(),
pos(Table),
member(Table,o,Xo,Yo),
nolose(Table,Xo,Yo,_,_),
convert(I,J,X,Y),
promqna(I,J,x),
pos(TableNew),
(G_Br=4 ->
(nolose(TableNew,Xo,Yo,_,_)->
move(TableNew,Xo,Yo,4);% Polsedniq parametyr na move e za rekursiqta na mislene
(Yo=7->
message("End of game","Anda Menang",!);
message("End of game","Anda Menang",!)
)
)
).
member(Table,El,X,Y):-
member(Table,Row,Y),
member(Row,El,X).
replace(Table,NewTable,NewEl,X,Y):-
member(Table,Row,Y), %opredelqm Row
replace(Row ,NewRow,NewEl,X ),
replace(Table,NewTable,NewRow,Y).
member([E,_,_,_,_,_,_,_],E,0).
member([_,E,_,_,_,_,_,_],E,1).
member([_,_,E,_,_,_,_,_],E,2).
member([_,_,_,E,_,_,_,_],E,3).
member([_,_,_,_,E,_,_,_],E,4).
member([_,_,_,_,_,E,_,_],E,5).
member([_,_,_,_,_,_,E,_],E,6).
member([_,_,_,_,_,_,_,E],E,7).
replace([_,A,B,C,D,E,F,G],[S,A,B,C,D,E,F,G],S,0).
replace([A,_,B,C,D,E,F,G],[A,S,B,C,D,E,F,G],S,1).
replace([A,B,_,C,D,E,F,G],[A,B,S,C,D,E,F,G],S,2).
replace([A,B,C,_,D,E,F,G],[A,B,C,S,D,E,F,G],S,3).
replace([A,B,C,D,_,E,F,G],[A,B,C,D,S,E,F,G],S,4).
replace([A,B,C,D,E,_,F,G],[A,B,C,D,E,S,F,G],S,5).
replace([A,B,C,D,E,F,_,G],[A,B,C,D,E,F,S,G],S,6).
replace([A,B,C,D,E,F,G,_],[A,B,C,D,E,F,G,S],S,7).
color(r):-brush(G_R).
color(x):-brush(G_X).
color(b):-brush(G_B).
color(o):-brush(G_O).
menu_new(press) :-
pen(0,0),
G_R:=brush(rgb(0,0,1)),
G_X:=brush(rgb(255,255,255)),
G_B:=brush(rgb(255,255,0)),
G_O:=brush(rgb(255,0,0)),
set(pos([ [x,b,x,b,x,b,x,b],
[b,r,b,r,b,r,b,r],
[r,b,r,b,r,b,r,b],
[b,r,b,r,b,r,b,r],
[r,b,r,b,r,b,r,b],
[b,r,b,r,b,r,b,r],
[r,b,r,b,r,b,r,b],
[b,r,b,r,b,r,b,o] ])),
G_Br=4,
G_I =0,
G_J =0,
G_K =0,
G_think1=0,
G_think2=0,
update_window(_).
menu_Petunjuk(press) :-
message("Petunjuk","Jebak musuh didalam 4 buah bidak yang kamu punya", !).
menu_exit(press) :-
close_window(_).
Wednesday, February 23, 2011
Listing Game Try Your Luck !!
Berikut ini adalah listing dari game Try Your Luck !!
Subscribe to:
Post Comments (Atom)
0 komentar:
Post a Comment