Page 1 of 1

TicTacToe

Posted: Thu Jan 02, 2014 9:37 am
by viro
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

Re: TicTacToe

Posted: Thu Jan 02, 2014 5:30 pm
by Klaus
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

Re: TicTacToe

Posted: Thu Jan 02, 2014 5:34 pm
by Klaus
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

Re: TicTacToe

Posted: Fri Jan 03, 2014 12:05 pm
by viro
just done your suggested code cleaning^^

still not happy with the reference to btn numbers though :/
everybody may use this stack without my permission :)