.
This commit is contained in:
Executable
BIN
Binary file not shown.
Executable
+147
@@ -0,0 +1,147 @@
|
||||
function Main.main 1
|
||||
push constant 1
|
||||
neg
|
||||
pop local 0
|
||||
push constant 0
|
||||
push constant 20
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 17
|
||||
call String.new 1
|
||||
push constant 87
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 109
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 84
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 115
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
push constant 2000
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push constant 0
|
||||
lt
|
||||
push local 0
|
||||
push constant 100
|
||||
gt
|
||||
or
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 33
|
||||
call String.new 1
|
||||
push constant 69
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 117
|
||||
call String.appendChar 2
|
||||
push constant 109
|
||||
call String.appendChar 2
|
||||
push constant 98
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 98
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 119
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 48
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 100
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 49
|
||||
call String.appendChar 2
|
||||
push constant 48
|
||||
call String.appendChar 2
|
||||
push constant 48
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
call Keyboard.readInt 1
|
||||
pop local 0
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 2000
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
push local 0
|
||||
call Tetris.tetris 1
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
Executable
+2219
File diff suppressed because it is too large
Load Diff
Executable
+999
@@ -0,0 +1,999 @@
|
||||
function Tetris.tetris 25
|
||||
call Piece.init 0
|
||||
pop temp 0
|
||||
call Tetris.border 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
pop static 0
|
||||
push constant 25
|
||||
call Array.new 1
|
||||
pop local 23
|
||||
push constant 0
|
||||
push local 23
|
||||
add
|
||||
push constant 16
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 15
|
||||
push constant 0
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 0
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 1
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 15
|
||||
push constant 15
|
||||
push constant 0
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 1
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 2
|
||||
push local 23
|
||||
add
|
||||
push constant 32
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 0
|
||||
push constant 32
|
||||
push constant 47
|
||||
push constant 47
|
||||
push constant 2
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 3
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 15
|
||||
push constant 16
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 3
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 4
|
||||
push local 23
|
||||
add
|
||||
push constant 16
|
||||
push constant 0
|
||||
push constant 47
|
||||
push constant 15
|
||||
push constant 0
|
||||
push constant 16
|
||||
push constant 31
|
||||
push constant 31
|
||||
push constant 4
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 5
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 15
|
||||
push constant 32
|
||||
push constant 0
|
||||
push constant 63
|
||||
push constant 15
|
||||
push constant 5
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 6
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 15
|
||||
push constant 31
|
||||
push constant 16
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 31
|
||||
push constant 6
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push argument 0
|
||||
push constant 3
|
||||
call Math.multiply 2
|
||||
pop static 1
|
||||
call Tetris.randomNumber 0
|
||||
pop static 2
|
||||
push constant 0
|
||||
push constant 0
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 7
|
||||
call String.new 1
|
||||
push constant 80
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
push static 0
|
||||
call Output.printInt 1
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
push constant 12
|
||||
call String.new 1
|
||||
push constant 78
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 120
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 80
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
label WHILE_EXP0
|
||||
push constant 0
|
||||
not
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push static 2
|
||||
pop local 12
|
||||
call Tetris.randomNumber 0
|
||||
pop static 2
|
||||
push local 12
|
||||
push local 23
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 24
|
||||
push constant 0
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 3
|
||||
push constant 1
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 4
|
||||
push constant 2
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 5
|
||||
push constant 3
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 6
|
||||
push constant 4
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 7
|
||||
push constant 5
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 8
|
||||
push constant 6
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 9
|
||||
push constant 7
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 10
|
||||
push constant 8
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 14
|
||||
push local 3
|
||||
push constant 240
|
||||
add
|
||||
push local 4
|
||||
push local 5
|
||||
push constant 240
|
||||
add
|
||||
push local 6
|
||||
push local 7
|
||||
push constant 240
|
||||
add
|
||||
push local 8
|
||||
push local 9
|
||||
push constant 240
|
||||
add
|
||||
push local 10
|
||||
push local 14
|
||||
call Piece.new 9
|
||||
pop local 0
|
||||
push local 0
|
||||
call Piece.draw 1
|
||||
not
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
call Tetris.finish 0
|
||||
not
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push constant 0
|
||||
return
|
||||
label IF_FALSE1
|
||||
label IF_FALSE0
|
||||
push static 2
|
||||
push local 23
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 24
|
||||
push constant 0
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 3
|
||||
push constant 1
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 4
|
||||
push constant 2
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 5
|
||||
push constant 3
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 6
|
||||
push constant 4
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 7
|
||||
push constant 5
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 8
|
||||
push constant 6
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 9
|
||||
push constant 7
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 10
|
||||
push constant 8
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 14
|
||||
push local 3
|
||||
push constant 16
|
||||
add
|
||||
push local 4
|
||||
push constant 32
|
||||
add
|
||||
push local 5
|
||||
push constant 16
|
||||
add
|
||||
push local 6
|
||||
push constant 32
|
||||
add
|
||||
push local 7
|
||||
push constant 16
|
||||
add
|
||||
push local 8
|
||||
push constant 32
|
||||
add
|
||||
push local 9
|
||||
push constant 16
|
||||
add
|
||||
push local 10
|
||||
push constant 32
|
||||
add
|
||||
push local 14
|
||||
call Piece.new 9
|
||||
pop local 1
|
||||
push local 1
|
||||
call Piece.draw 1
|
||||
pop temp 0
|
||||
label WHILE_EXP1
|
||||
push local 0
|
||||
call Piece.getMove 1
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push constant 0
|
||||
pop local 15
|
||||
label WHILE_EXP2
|
||||
push local 15
|
||||
push constant 3
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END2
|
||||
call Keyboard.keyPressed 0
|
||||
pop local 11
|
||||
push local 11
|
||||
push constant 130
|
||||
eq
|
||||
if-goto IF_TRUE2
|
||||
goto IF_FALSE2
|
||||
label IF_TRUE2
|
||||
push local 0
|
||||
call Piece.moveLeft 1
|
||||
pop temp 0
|
||||
push constant 80
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
label IF_FALSE2
|
||||
push local 11
|
||||
push constant 132
|
||||
eq
|
||||
if-goto IF_TRUE3
|
||||
goto IF_FALSE3
|
||||
label IF_TRUE3
|
||||
push local 0
|
||||
call Piece.moveRight 1
|
||||
pop temp 0
|
||||
push constant 80
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
label IF_FALSE3
|
||||
push local 11
|
||||
push constant 131
|
||||
eq
|
||||
if-goto IF_TRUE4
|
||||
goto IF_FALSE4
|
||||
label IF_TRUE4
|
||||
push local 0
|
||||
call Piece.rotate 1
|
||||
pop temp 0
|
||||
label IF_FALSE4
|
||||
push local 11
|
||||
push constant 133
|
||||
eq
|
||||
if-goto IF_TRUE5
|
||||
goto IF_FALSE5
|
||||
label IF_TRUE5
|
||||
push local 0
|
||||
call Piece.moveDown 1
|
||||
pop temp 0
|
||||
push local 0
|
||||
call Piece.moveDown 1
|
||||
pop temp 0
|
||||
label IF_FALSE5
|
||||
push local 15
|
||||
push constant 1
|
||||
add
|
||||
pop local 15
|
||||
goto WHILE_EXP2
|
||||
label WHILE_END2
|
||||
push local 0
|
||||
call Piece.moveDown 1
|
||||
pop temp 0
|
||||
push local 2
|
||||
push constant 1
|
||||
add
|
||||
pop local 2
|
||||
push constant 80
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push constant 0
|
||||
pop local 2
|
||||
push local 0
|
||||
call Piece.dispose 1
|
||||
pop temp 0
|
||||
call Tetris.completeRow 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
push constant 7
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push static 0
|
||||
call Output.printInt 1
|
||||
pop temp 0
|
||||
push constant 0
|
||||
call Screen.setColor 1
|
||||
pop temp 0
|
||||
push constant 16
|
||||
push constant 32
|
||||
push constant 80
|
||||
push constant 96
|
||||
call Screen.drawRectangle 4
|
||||
pop temp 0
|
||||
push constant 0
|
||||
not
|
||||
call Screen.setColor 1
|
||||
pop temp 0
|
||||
push local 1
|
||||
call Piece.dispose 1
|
||||
pop temp 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.completeRow 4
|
||||
push constant 16384
|
||||
push constant 11
|
||||
add
|
||||
pop local 0
|
||||
push constant 15
|
||||
pop local 1
|
||||
label WHILE_EXP0
|
||||
push local 1
|
||||
push constant 0
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 0
|
||||
not
|
||||
pop local 3
|
||||
push constant 0
|
||||
pop local 2
|
||||
label WHILE_EXP1
|
||||
push local 2
|
||||
push constant 10
|
||||
lt
|
||||
push local 3
|
||||
and
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push local 0
|
||||
push local 2
|
||||
add
|
||||
push local 1
|
||||
push constant 512
|
||||
call Math.multiply 2
|
||||
add
|
||||
call Memory.peek 1
|
||||
push local 3
|
||||
and
|
||||
pop local 3
|
||||
push local 2
|
||||
push constant 1
|
||||
add
|
||||
pop local 2
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push local 3
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 0
|
||||
call Screen.setColor 1
|
||||
pop temp 0
|
||||
push constant 176
|
||||
push local 1
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
push constant 335
|
||||
push local 1
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
push constant 15
|
||||
add
|
||||
call Screen.drawRectangle 4
|
||||
pop temp 0
|
||||
push static 0
|
||||
push constant 1
|
||||
add
|
||||
pop static 0
|
||||
push local 1
|
||||
call Tetris.shift 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push local 1
|
||||
push constant 1
|
||||
sub
|
||||
pop local 1
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.shift 5
|
||||
push constant 16384
|
||||
push constant 11
|
||||
add
|
||||
pop local 2
|
||||
label WHILE_EXP0
|
||||
push argument 0
|
||||
push constant 1
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 0
|
||||
pop local 0
|
||||
label WHILE_EXP1
|
||||
push local 0
|
||||
push constant 10
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push constant 0
|
||||
pop local 4
|
||||
label WHILE_EXP2
|
||||
push local 4
|
||||
push constant 16
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END2
|
||||
push local 2
|
||||
push local 0
|
||||
add
|
||||
push argument 0
|
||||
push constant 1
|
||||
sub
|
||||
push constant 512
|
||||
call Math.multiply 2
|
||||
push local 4
|
||||
push constant 32
|
||||
call Math.multiply 2
|
||||
add
|
||||
add
|
||||
pop local 3
|
||||
push local 3
|
||||
call Memory.peek 1
|
||||
pop local 1
|
||||
push local 2
|
||||
push local 0
|
||||
add
|
||||
push argument 0
|
||||
push constant 512
|
||||
call Math.multiply 2
|
||||
push local 4
|
||||
push constant 32
|
||||
call Math.multiply 2
|
||||
add
|
||||
add
|
||||
push local 1
|
||||
call Memory.poke 2
|
||||
pop temp 0
|
||||
push local 3
|
||||
push constant 0
|
||||
call Memory.poke 2
|
||||
pop temp 0
|
||||
push local 4
|
||||
push constant 1
|
||||
add
|
||||
pop local 4
|
||||
goto WHILE_EXP2
|
||||
label WHILE_END2
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push argument 0
|
||||
push constant 1
|
||||
sub
|
||||
pop argument 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.border 0
|
||||
push constant 175
|
||||
push constant 0
|
||||
push constant 175
|
||||
push constant 255
|
||||
call Screen.drawLine 4
|
||||
pop temp 0
|
||||
push constant 336
|
||||
push constant 0
|
||||
push constant 336
|
||||
push constant 255
|
||||
call Screen.drawLine 4
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.newPiece 1
|
||||
push constant 9
|
||||
call Array.new 1
|
||||
pop local 0
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
push argument 0
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
push argument 1
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 2
|
||||
push local 0
|
||||
add
|
||||
push argument 2
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 3
|
||||
push local 0
|
||||
add
|
||||
push argument 3
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 4
|
||||
push local 0
|
||||
add
|
||||
push argument 4
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 5
|
||||
push local 0
|
||||
add
|
||||
push argument 5
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 6
|
||||
push local 0
|
||||
add
|
||||
push argument 6
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 7
|
||||
push local 0
|
||||
add
|
||||
push argument 7
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 8
|
||||
push local 0
|
||||
add
|
||||
push argument 8
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push local 0
|
||||
return
|
||||
function Tetris.randomNumber 4
|
||||
push constant 7
|
||||
pop local 0
|
||||
push constant 13
|
||||
pop local 1
|
||||
push constant 1133
|
||||
pop local 2
|
||||
push local 0
|
||||
push static 1
|
||||
call Math.multiply 2
|
||||
push local 1
|
||||
add
|
||||
pop local 3
|
||||
push local 3
|
||||
push local 2
|
||||
call Tetris.mod 2
|
||||
pop static 1
|
||||
push static 1
|
||||
push constant 7
|
||||
call Tetris.mod 2
|
||||
return
|
||||
function Tetris.finish 1
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
push constant 10
|
||||
push constant 24
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 12
|
||||
call String.new 1
|
||||
push constant 89
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 117
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 115
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
push static 0
|
||||
call Output.printInt 1
|
||||
pop temp 0
|
||||
push constant 10000
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
push constant 10
|
||||
push constant 0
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 63
|
||||
call String.new 1
|
||||
push constant 87
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 117
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 100
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 121
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 117
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 107
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 112
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 121
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 103
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 44
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 102
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 121
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 115
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 107
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
call String.appendChar 2
|
||||
push constant 89
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 100
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 102
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
call String.appendChar 2
|
||||
push constant 78
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
call Keyboard.readChar 0
|
||||
pop local 0
|
||||
push local 0
|
||||
push constant 89
|
||||
eq
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
label IF_FALSE0
|
||||
push local 0
|
||||
push constant 78
|
||||
eq
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
call Sys.halt 0
|
||||
pop temp 0
|
||||
label IF_FALSE1
|
||||
push constant 0
|
||||
not
|
||||
return
|
||||
function Tetris.mod 2
|
||||
push argument 0
|
||||
push argument 1
|
||||
lt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push argument 0
|
||||
return
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push argument 1
|
||||
call Math.divide 2
|
||||
push argument 1
|
||||
call Math.multiply 2
|
||||
pop local 1
|
||||
push argument 0
|
||||
push local 1
|
||||
sub
|
||||
pop local 0
|
||||
push local 0
|
||||
return
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
class Main {
|
||||
function void main (){
|
||||
var int s;
|
||||
let s = -1;
|
||||
do Output.moveCursor(0,20);
|
||||
do Output.printString("Welcome to Tetris");
|
||||
do Sys.wait(2000);
|
||||
do Output.println();
|
||||
do Output.println();
|
||||
do Output.println();
|
||||
while ((s < 0) | (s > 100)){ // gets a number used for seed for the random function
|
||||
let s = Keyboard.readInt("Enter a number between 0 and 100:");
|
||||
do Screen.clearScreen();
|
||||
}
|
||||
do Sys.wait(2000);
|
||||
do Tetris.tetris(s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
+473
@@ -0,0 +1,473 @@
|
||||
class Piece {
|
||||
static int lBorder, rBorder, uBorder, dBorder, st;
|
||||
field int x1, y1, x2, y2, x3, y3, x4, y4, piece, direction;
|
||||
field bool move;
|
||||
static Array st;
|
||||
|
||||
constructor Piece new(int Ax1, int Ay1, int Ax2, int Ay2, int Ax3, int Ay3, int Ax4, int Ay4, int p) {
|
||||
let x1 = Ax1;
|
||||
let y1 = Ay1;
|
||||
let x2 = Ax2;
|
||||
let y2 = Ay2;
|
||||
let x3 = Ax3;
|
||||
let y3 = Ay3;
|
||||
let x4 = Ax4;
|
||||
let y4 = Ay4;
|
||||
let piece = p;
|
||||
let direction = 0;
|
||||
let move = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
function void init(){
|
||||
var int a;
|
||||
let lBorder = 0;
|
||||
let rBorder = 511;
|
||||
let uBorder = 0;
|
||||
let dBorder = 255;
|
||||
let st = Array.new(16);
|
||||
let st[0] = 1;
|
||||
while (a < 15){
|
||||
let a = a + 1;
|
||||
let st[a] = st[a - 1] + st[a - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
method void dispose() {
|
||||
do Memory.deAlloc(this);
|
||||
return;
|
||||
}
|
||||
|
||||
/** draws 2 rectangles also checks if there is a piece at the spawn which will indicate end of the game. */
|
||||
method bool draw() {
|
||||
var bool finish;
|
||||
let finish = true;
|
||||
let finish = Piece.sample(x1,y1) & finish;
|
||||
let finish = Piece.sample(x2,y2) & finish;
|
||||
let finish = Piece.sample(x3,y3) & finish;
|
||||
let finish = Piece.sample(x4,y4) & finish;
|
||||
if (finish){
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Erases the square from the screen. */
|
||||
method void erase() {
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y2, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
return;
|
||||
}
|
||||
/** checks if those coodinates hold any value > 0. */
|
||||
function bool sample(int x, int y){
|
||||
var int value, address, bit, memBlock;
|
||||
let memBlock = x / 16;
|
||||
let address = (32 * y) + memBlock + 16384;
|
||||
if (address > 24576){
|
||||
return false;
|
||||
}
|
||||
let value = Memory.peek(address);
|
||||
if (value = 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
method bool getMove(){
|
||||
return move;
|
||||
}
|
||||
|
||||
/** Checks if the piece can move in the given direction(dir). */
|
||||
method bool fullSample(int dir){
|
||||
var int size1, size2, i, j;
|
||||
var bool result, flagUpon;
|
||||
if (dir = 1){ //down
|
||||
let size1 = x2 - x1;
|
||||
let size2 = x4 - x3;
|
||||
let result = true;
|
||||
while (i < size1){ // for each block of the first rectangle
|
||||
let j = 0;
|
||||
let flagUpon = false;
|
||||
while (j < size2){ // for each block of the second rectangle
|
||||
if ((x1 + i) = (x3 + j)){ // if this block of the first rectangle sits upon a block of the second rectangle
|
||||
let flagUpon = true;
|
||||
}
|
||||
let result = result & Piece.sample(x3 + j, y4 + 1); // if there is a block under the second rectangle
|
||||
let j = j + 16; // sets the coords for the next block of the second rectangle
|
||||
}
|
||||
if (~(flagUpon)){
|
||||
let result = result & Piece.sample(x1 + i, y2 + 1); // if there is a block under the first rectangle
|
||||
}
|
||||
let i = i + 16; // sets the coords for the next block of the firs rectangle
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else{
|
||||
if (dir = 2){ //right
|
||||
let size1 = y2 - y1;
|
||||
let size2 = y4 - y3;
|
||||
let result = true;
|
||||
while (i < size1){
|
||||
let j = 0;
|
||||
let flagUpon = false;
|
||||
while (j < size2){
|
||||
if ((y1 + i) = (y3 + j)){
|
||||
let flagUpon = true;
|
||||
}
|
||||
let result = result & Piece.sample(x4 + 1, (y3 + j));
|
||||
let j = j + 16;
|
||||
}
|
||||
if (~(flagUpon)){
|
||||
let result = result & Piece.sample(x2 + 1, (y1 + i));
|
||||
}
|
||||
let i = i +16;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else{ // left
|
||||
let size1 = y2 - y1;
|
||||
let size2 = y4 - y3;
|
||||
let result = true;
|
||||
while (i < size2){
|
||||
let j = 0;
|
||||
let flagUpon = false;
|
||||
while (j < size1){
|
||||
if ((y3 + i) = (y1 + j)){
|
||||
let flagUpon = true;
|
||||
}
|
||||
let result = result & Piece.sample(x1 - 1, (y1 + j));
|
||||
let j = j + 16;
|
||||
}
|
||||
if (~(flagUpon)){
|
||||
let result = result & Piece.sample(x3 - 1, (y3 + i));
|
||||
}
|
||||
let i = i + 16;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Moves the game piece 16 pixels down. */
|
||||
method void moveDown() {
|
||||
var int i;
|
||||
if ((y2 < dBorder) & (y4 < dBorder) & (move) & fullSample(1)) {
|
||||
while (i < 16){
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y1, x2, y1);
|
||||
do Screen.drawRectangle(x3, y3, x4, y3);
|
||||
let y1 = y1 + 1;
|
||||
let y2 = y2 + 1;
|
||||
let y3 = y3 + 1;
|
||||
let y4 = y4 + 1;
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y2, x2, y2);
|
||||
do Screen.drawRectangle(x3, y4, x4, y4);
|
||||
let i = i + 1;
|
||||
do Sys.wait(10);
|
||||
}
|
||||
}
|
||||
else{
|
||||
let move = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** Moves the game piece 16 pixels to the left. */
|
||||
method void moveLeft() {
|
||||
var int i;
|
||||
if ((x1 + 15 > lBorder) & (move) & (x3 + 15 > lBorder)& fullSample(0)){
|
||||
while (i < 16){
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x2, y1, x2, y2);
|
||||
do Screen.drawRectangle(x4, y3, x4, y4);
|
||||
let x1 = x1 - 1;
|
||||
let x2 = x2 - 1;
|
||||
let x3 = x3 - 1;
|
||||
let x4 = x4 - 1;
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
let i = i + 1;
|
||||
do Sys.wait(10);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** Moves the game piece 16 pixels to the right. */
|
||||
method void moveRight() {
|
||||
var int i;
|
||||
if ((x4 < rBorder) & (move) & (x2 < rBorder) & fullSample(2)){
|
||||
while (i < 16){
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y1, x1, y2);
|
||||
do Screen.drawRectangle(x3, y3, x3, y4);
|
||||
let x1 = x1 + 1;
|
||||
let x2 = x2 + 1;
|
||||
let x3 = x3 + 1;
|
||||
let x4 = x4 + 1;
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
let i = i + 1;
|
||||
do Sys.wait(10);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** Deletes the piece and draws it at the new coodinates. */
|
||||
method void reDraw(int Ax1, int Ay1, int Ax2, int Ay2, int Ax3, int Ay3, int Ax4, int Ay4){
|
||||
var int absTmp;
|
||||
if((Ax1 < 175) | (Ax3 < 175) | (Ax2 > 336) | (Ax4 > 336)){
|
||||
return;
|
||||
}
|
||||
if((Ay2 > 255) | (Ay4 > 255) | (Ay1 < 0) | (Ay3 < 0)){
|
||||
return;
|
||||
}
|
||||
if((Ax1 > Ax2) | (Ax3 > Ax4) | (Ay1 > Ay2) | (Ay3 > Ay4)){
|
||||
return;
|
||||
}
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
do Screen.setColor(true);
|
||||
let x1 = Ax1;
|
||||
let y1 = Ay1;
|
||||
let x2 = Ax2;
|
||||
let y2 = Ay2;
|
||||
let x3 = Ax3;
|
||||
let y3 = Ay3;
|
||||
let x4 = Ax4;
|
||||
let y4 = Ay4;
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
return;
|
||||
}
|
||||
|
||||
/** Rotates the piece clockwise. */
|
||||
method void rotate(){
|
||||
var bool samp;
|
||||
let samp = true;
|
||||
if (direction = 0){ // starting position
|
||||
if (piece = 0){ // arrow
|
||||
let samp = Piece.sample(x4, y1) & samp; // checks if the place at which the new piece will be drawn are free
|
||||
let samp = Piece.sample(x4, y1 - 1) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2, y2, x4 - 15, y4 - 47, x4, y4); // redraws it at the new location
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1 + 16, y1) & samp;
|
||||
let samp = Piece.sample(x1 + 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x4, y1 - 16) & samp;
|
||||
if(samp){
|
||||
do reDraw(x1 + 16, y1 - 16, x4 - 16, y4, x4 - 15, y1 - 16, x4, y1 - 1);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1 - 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x1 - 16, y1) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 - 16, x2 - 16, y2 + 16, x3 + 32, y3, x4, y4);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x3 + 16, y3 - 32) & samp;
|
||||
let samp = Piece.sample(x4, y4 - 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 16, y1, x2, y2 + 16, x3 + 16, y3 - 32, x4, y4 - 16);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x3 + 32, y3 - 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 - 16, y2 + 16, x3 + 32, y3 - 32, x4 + 16, y4 - 16);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 + 32, y1 - 32) & samp;
|
||||
let samp = Piece.sample(x2 + 16, y2 - 16) & samp;
|
||||
let samp = Piece.sample(x4 - 16, y4 + 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 32, y1 - 32, x2 + 16, y2 - 16, x3, y3, x4 - 16, y4 + 16);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (direction = 1){
|
||||
if (piece = 0){
|
||||
let samp = Piece.sample(x1, y3) & samp;
|
||||
let samp = Piece.sample(x1 - 1, y3) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y3, x4, y3 + 15, x1, y1, x2, y2);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 + 16, x4, y4 + 16, x3, y3 + 32, x4, y2);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x2 + 16, y2 - 16) & samp;
|
||||
let samp = Piece.sample(x3 - 32, y3) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 + 16, x2 + 16, y2 - 16, x3 - 32, y3, x4 - 32, y4);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x1 - 16, y1) & samp;
|
||||
let samp = Piece.sample(x4, y4 + 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1, x2, y2 - 16, x3 - 16, y3 +32, x4, y4 + 16);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x3 - 32, y3 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 + 16, y2 - 16, x3 - 32, y3 + 32, x4 - 16, y4 + 16);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3 + 16, y3 - 16) & samp;
|
||||
let samp = Piece.sample(x4 + 32, y4 - 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 32, y1 + 16, x2 - 16, y2, x3, y3 - 16, x4 + 16, y4 - 32);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (direction = 2){
|
||||
if (piece = 0){
|
||||
let samp = Piece.sample(x1, y1+16) & samp;
|
||||
let samp = Piece.sample(x1, y1+32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x1 + 15, y1 + 47, x3, y3, x4, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1 + 16, x1 + 15, y1 + 31, x1 + 16, y1 - 16, x4 - 16, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x2 + 32, y2 + 16) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1 - 16, x2 - 32, y2 - 16, x3 + 16, y3 - 32, x4 + 16, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x2 - 16, y2 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 - 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 - 16, y2 + 16, x3, y3 - 32, x4 - 16, y4 - 16);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x1 - 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x2 - 32, y2) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 - 16, x2 - 32, y2, x3 + 16, y3 - 16, x4, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 + 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x3 - 16, y3 - 16) & samp;
|
||||
let samp = Piece.sample(x4 - 32, y4 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 16, y1 - 16, x2, y2, x3 - 16, y3 + 16, x4 - 32, y4 + 32);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (piece = 0){
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
let samp = Piece.sample(x4 + 32, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x3, y3, x4, y4, x1, y1 + 32, x1 + 47, y1 + 47);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1 - 16, x2, y2 -16, x1, y1, x4 + 16, y4);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1 + 32, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3 - 16, y3 + 32) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 32, y1 + 16, x2 + 32, y2 + 16, x3 - 16, y3 + 32, x4 + 16, y4);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x3, y3 + 32) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4 + 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 + 16, y2 - 16, x3, y3 + 32, x4 + 16, y4 + 16);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x3 - 16, y3 + 16) & samp;
|
||||
let samp = Piece.sample(x2 + 32, y2) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 16, y1 + 16, x2 + 32, y2, x3 - 16, y3 + 16, x4, y4);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 32) & samp;
|
||||
let samp = Piece.sample(x3 + 16, y3) & samp;
|
||||
let samp = Piece.sample(x4 + 32, y4 - 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 + 32, x2, y2 + 16, x3 + 16, y3, x4 + 32, y4 - 16);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+203
@@ -0,0 +1,203 @@
|
||||
class Tetris {
|
||||
static int points, seed, next_seed;
|
||||
|
||||
function void tetris(int z){
|
||||
var Piece p, nextPiece;
|
||||
var int i, x1, y1, x2, y2, x3, y3, x4, y4, key, j, randTmp, piece_number, moves;
|
||||
var Array left_g, right_g, box, stick, left_z, right_z,dick, all_piece, tmp;
|
||||
do Piece.init();
|
||||
do Tetris.border();
|
||||
let points = 0;
|
||||
let all_piece = Array.new(25);
|
||||
let all_piece[0] = Tetris.newPiece(16,0,31,15, 0,16,47,31, 0); // arrow
|
||||
let all_piece[1] = Tetris.newPiece(0,0,15,15, 0,16,47,31, 1); // right_L
|
||||
let all_piece[2] = Tetris.newPiece(32,16,47,31, 0,32,47,47, 2); // left_L
|
||||
let all_piece[3] = Tetris.newPiece(0,0,31,15, 16,16,47,31, 3); // left_z
|
||||
let all_piece[4] = Tetris.newPiece(16,0,47,15, 0,16,31,31, 4); // right_z
|
||||
let all_piece[5] = Tetris.newPiece(0,0,31,15, 32,0,63,15, 5); //stick
|
||||
let all_piece[6] = Tetris.newPiece(0,0,15,31, 16,0,31,31, 6); //box
|
||||
|
||||
|
||||
let seed = z * 3; // multiply by 3, because it gets in a loop on some even numbers
|
||||
let next_seed = Tetris.randomNumber();
|
||||
do Output.moveCursor(0,0);
|
||||
do Output.printString("Point: ");
|
||||
do Output.printInt(points);
|
||||
do Output.println();
|
||||
do Output.printString("Next Piece: ");
|
||||
while (true){ // The main game loop
|
||||
let j = next_seed;
|
||||
let next_seed = Tetris.randomNumber();
|
||||
let tmp = all_piece[j]; // initializes the coords of the game piece
|
||||
let x1 = tmp[0];
|
||||
let y1 = tmp[1];
|
||||
let x2 = tmp[2];
|
||||
let y2 = tmp[3];
|
||||
let x3 = tmp[4];
|
||||
let y3 = tmp[5];
|
||||
let x4 = tmp[6];
|
||||
let y4 = tmp[7];
|
||||
let piece_number = tmp[8];
|
||||
let p = Piece.new(x1 + 240, y1, x2 + 240, y2, x3 + 240, y3, x4 + 240, y4, piece_number);
|
||||
if (~(p.draw())){ // if a piece tries to spawn above a limit the game ends
|
||||
if (~(Tetris.finish())){
|
||||
return;
|
||||
}
|
||||
}
|
||||
let tmp = all_piece[next_seed];
|
||||
let x1 = tmp[0]; // initializes the coords of the next game piece that is being displayed
|
||||
let y1 = tmp[1];
|
||||
let x2 = tmp[2];
|
||||
let y2 = tmp[3];
|
||||
let x3 = tmp[4];
|
||||
let y3 = tmp[5];
|
||||
let x4 = tmp[6];
|
||||
let y4 = tmp[7];
|
||||
let piece_number = tmp[8];
|
||||
let nextPiece = Piece.new(x1 + 16, y1 + 32, x2+16, y2 + 32, x3+16, y3 + 32, x4 + 16, y4 + 32, piece_number);
|
||||
do nextPiece.draw();
|
||||
while (p.getMove()){
|
||||
let moves = 0;
|
||||
while (moves < 3){ // one can move its piece 3 times before it moves down automatically
|
||||
let key = Keyboard.keyPressed();
|
||||
if (key = 130){
|
||||
do p.moveLeft();
|
||||
do Sys.wait(80);
|
||||
}
|
||||
if (key = 132){
|
||||
do p.moveRight();
|
||||
do Sys.wait(80);
|
||||
}
|
||||
if (key = 131){
|
||||
do p.rotate();
|
||||
}
|
||||
if (key = 133){
|
||||
do p.moveDown();
|
||||
do p.moveDown();
|
||||
}
|
||||
let moves = moves +1;
|
||||
}
|
||||
do p.moveDown();
|
||||
let i = i + 1;
|
||||
do Sys.wait(80);
|
||||
}
|
||||
let i = 0;
|
||||
do p.dispose();
|
||||
do Tetris.completeRow();
|
||||
do Output.moveCursor(0,7);
|
||||
do Output.printInt(points);
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(16,32,80,96);
|
||||
do Screen.setColor(true);
|
||||
do nextPiece.dispose();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function void completeRow(){ // checks if a row has been completed
|
||||
var int adddress, row, colloum;
|
||||
var bool complete;
|
||||
let adddress = 16384 + 11;
|
||||
let row = 15;
|
||||
while (row > 0){ // for each row
|
||||
let complete = true;
|
||||
let colloum = 0;
|
||||
while ((colloum < 10) & (complete)){ // for each collum
|
||||
let complete = Memory.peek(adddress + colloum + (row * 512)) & complete;
|
||||
let colloum = colloum + 1;
|
||||
}
|
||||
if (complete){ // removes the row
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(176, row * 16, 335, ((row * 16)+ 15) );
|
||||
let points = points + 1;
|
||||
do Tetris.shift(row);
|
||||
}
|
||||
let row = row - 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function void shift(int rowShift){ // shifts all rows above the completed one
|
||||
var int j, val, adddress, tmp, k;
|
||||
let adddress = 16384 + 11;
|
||||
while (rowShift > 1){ // each row
|
||||
let j = 0;
|
||||
while (j < 10){ // collum in the game field
|
||||
let k = 0;
|
||||
while (k < 16){ // each line a in 16 x 16 box
|
||||
let tmp = adddress + j + (((rowShift - 1) * 512) + (k * 32));
|
||||
let val = Memory.peek(tmp);
|
||||
do Memory.poke(adddress + j + ((rowShift * 512) + (k * 32)), val);
|
||||
do Memory.poke(tmp,0);
|
||||
let k = k+ 1;
|
||||
}
|
||||
let j = j + 1;
|
||||
}
|
||||
let rowShift = rowShift - 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function void border(){ // draws a border
|
||||
do Screen.drawLine(175,0,175,255);
|
||||
do Screen.drawLine(336,0,336,255);
|
||||
return;
|
||||
}
|
||||
|
||||
function Array newPiece(int Ax1, int Ay1, int Ax2, int Ay2, int Ax3, int Ay3, int Ax4, int Ay4,int p){
|
||||
var Array gamepice;
|
||||
let gamepice = Array.new(9);
|
||||
let gamepice[0] = Ax1;
|
||||
let gamepice[1] = Ay1;
|
||||
let gamepice[2] = Ax2;
|
||||
let gamepice[3] = Ay2;
|
||||
let gamepice[4] = Ax3;
|
||||
let gamepice[5] = Ay3;
|
||||
let gamepice[6] = Ax4;
|
||||
let gamepice[7] = Ay4;
|
||||
let gamepice[8] = p;
|
||||
return gamepice;
|
||||
}
|
||||
|
||||
function int randomNumber(){ // radom number generator
|
||||
var int multiplier,additor,moduler,toBeModulated;
|
||||
let multiplier = 7;
|
||||
let additor = 13;
|
||||
let moduler = 1133;
|
||||
let toBeModulated = (multiplier * seed) + additor;
|
||||
let seed = Tetris.mod(toBeModulated,moduler);
|
||||
return Tetris.mod(seed,7);
|
||||
}
|
||||
|
||||
function bool finish(){ // after finishing the game the player has 2 options to start onether or to end the game
|
||||
var char c;
|
||||
do Screen.clearScreen();
|
||||
do Output.moveCursor(10,24);
|
||||
do Output.printString("Your score: ");
|
||||
do Output.printInt(points);
|
||||
do Sys.wait(10000);
|
||||
do Screen.clearScreen();
|
||||
do Output.moveCursor(10,0);
|
||||
do Output.printString("Would you like to play again, for yes click 'Y' and for no 'N':");
|
||||
let c = Keyboard.readChar();
|
||||
if (c = 89){
|
||||
do Screen.clearScreen();
|
||||
return false;
|
||||
}
|
||||
if (c = 78){
|
||||
do Screen.clearScreen();
|
||||
do Sys.halt();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function int mod(int tbm, int mo){ //simple moduler devision
|
||||
var int val, tmp2;
|
||||
if (tbm < mo){
|
||||
return tbm;
|
||||
}
|
||||
let tmp2 = (tbm / mo) * mo;
|
||||
let val = tbm - tmp2;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user