SEKILAS TENTANG APLIKASI GAME PERHITUNGAN DI DALAM PUZZLE
Aplikasi ini berjudul “Game Perhitungan didalam Puzzle”. Didalam aplikasi ini terdapat angka yang terdiri dari 1 sampai 9 yang harus dipilih pemain ke lingkaran pada puzzle yang telah disediakan sehingga hasil dari penjumlahannya sama dengan yang teracak didalam kotak yang berada disebelah puzzle.
Berikut adalah listing dari game ini :
?- set(yel(1)),
window( _,_,win_func(_), "Numpuzzle",100,100,600,500).
%%%%%%%%%%%%%%%%%%
% WINDOW %
%%%%%%%%%%%%%%%%%%
win_func(init):- window_brush(_,rgb(0,0,0)),
menu(pop_up, _,_,game(_),"Game"),
init_data,random.
win_func(paint):- set(yel(1)),
pen(1,rgb(255,100,0)),
color_text_back(_,rgb(0,0,0)),
color_text(_,rgb(255,100,0)),
draw_ell,
eval_sum,
draw_score,
pen(3,rgb(255,100,0)),
draw_pull(1),
draw_table.
win_func(mouse_click(X,Y)):- target(X,Y).
game(init):-
menu(normal, _,_,s1(_),"New Game"),
menu(separator, _,_,fail(_),_),
menu(normal, _,_,s2(_),"Exit").
s1(press):-start.
s2(press):-close_window(_).
%%%%%%%%%%%%%%%%
% INIT %
%%%%%%%%%%%%%%%%
init_data:-
assert(data(1,1,0)),
assert(data(2,1,0)),
assert(data(3,1,0)),
assert(data(1,2,0)),
assert(data(2,2,0)),
assert(data(3,2,0)),
assert(data(1,3,0)),
assert(data(2,3,0)),
assert(data(3,3,0)).
col(yellow):- brush(rgb(255,255,0)).
col(red):- brush(rgb(255,0,0)).
col(green):- brush(rgb(0,255,0)).
col(black):- brush(rgb(0,0,0)).
%%%%%%%%%%%%%%%%
% DRAW %
%%%%%%%%%%%%%%%%
draw_circle(X,Y,C):-col(C), ellipse(X,Y,X + 40,Y + 40).
draw_circle_text(X,Y,I):- I1 is print(I),
text_out(X + 17,Y + 13,I1).
draw_table:- data(X,Y,_),
X1 is 40 + 90 * (X - 1),
Y1 is 80 + 90 * (Y - 1),
draw_circle(X1,Y1,black),
draw_line(X1,Y1,X,Y),
fail.
draw_line(X1,Y1,X,Y):- X < 3,
line(X1 + 40,Y1 + 20,X1 + 90,Y1 + 20).
draw_line(X1,Y1,X,Y):- Y < 3,
line(X1 + 20,Y1 + 40,X1 + 20,Y1 + 90).
draw_line(X1,Y1,X,Y).
draw_pull(I):- I < 10,
draw_p1(I),
I1 is print(I),
text_out(45 + 60 * (I - 1),355, I1),
draw_circle(30,380,yellow),
I2 is I + 1,
draw_pull(I2).
draw_pull(10).
draw_p1(I):- X1 is 30 + 60 * (I - 1),
draw_circle(X1,380,green).
draw_ell:- col(black),
ellipse(70,120,140,170),
ellipse(160,120,230,170),
ellipse(70,210,140,260),
ellipse(160,210,230,260).
draw_sum(X,Y,T):-
T1 is print(T),
X1 is 99 + 90 * (X - 1),
Y1 is 136 + 90 * (Y - 1),
text_out(X1,Y1," "),
text_out(X1,Y1,T1).
eval_sum:- sum(S1,S2,S3,S4),
draw_sum(1,1,S1),
draw_sum(1,2,S2),
draw_sum(2,1,S3),
draw_sum(2,2,S4).
draw_score:- round_rect(370,160,470,250,17,17),
line(420,160,420,250),
line(370,205,470,205),
tem(S1,S2,S3,S4),
S11 is print(S1),
S22 is print(S2),
S33 is print(S3),
S44 is print(S4),
text_out(390,175,S11),
text_out(438,175,S22),
text_out(390,220,S33),
text_out(438,220,S44).
%%%%%%%%%%%%%%%%%%
% RANDOM %
%%%%%%%%%%%%%%%%%%
initial(G,List):-toX(G,L),forX(G,L,List).
toX(0,[]).
toX(X,[H|T]):-H is X,Z is X - 1,toX(Z,T).
delel([H|T],1,T,H).
delel([H1|T1],N,[H2|T2],E):-H2 is H1,Z is N - 1,
delel(T1,Z,T2,E).
forX(0,_,[]).
forX(D,L,[H|T]):-P is random(D) + 1,delel(L,P,L1,Z),
H is Z,
Temp is D - 1,
forX(Temp,L1,T).
posel([H|T],1,H).
posel([H|T],N,E):- N1 is N - 1,posel(T,N1,E).
random:- initial(9,L),
posel(L,1,E1),posel(L,2,E2),posel(L,3,E3),
posel(L,4,E4),posel(L,5,E5),posel(L,6,E6),
posel(L,7,E7),posel(L,8,E8),posel(L,9,E9),
S1 is E1 + E2 + E4 + E5,
S2 is E2 + E3 + E5 + E6,
S3 is E4 + E5 + E7 + E8,
S4 is E5 + E6 + E8 + E9,
set(tem(S1,S2,S3,S4)).
%%%%%%%%%%%%%%%%%
% START %
%%%%%%%%%%%%%%%%%
erase:- data(A,B,C),retract(data(A,B,C)),fail.
erase.
start:- erase,init_data,random,update_window(_).
%%%%%%%%%%%%%%%%%%%%
% CONTROL %
%%%%%%%%%%%%%%%%%%%%
target(X,Y):- X >= 30,X =< 550,
I is (X + 30)//60,
abs(Y - 400) =< 20,
abs(X - (50 + 60 * (I - 1))) =< 20,
yel(T),
not(data(_,_,I)),
(T =\= 0 -> draw_circle(30 + 60 * (T - 1),380,green)),
draw_circle(30 + 60 * (I - 1),380,yellow),
set(yel(I)).
target(X,Y):- X >= 40, X =< 260,
Y >= 80, Y =< 300,
X1 is (X + 50)//90,
Y1 is (Y + 10)//90,
abs(X - (60 + 90 * (X1 - 1))) =< 20,
abs(Y - (100 + 90 * (Y1 - 1))) =< 20,
put_pull(X1,Y1).
target(X,Y).
put_pull(X1,Y1):- data(X1,Y1,TT), TT =:= 0,
put_next(X1,Y1).
put_pull(X1,Y1):- data(X1,Y1,T),
retract(data(X1,Y1,T)),
assert(data(X1,Y1,0)),
yel(T1),
T_new is 30 + 60 * (T - 1),
draw_circle(T_new,380,yellow),
X is 40 + 90 * (X1 - 1),
Y is 80 + 90 * (Y1 - 1),
eval_sum,
draw_circle_text(X,Y," "),
set(yel(T)),!,
(T1 =\= 0 -> T_old is 30 + 60 * (T1 - 1),
draw_circle(T_old,380,green)).
put_next(X1,Y1):- X is 40 + 90 * (X1 - 1),
Y is 80 + 90 * (Y1 - 1),
yel(T),
draw_circle_text(X,Y,T),
retract(data(X1,Y1,_)),
assert(data(X1,Y1,T)),
XY is 30 + 60 * (T - 1),
draw_circle(XY,380,red),
eval_sum,
check(T).
check(T):- data(_,_,0),change(T).
check(T):- res,set(yel(0)).
change(T):-T1 is T + 1,T1 =< 9, not(data(_,_,T1)),set(yel(T1)),
X is 30 + 60 * (T1 - 1),draw_circle(X,380,yellow).
change(T):-T =:= 9,change(0).
change(T):-T1 is T + 1, change(T1).
%%%%%%%%%%%%%%%%%%
% RESULT %
%%%%%%%%%%%%%%%%%%
sum(S1,S2,S3,S4):- data(1,1,T1),data(1,2,T2),data(1,3,T3),
data(2,1,T4),data(2,2,T5),data(2,3,T6),
data(3,1,T7),data(3,2,T8),data(3,3,T9),
S1 is T1 + T2 + T4 + T5,
S2 is T2 + T3 + T5 + T6,
S3 is T4 + T5 + T7 + T8,
S4 is T5 + T6 + T8 + T9.
res:- sum(S1,S2,S3,S4),
tem(S11,S22,S33,S44),
S1 =:= S11, S2 =:= S33, S3 =:= S22, S4 =:= S44,
you_win,erase.
res.
you_win:- beep(t),
color_text(_,rgb(0,0,255)),
text_out(390,140,"You win!!!"),wait(0.5),
text_out(390,140," "),wait(0.5),
text_out(390,140,"You win!!!"),wait(0.5).
OUTPUT GAME
Tidak ada komentar:
Posting Komentar