]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/tetris/game/game.factor
Harmonize spelling
[factor.git] / extra / tetris / game / game.factor
index 00b5bb6c410a8d16d59f19eb47da80b56154b1de..ac5dbc2579ea3f31944b460ada4e38aae2d21d7c 100644 (file)
@@ -1,6 +1,9 @@
 ! Copyright (C) 2006, 2007, 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators kernel lists math math.functions sequences system tetris.board tetris.piece tetris.tetromino ;
+
+USING: accessors combinators kernel lists math math.functions
+sequences system tetris.board tetris.piece ;
+
 IN: tetris.game
 
 TUPLE: tetris
@@ -18,8 +21,9 @@ CONSTANT: default-height 20
 : <tetris> ( width height -- tetris )
     dupd <board> swap <piece-llist>
     tetris new swap >>pieces swap >>board ;
-        
-: <default-tetris> ( -- tetris ) default-width default-height <tetris> ;
+
+: <default-tetris> ( -- tetris )
+    default-width default-height <tetris> ;
 
 : <new-tetris> ( old -- new )
     board>> [ width>> ] [ height>> ] bi <tetris> ;
@@ -31,14 +35,14 @@ CONSTANT: default-height 20
 : toggle-pause ( tetris -- )
     [ not ] change-paused? drop ;
 
-: level>> ( tetris -- level )
-    rows>> 1+ 10 / ceiling ;
+: level ( tetris -- level )
+    rows>> 1 + 10 / ceiling ;
 
 : update-interval ( tetris -- interval )
-    level>> 1- 60 * 1000 swap - ;
+    level 1 - 60 * 1,000,000,000 swap - ;
 
 : add-block ( tetris block -- )
-    over board>> spin current-piece tetromino>> colour>> set-block ;
+    over [ board>> ] 2dip current-piece tetromino>> color>> set-block ;
 
 : game-over? ( tetris -- ? )
     [ board>> ] [ next-piece ] bi piece-valid? not ;
@@ -57,10 +61,10 @@ CONSTANT: default-height 20
         { 2 [ 100 ] }
         { 3 [ 300 ] }
         { 4 [ 1200 ] }
-    } case swap 1+ * ;
+    } case swap 1 + * ;
 
 : add-score ( tetris n-rows -- tetris )
-    over level>> swap rows-score swap [ + ] change-score ;
+    over level swap rows-score swap [ + ] change-score ;
 
 : add-rows ( tetris rows -- tetris )
     swap [ + ] change-rows ;
@@ -69,8 +73,8 @@ CONSTANT: default-height 20
     [ add-score ] keep add-rows drop ;
 
 : lock-piece ( tetris -- )
-    [ dup current-piece piece-blocks [ add-block ] with each ] keep
-    new-current-piece dup board>> check-rows score-rows ;
+    [ dup current-piece piece-blocks [ add-block ] with each ]
+    [ new-current-piece dup board>> check-rows score-rows ] bi ;
 
 : can-rotate? ( tetris -- ? )
     [ board>> ] [ current-piece clone 1 rotate-piece ] bi piece-valid? ;
@@ -86,7 +90,7 @@ CONSTANT: default-height 20
     [ drop board>> ] [ [ current-piece clone ] dip move-piece ] 2bi piece-valid? ;
 
 : tetris-move ( tetris move -- ? )
-    #! moves the piece if possible, returns whether the piece was moved
+    ! moves the piece if possible, returns whether the piece was moved
     2dup can-move? [
         [ current-piece ] dip move-piece drop t
     ] [
@@ -104,10 +108,10 @@ CONSTANT: default-height 20
     dup { 0 1 } tetris-move [ move-drop ] [ lock-piece ] if ;
 
 : update ( tetris -- )
-    millis over last-update>> -
+    nano-count over last-update>> -
     over update-interval > [
         dup move-down
-        millis >>last-update
+        nano-count >>last-update
     ] when drop ;
 
 : ?update ( tetris -- )