For Programmers: Free Programming Magazines  


Home > Archive > Prolog > December 2004 > PLEASE HELP!!!!!!!!!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PLEASE HELP!!!!!!!!!
PredAlien

2004-12-07, 4:13 am

ok below is the code for my tic tac toe game in XPCE/prolog so far (copy
and paste it into your text editor and compile)
there are 9 buttons each respesenting an empty square in a game of tic tac
toe. I want for the user to be able to click on one of the buttons, for
that button pressed to be removed, and for either a cross or a nought to
be positioned depending on whether it is player X's go or player O's go.
In my code i have draw functions:
draw1(1) draws an X in the top left square.
draw1(0) draws an O in the top left square.

draw5(1) draws an X in the center square.
draw5(0) draws an O in the center square.

draw9(1) draws an X in the bottom right square.
draw9(0) draws an O in the bottom right square.

i also have a whosgo function:
whosgo(1) displays the text 'Player X go'
whosgo(0) displays the text 'Player O go'


could someone please help me sought out my program so it works as a simple
game of tic tac toe without using CLASSES !!!!! THANKYOU!!!!!




:- pce_global(@grid,new(window('Tic-Tac-Toe',size(500,500)))).


run:-
send(@grid,open),
send(@grid,display,new(@line1,line(300,0
)),point(100,200)),
send(@grid,display,new(@line2,line(300,0
)),point(100,300)),
send(@grid,display,new(@line3,line(0,300
)),point(200,100)),
send(@grid,display,new(@line4,line(0,300
)),point(300,100)),


send(@grid,display,new(@buttonone,button
('1')),point(110,137.5)),
send(@grid,display,new(@buttontwo,button
('2')),point(210,137.5)),
send(@grid,display,new(@buttonthree,butt
on('3')),point(310,137.5)),
send(@grid,display,new(@buttonfour,butto
n('4')),point(110,237.5)),
send(@grid,display,new(@buttonfive,butto
n('5')),point(210,237.5)),
send(@grid,display,new(@buttonsix,button
('6')),point(310,237.5)),
send(@grid,display,new(@buttonseven,butt
on('7')),point(110,337.5)),
send(@grid,display,new(@buttoneight,butt
on('8')),point(210,337.5)),
send(@grid,display,new(@buttonnine,butto
n('9')),point(310,337.5)).

draw1(X):-
(
X is 1
-> free(@buttonone),
send(@board,display,new(@one_cross1,line
(80,80)),point(110,110)),
send(@one_cross1,colour(red)),
send(@board,display,new(@one_cross2,line
(-80,80)),point(190,110)),
send(@one_cross2,colour(red))

; free(@buttonone),
send(@board,display,new(@one_nought,circ
le(80)),point(110,110)),
send(@one_nought,colour(blue))
).

draw2(X):-
(
X is 1
-> free(@buttontwo),
send(@board,display,new(@two_cross1,line
(80,80)),point(110,110)),
send(@two_cross1,colour(red)),
send(@board,display,new(@two_cross2,line
(-80,80)),point(190,110)),
send(@two_cross2,colour(red))

; free(@buttontwo),
send(@board,display,new(@two_nought,circ
le(80)),point(110,110)),
send(@two_nought,colour(blue))
).

draw3(X):-
(
X is 1
-> free(@buttonthree),
send(@board,display,new(@three_cross1,li
ne(80,80)),point(310,110)),
send(@three_cross1,colour(red)),
send(@board,display,new(@three_cross2,li
ne(-80,80)),point(390,110)),
send(@three_cross2,colour(red))


; free(@buttonthree),
send(@board,display,new(@three_nought,ci
rcle(80)),point(310,110)),
send(@three_nought,colour(blue))
).

draw4(X):-
(
X is 1
-> free(@buttonfour),
send(@board,display,new(@four_cross1,lin
e(80,80)),point(110,210)),
send(@four_cross1,colour(red)),
send(@board,display,new(@four_cross2,lin
e(-80,80)),point(190,210)),
send(@four_cross2,colour(red))

; free(@buttonfour),
send(@board,display,new(@four_nought,cir
cle(80)),point(110,210)),
send(@four_nought,colour(blue))
).

draw5(X):-
(
X is 1
-> free(@buttonfive),
send(@board,display,new(@five_cross1,lin
e(80,80)),point(210,210)),
send(@five_cross1,colour(red)),send(@boa
rd,display,new(@five_cross2,line(-80,80)),point(290,210)),
send(@five_cross2,colour(red))
; free(@buttonfive),
send(@board,display,new(@five_nought,cir
cle(80)),point(210,210)),
send(@five_nought,colour(blue))
).

draw6(X):-
(
X is 1
-> free(@buttonsix),
send(@board,display,new(@six_cross1,line
(80,80)),point(310,210)),
send(@six_cross1,colour(red)),send(@boar
d,display,new(@six_cross2,line(-80,80)),point(390,210)),
send(@six_cross2,colour(red))
; free(@buttonsix),
send(@board,display,new(@six_nought,circ
le(80)),point(310,210)),
send(@six_nought,colour(blue))
).

draw7(X):-
(
X is 1
-> free(@buttonseven),
send(@board,display,new(@seven_cross1,li
ne(80,80)),point(110,310)),
send(@seven_cross1,colour(red)),send(@bo
ard,display,new(@seven_cross2,line(-80,80)),point(190,310)),
send(@seven_cross2,colour(red))
; free(@buttonseven),
send(@board,display,new(@seven_nought,ci
rcle(80)),point(110,310)),
send(@seven_nought,colour(blue))
).

draw8(X):-
(
X is 1
-> free(@buttoneight),
send(@board,display,new(@eight_cross1,li
ne(80,80)),point(210,310)),
send(@eight_cross1,colour(red)),send(@bo
ard,display,new(@eight_cross2,line(-80,80)),point(290,310)),
send(@eight_cross2,colour(red))
; free(@buttoneight),
send(@board,display,new(@eight_nought,ci
rcle(80)),point(210,310)),
send(@eight_nought,colour(blue))
).

draw9(X):-
(
X is 1
-> free(@buttonnine),
send(@board,display,new(@nine_cross1,lin
e(80,80)),point(310,310)),
send(@nine_cross1,colour(red)),send(@boa
rd,display,new(@nine_cross2,line(-80,80)),point(390,310)),
send(@nine_cross2,colour(red))
; free(@buttonnine),
send(@board,display,new(@nine_nought,cir
cle(80)),point(310,310)),
send(@nine_nought,colour(blue))
).

whosgo(X):-

(
X is 1
-> send(@board,display,new(@player1,text('
Player X
go!')),point(175,35)),
send(@player1,font,font(arial,bold,24)),

send(@player1,colour(red))

; send(@board,display,new(@player2,text('
Player O go!')),point(175,35)),
send(@player2,font,font(arial,bold,24)),

send(@player2,colour(blue))

).




Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com