factor/extra/tetris/tetromino/tetromino.factor

115 lines
2.1 KiB
Factor
Raw Normal View History

! Copyright (C) 2006, 2007, 2008 Alex Chapman
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: kernel arrays namespaces sequences math math.order
2009-03-07 02:22:21 -05:00
math.vectors colors colors.constants random ;
2007-09-20 18:09:08 -04:00
IN: tetris.tetromino
TUPLE: tetromino states colour ;
C: <tetromino> tetromino
SYMBOL: tetrominoes
{
[
{ {
{ 0 0 } { 1 0 } { 2 0 } { 3 0 }
}
{ { 0 0 }
{ 0 1 }
{ 0 2 }
{ 0 3 }
}
2009-03-07 02:22:21 -05:00
} COLOR: cyan
2007-09-20 18:09:08 -04:00
] [
{
{ { 1 0 }
{ 0 1 } { 1 1 } { 2 1 }
} {
{ 0 0 }
{ 0 1 } { 1 1 }
{ 0 2 }
} {
{ 0 0 } { 1 0 } { 2 0 }
{ 1 1 }
} {
{ 1 0 }
{ 0 1 } { 1 1 }
{ 1 2 }
}
2009-03-07 02:22:21 -05:00
} COLOR: purple
2007-09-20 18:09:08 -04:00
] [
{ { { 0 0 } { 1 0 }
{ 0 1 } { 1 1 } }
2009-03-07 02:22:21 -05:00
} COLOR: yellow
2007-09-20 18:09:08 -04:00
] [
{
{ { 0 0 } { 1 0 } { 2 0 }
{ 0 1 }
} {
{ 0 0 } { 1 0 }
{ 1 1 }
{ 1 2 }
} {
{ 2 0 }
{ 0 1 } { 1 1 } { 2 1 }
} {
{ 0 0 }
{ 0 1 }
{ 0 2 } { 1 2 }
}
2009-03-07 02:22:21 -05:00
} COLOR: orange
2007-09-20 18:09:08 -04:00
] [
{
{ { 0 0 } { 1 0 } { 2 0 }
{ 2 1 }
} {
{ 1 0 }
{ 1 1 }
{ 0 2 } { 1 2 }
} {
{ 0 0 }
{ 0 1 } { 1 1 } { 2 1 }
} {
{ 0 0 } { 1 0 }
{ 0 1 }
{ 0 2 }
}
2009-03-07 02:22:21 -05:00
} COLOR: blue
2007-09-20 18:09:08 -04:00
] [
{
{ { 1 0 } { 2 0 }
{ 0 1 } { 1 1 }
} {
{ 0 0 }
{ 0 1 } { 1 1 }
{ 1 2 }
}
2009-03-07 02:22:21 -05:00
} COLOR: green
2007-09-20 18:09:08 -04:00
] [
{
{
{ 0 0 } { 1 0 }
{ 1 1 } { 2 1 }
} {
{ 1 0 }
{ 0 1 } { 1 1 }
{ 0 2 }
}
2009-03-07 02:22:21 -05:00
} COLOR: red
2007-09-20 18:09:08 -04:00
]
2009-03-07 02:22:21 -05:00
} [ first2 <tetromino> ] map tetrominoes set-global
2007-09-20 18:09:08 -04:00
: random-tetromino ( -- tetromino )
tetrominoes get random ;
: blocks-max ( blocks quot -- max )
map supremum 1 + ; inline
2007-09-20 18:09:08 -04:00
: blocks-width ( blocks -- width )
[ first ] blocks-max ;
: blocks-height ( blocks -- height )
[ second ] blocks-max ;