Not logged in
Overview
SHA1 Hash:737320dc2be5ed6fc68d91082d0f9bcf97f45116
Date: 2011-11-10 15:48:13
User: crc
Comment:add a tic-tac-toe and simple example of canvas' usage
Timelines: family | ancestors | descendants | both | trunk
Other Links: files | manifest
Tags And Properties
Changes
[hide diffs]    [patch]

Added games/spots.rx version [9971286b227f8383]

@@ -0,0 +1,4 @@
+with canvas'
+: spots
+  clear
+  repeat click? [ mouse 4 solid red circle ] ifTrue again ;

Added games/tic-tac-toe.rx version [ea4dcd451fd68a5a]

@@ -0,0 +1,40 @@
+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 ;
+