]> gitweb.factorcode.org Git - factor.git/blob - extra/tetris/tetromino/tetromino.factor
Harmonize spelling
[factor.git] / extra / tetris / tetromino / tetromino.factor
1 ! Copyright (C) 2006, 2007, 2008 Alex Chapman
2 ! See http://factorcode.org/license.txt for BSD license.
3
4 USING: colors math namespaces random sequences ;
5
6 IN: tetris.tetromino
7
8 TUPLE: tetromino states color ;
9
10 C: <tetromino> tetromino
11
12 SYMBOL: tetrominoes
13
14 {
15   [
16     { {
17         { 0 0 } { 1 0 } { 2 0 } { 3 0 }
18       }
19       { { 0 0 }
20         { 0 1 }
21         { 0 2 }
22         { 0 3 }
23       }
24     } COLOR: cyan
25   ] [
26     {
27       {         { 1 0 }
28         { 0 1 } { 1 1 } { 2 1 }
29       } {
30         { 0 0 }
31         { 0 1 } { 1 1 }
32         { 0 2 }
33       } {
34         { 0 0 } { 1 0 } { 2 0 }
35                 { 1 1 }
36       } {
37                 { 1 0 }
38         { 0 1 } { 1 1 }
39                 { 1 2 }
40       }
41     } COLOR: purple
42   ] [
43     { { { 0 0 } { 1 0 }
44         { 0 1 } { 1 1 } }
45     } COLOR: yellow
46   ] [
47     {
48       { { 0 0 } { 1 0 } { 2 0 }
49         { 0 1 }
50       } {
51         { 0 0 } { 1 0 }
52                 { 1 1 }
53                 { 1 2 }
54       } {
55                         { 2 0 }
56         { 0 1 } { 1 1 } { 2 1 }
57       } {
58         { 0 0 }
59         { 0 1 }
60         { 0 2 } { 1 2 }
61       }
62     } COLOR: orange
63   ] [
64     {
65       { { 0 0 } { 1 0 } { 2 0 }
66                         { 2 1 }
67       } {
68                 { 1 0 }
69                 { 1 1 }
70         { 0 2 } { 1 2 }
71       } {
72         { 0 0 }
73         { 0 1 } { 1 1 } { 2 1 }
74       } {
75         { 0 0 } { 1 0 }
76         { 0 1 }
77         { 0 2 }
78       }
79     } COLOR: blue
80   ] [
81     {
82       {          { 1 0 } { 2 0 }
83         { 0 1 } { 1 1 }
84       } {
85         { 0 0 }
86         { 0 1 } { 1 1 }
87                 { 1 2 }
88       }
89     } COLOR: green
90   ] [
91     {
92       {
93         { 0 0 } { 1 0 }
94                 { 1 1 } { 2 1 }
95       } {
96                 { 1 0 }
97         { 0 1 } { 1 1 }
98         { 0 2 }
99       }
100     } COLOR: red
101   ]
102 } [ first2 <tetromino> ] map tetrominoes set-global
103
104 : random-tetromino ( -- tetromino )
105     tetrominoes get random ;
106
107 : blocks-max ( blocks quot -- max )
108     map supremum 1 + ; inline
109
110 : blocks-width ( blocks -- width )
111     [ first ] blocks-max ;
112
113 : blocks-height ( blocks -- height )
114     [ second ] blocks-max ;