TicTacToe

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
viro
Posts: 52
Joined: Fri Jul 05, 2013 6:59 pm
Location: Germany, Hesse

TicTacToe

Post by viro » Thu Jan 02, 2014 9:37 am

Hello community,
i created a tictactoe game and would like you to point me at how to simplify the algorithm to check wether someonehas won or not..
funtion is located in main card script.

regards viro
Attachments
tictactoe.zip
(2.61 KiB) Downloaded 473 times
the funniest thing about this particular signature is that by the time you realize it doesn't say anything it's too late to stop reading it

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: TicTacToe

Post by Klaus » Thu Jan 02, 2014 5:30 pm

HI viro,

sehr schön! :D
Thanks for sharing this one!

Some general hints::
1. Avoid using NUMBERS as the NAMES of objects in any case!
This will "confuse" the engine and might give unexspected results 8)

In your case it works, because your buttons are correctly named like their LAYERS:
button "1" = first button etc.

2. When "sending" commands, put the commands in QUOTES:
...
send "whatever" to this cd
...
But since the card script is in the message heirachie, you do not need to send
this command at all, just execute it (NO quotes in that case):

Code: Select all

...
   if tName is "x" then
         checkWin
         put "o" into tName
      else
...
The algorithm for checking is OK, one might "finetune" the syntax, but it works
"und dat is de Hauptsach', Jung"! :D


Best

Klaus

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: TicTacToe

Post by Klaus » Thu Jan 02, 2014 5:34 pm

And here some "code cleaning" for the script of grp "feld" (??? :D )

Code: Select all

global tID,tName,tGameStarted,tFirstMove

on mouseUp
   put the childControlIDs of group "feld" into tID
   
   ## I avoid nested IF THEN clauses wherever possible:
   if the label of the target <> empty then
      exit to top
   end if
   ## ONE IF END IF less so far! :-D
   
   set the label of the target to tName
   ## We need to check right now, to be able to stop the game immediately after clicking!
   checkWin
   
   put true into tGameStarted
   if tName is "x" then
      put "O" into tName
   else
      put "X" into tName
   end if
   put false into tFirstMove
   put tName into fld "fldReihe"
end mouseUp

viro
Posts: 52
Joined: Fri Jul 05, 2013 6:59 pm
Location: Germany, Hesse

Re: TicTacToe

Post by viro » Fri Jan 03, 2014 12:05 pm

just done your suggested code cleaning^^

still not happy with the reference to btn numbers though :/
everybody may use this stack without my permission :)
Attachments
tictactoe.zip
(2.6 KiB) Downloaded 399 times
the funniest thing about this particular signature is that by the time you realize it doesn't say anything it's too late to stop reading it

Post Reply

Return to “Games”