Artifact ea4dcd451fd68a5a4560e55109b66f9d191f608e
File games/tic-tac-toe.rx part of check-in [737320dc2b] - add a tic-tac-toe and simple example of canvas' usage by crc on 2011-11-10 15:48:13. [annotate]
with canvas'
3 elements mx my color
: toggle dup @ not swap ! ;
: player @color [ red ] [ blue ] if color toggle ;
: drawBoard ( - )
0 0 @fh @fw white solid box
0 50 150 black hline
0 100 150 black hline
50 0 150 black vline
100 0 150 black vline ;
: top ( n- ) 5 40 40 player solid box ;
: middle ( n- ) 55 40 40 player solid box ;
: bottom ( n- ) 105 40 40 player solid box ;
: column ( nn- )
swap
[ 0 50 within ] [ drop top ] when
[ 50 100 within ] [ drop middle ] when
[ 100 150 within ] [ drop bottom ] when
2drop ;
: row ( nn- )
[ 0 50 within ] [ drop 5 column ] when
[ 50 100 within ] [ drop 55 column ] when
[ 100 150 within ] [ drop 105 column ] when
2drop ;
: moved? ( nn-nnf )
2over @mx = [ @my = ] dip and [ 2over [ !my ] [ !mx ] bi* ] dip ;
: process ( - )
click? [ mouse swap moved? [ row ] [ 2drop ] if ] ifTrue ;
: tic-tac-toe ( - )
clear drawBoard repeat process again ;