xpce/prolog tic-tac-toe

Df0edc8d0f85d69e84fcab7c5fabfcb7
0
rego 101 Dec 06, 2004 at 12:34

hi all,
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,button(‘3’)),point(310,137.5)),
send(@grid,display,new(@buttonfour,button(‘4’)),point(110,237.5)),
send(@grid,display,new(@buttonfive,button(‘5’)),point(210,237.5)),
send(@grid,display,new(@buttonsix,button(‘6’)),point(310,237.5)),
send(@grid,display,new(@buttonseven,button(‘7’)),point(110,337.5)),
send(@grid,display,new(@buttoneight,button(‘8’)),point(210,337.5)),
send(@grid,display,new(@buttonnine,button(‘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,circle(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,circle(80)),point(110,110)),
send(@two_nought,colour(blue))
).

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

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

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

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

draw5(X):-
(
X is 1
-> free(@buttonfive),
send(@board,display,new(@five_cross1,line(80,80)),point(210,210)),

send(@five_cross1,colour(red)),send(@board,display,new(@five_cross2,line(-80,80)),point(290,210)),
send(@five_cross2,colour(red))
; free(@buttonfive),
send(@board,display,new(@five_nought,circle(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(@board,display,new(@six_cross2,line(-80,80)),point(390,210)),
send(@six_cross2,colour(red))
; free(@buttonsix),
send(@board,display,new(@six_nought,circle(80)),point(310,210)),
send(@six_nought,colour(blue))
).

draw7(X):-
(
X is 1
-> free(@buttonseven),
send(@board,display,new(@seven_cross1,line(80,80)),point(110,310)),

send(@seven_cross1,colour(red)),send(@board,display,new(@seven_cross2,line(-80,80)),point(190,310)),
send(@seven_cross2,colour(red))
; free(@buttonseven),
send(@board,display,new(@seven_nought,circle(80)),point(110,310)),
send(@seven_nought,colour(blue))
).

draw8(X):-
(
X is 1
-> free(@buttoneight),
send(@board,display,new(@eight_cross1,line(80,80)),point(210,310)),

send(@eight_cross1,colour(red)),send(@board,display,new(@eight_cross2,line(-80,80)),point(290,310)),
send(@eight_cross2,colour(red))
; free(@buttoneight),
send(@board,display,new(@eight_nought,circle(80)),point(210,310)),
send(@eight_nought,colour(blue))
).

draw9(X):-
(
X is 1
-> free(@buttonnine),
send(@board,display,new(@nine_cross1,line(80,80)),point(310,310)),

send(@nine_cross1,colour(red)),send(@board,display,new(@nine_cross2,line(-80,80)),point(390,310)),
send(@nine_cross2,colour(red))
; free(@buttonnine),
send(@board,display,new(@nine_nought,circle(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))

).

0 Replies

Please log in or register to post a reply.

No replies have been made yet.