rem This program is (C)Copyright 1995, Matthew Estes rem This program is free software; you can redistribute it and/or modify rem it under the terms of the GNU General Public License as published by rem the Free Software Foundation; version 2 of the License rem This program is distributed in the hope that it will be useful, rem but WITHOUT ANY WARRANTY; without even the implied warranty of rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the rem GNU General Public License for more details. rem You should have received a copy of the GNU General Public License rem along with this program; if not, write to the Free Software rem Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA DECLARE SUB LinDel () DECLARE SUB MDown () DECLARE SUB Test () DECLARE SUB COrn () DECLARE SUB Move () DECLARE SUB NewBlocks () DECLARE SUB Done () DECLARE SUB MLeft () DECLARE SUB MRight () DECLARE SUB Update () SCREEN 0 COLOR 7, 0 CLS DIM SHARED board(1 TO 28, -4 TO 23) AS INTEGER DIM SHARED Delay AS LONG DIM SHARED ox AS INTEGER DIM SHARED oy AS INTEGER DIM SHARED orn AS INTEGER DIM SHARED obj AS INTEGER DIM SHARED onoff AS INTEGER DIM SHARED Colr AS INTEGER DIM SHARED NewBlock AS INTEGER DIM SHARED LD AS INTEGER DIM SHARED Lines AS INTEGER DIM SHARED gameover AS INTEGER Delay = 10000 CLS LOCATE 1, 1: PRINT "Tetris: Ported from the TI-85 Graphing Calculator" LOCATE 2, 1: PRINT "By: Matt Estes, Ported By: Matt Estes" DO LOOP UNTIL INKEY$ <> "" CLS FOR y = 2 TO 24 LOCATE y, 1: PRINT "]"; LOCATE y, 30: PRINT "["; NEXT y LOCATE 1, 1: PRINT STRING$(30, "-"); LOCATE 25, 1: PRINT STRING$(30, "-"); LOCATE 1, 32: PRINT "Tetris"; LOCATE 2, 32: PRINT "By: Matt Estes"; LOCATE 3, 32: PRINT "Lines:"; Lines DO IF gameover <> 0 THEN Done IF NewBlock = 0 THEN NewBlocks FOR x = 1 TO 4 a$ = INKEY$ IF a$ = CHR$(13) THEN Done IF a$ = CHR$(0) + CHR$(75) THEN MLeft IF a$ = CHR$(0) + CHR$(77) THEN MRight IF a$ = CHR$(0) + CHR$(80) THEN MDown IF a$ = CHR$(0) + CHR$(72) THEN COrn Update FOR y = 1 TO Delay NEXT y NEXT x MDown Test Update IF Lines > 10 THEN Delay = 8000 IF Lines > 20 THEN Delay = 6000 IF Lines > 30 THEN Delay = 4000 IF Lines > 50 THEN Delay = 2000 IF Lines > 70 THEN Delay = 1000 LOOP SUB COrn SELECT CASE obj CASE 1 EXIT SUB CASE 2 SELECT CASE orn CASE 1 IF ox >= 25 THEN EXIT SUB d = board(ox + 1, oy) + board(ox + 2, oy) + board(ox + 3, oy) CASE 2 d = board(ox, oy - 1) + board(ox, oy - 2) + board(ox, oy - 3) END SELECT CASE 3 SELECT CASE orn CASE 1 d = board(ox, oy - 1) + board(ox, oy - 2) CASE 2 IF ox >= 26 THEN EXIT SUB d = board(ox, oy) + board(ox + 2, oy - 1) END SELECT CASE 4 SELECT CASE orn CASE 1 d = board(ox, oy) + board(ox + 1, oy - 2) CASE 2 IF ox >= 26 THEN EXIT SUB d = board(ox + 1, oy) + board(ox + 2, oy) END SELECT CASE 5 SELECT CASE orn CASE 1 IF ox >= 26 THEN EXIT SUB d = board(ox + 1, oy - 1) + board(ox + 2, oy - 1) CASE 2 d = board(ox, oy - 2) + board(ox + 1, oy - 2) + board(ox + 1, oy) CASE 3 IF ox >= 26 THEN EXIT SUB d = board(ox, oy) + board(ox + 2, oy) + board(ox + 2, oy - 1) CASE 4 d = board(ox, oy - 1) + board(ox, oy - 2) END SELECT CASE 6 SELECT CASE orn CASE 1 IF ox >= 26 THEN EXIT SUB d = board(ox, oy - 1) + board(ox + 2, oy) CASE 2 d = board(ox, oy - 2) + board(ox + 1, oy - 2) CASE 3 IF ox >= 26 THEN EXIT SUB d = board(ox + 1, oy - 1) + board(ox + 2, oy - 1) + board(ox + 2, oy) CASE 4 d = board(ox, oy) + board(ox + 1, oy) + board(ox + 1, oy - 2) END SELECT CASE 7 SELECT CASE orn CASE 1 d = board(ox, oy - 1) + board(ox, oy - 2) CASE 2 IF ox >= 26 THEN EXIT SUB d = board(ox + 1, oy) + board(ox + 2, oy - 1) CASE 3 d = board(ox + 1, oy - 2) CASE 4 IF ox >= 26 THEN EXIT SUB d = board(ox, oy) + board(ox + 2, oy) END SELECT END SELECT IF d = 0 THEN bob = onoff onoff = 0 Move onoff = bob SELECT CASE obj CASE 2 orn = orn + 1 IF orn > 2 THEN orn = 1 CASE 3 orn = orn + 1 IF orn > 2 THEN orn = 1 CASE 4 orn = orn + 1 IF orn > 2 THEN orn = 1 CASE 5 orn = orn + 1 IF orn > 4 THEN orn = 1 CASE 6 orn = orn + 1 IF orn > 4 THEN orn = 1 CASE 7 orn = orn + 1 IF orn > 4 THEN orn = 1 END SELECT Move END IF END SUB SUB Done COLOR 7, 0 CLS PRINT "Game Over" PRINT "Lines:"; Lines END END SUB SUB LinDel IF LD = 1 THEN GOTO skip FOR a = LD TO 2 STEP -1 FOR b = 1 TO 28 STEP 1 board(b, a) = board(b, a - 1) NEXT b NEXT a skip: FOR a = 1 TO 28 STEP 1 board(a, 1) = 0 NEXT a END SUB SUB MDown IF oy >= 23 THEN NewBlock = 0 EXIT SUB END IF d = 0 SELECT CASE obj CASE 1 d = board(ox, oy + 1) + board(ox + 1, oy + 1) CASE 2 SELECT CASE orn CASE 1 d = board(ox, oy + 1) CASE 2 d = board(ox, oy + 1) + board(ox + 1, oy + 1) + board(ox + 2, oy + 1) + board(ox + 3, oy + 1) END SELECT CASE 3 SELECT CASE orn CASE 1 d = board(ox, oy + 1) + board(ox + 1, oy + 1) + board(ox + 2, oy) CASE 2 d = board(ox, oy) + board(ox + 1, oy + 1) END SELECT CASE 4 SELECT CASE orn CASE 1 d = board(ox, oy) + board(ox + 1, oy + 1) + board(ox + 2, oy + 1) CASE 2 d = board(ox, oy + 1) + board(ox + 1, oy) END SELECT CASE 5 SELECT CASE orn CASE 1 d = board(ox, oy + 1) + board(ox + 1, oy + 1) CASE 2 d = board(ox, oy + 1) + board(ox + 1, oy) + board(ox + 2, oy) CASE 3 d = board(ox, oy - 1) + board(ox + 1, oy + 1) CASE 4 d = board(ox, oy + 1) + board(ox + 1, oy + 1) + board(ox + 2, oy + 1) END SELECT CASE 6 SELECT CASE orn CASE 1 d = board(ox, oy + 1) + board(ox + 1, oy + 1) CASE 2 d = board(ox, oy + 1) + board(ox + 1, oy + 1) + board(ox + 2, oy + 1) CASE 3 d = board(ox, oy + 1) + board(ox + 1, oy - 1) CASE 4 d = board(ox, oy) + board(ox + 1, oy) + board(ox + 2, oy + 1) END SELECT CASE 7 SELECT CASE orn CASE 1 d = board(ox, oy + 1) + board(ox + 1, oy + 1) + board(ox + 2, oy + 1) CASE 2 d = board(ox, oy + 1) + board(ox + 1, oy) CASE 3 d = board(ox, oy) + board(ox + 1, oy + 1) + board(ox + 2, oy) CASE 4 d = board(ox, oy) + board(ox + 1, oy + 1) + board(ox, oy - 2) END SELECT END SELECT IF d = 0 THEN bob = onoff onoff = 0 Move onoff = bob oy = oy + 1 Move END IF IF d <> 0 THEN NewBlock = 0 END SUB SUB MLeft IF ox <= 1 THEN EXIT SUB END IF d = 0 SELECT CASE obj CASE 1 d = board(ox - 1, oy) + board(ox - 1, oy - 1) CASE 2 SELECT CASE orn CASE 1 d = board(ox - 1, oy) + board(ox - 1, oy - 1) + board(ox - 1, oy - 2) + board(ox - 1, oy - 3) CASE 2 d = board(ox - 1, oy) END SELECT CASE 3 SELECT CASE orn CASE 1 d = board(ox - 1, oy) + board(ox, oy - 1) CASE 2 d = board(ox, oy) + board(ox - 1, oy - 1) + board(ox - 1, oy - 2) END SELECT CASE 4 SELECT CASE orn CASE 1 d = board(ox, oy) + board(ox - 1, oy - 1) CASE 2 d = board(ox - 1, oy) + board(ox - 1, oy - 1) + board(ox, oy - 2) END SELECT CASE 5 SELECT CASE orn CASE 1 d = board(ox - 1, oy) + board(ox - 1, oy - 1) + board(ox - 1, oy - 2) CASE 2 d = board(ox - 1, oy) + board(ox - 1, oy - 1) CASE 3 d = board(ox, oy) + board(ox, oy - 1) + board(ox - 1, oy - 2) CASE 4 d = board(ox - 1, oy) + board(ox + 1, oy - 1) END SELECT CASE 6 SELECT CASE orn CASE 1 d = board(ox - 1, oy) + board(ox, oy - 1) + board(ox, oy - 2) CASE 2 d = board(ox - 1, oy) + board(ox - 1, oy - 1) CASE 3 d = board(ox - 1, oy) + board(ox - 1, oy - 1) + board(ox - 1, oy - 2) CASE 4 d = board(ox + 1, oy) + board(ox - 1, oy - 1) END SELECT CASE 7 SELECT CASE orn CASE 1 d = board(ox - 1, oy) + board(ox, oy - 1) CASE 2 d = board(ox - 1, oy) + board(ox - 1, oy - 1) + board(ox - 1, oy - 2) CASE 3 d = board(ox, oy) + board(ox - 1, oy - 1) CASE 4 d = board(ox, oy) + board(ox - 1, oy - 1) + board(ox, oy - 2) END SELECT END SELECT IF d = 0 THEN bob = onoff onoff = 0 Move onoff = bob ox = ox - 1 Move END IF END SUB SUB Move SELECT CASE obj CASE 1 board(ox, oy) = onoff board(ox + 1, oy) = onoff board(ox, oy - 1) = onoff board(ox + 1, oy - 1) = onoff CASE 2 SELECT CASE orn CASE 1 board(ox, oy) = onoff board(ox, oy - 1) = onoff board(ox, oy - 2) = onoff board(ox, oy - 3) = onoff CASE 2 board(ox, oy) = onoff board(ox + 1, oy) = onoff board(ox + 2, oy) = onoff board(ox + 3, oy) = onoff END SELECT CASE 3 SELECT CASE orn CASE 1 board(ox, oy) = onoff board(ox + 1, oy) = onoff board(ox + 1, oy - 1) = onoff board(ox + 2, oy - 1) = onoff CASE 2 board(ox + 1, oy) = onoff board(ox, oy - 1) = onoff board(ox, oy - 2) = onoff board(ox + 1, oy - 1) = onoff END SELECT CASE 4 SELECT CASE orn CASE 1 board(ox, oy - 1) = onoff board(ox + 1, oy) = onoff board(ox + 2, oy) = onoff board(ox + 1, oy - 1) = onoff CASE 2 board(ox, oy) = onoff board(ox, oy - 1) = onoff board(ox + 1, oy - 1) = onoff board(ox + 1, oy - 2) = onoff END SELECT CASE 5 SELECT CASE orn CASE 1 board(ox, oy) = onoff board(ox + 1, oy) = onoff board(ox, oy - 1) = onoff board(ox, oy - 2) = onoff CASE 2 board(ox, oy) = onoff board(ox, oy - 1) = onoff board(ox + 1, oy - 1) = onoff board(ox + 2, oy - 1) = onoff CASE 3 board(ox + 1, oy) = onoff board(ox, oy - 2) = onoff board(ox + 1, oy - 1) = onoff board(ox + 1, oy - 2) = onoff CASE 4 board(ox, oy) = onoff board(ox + 1, oy) = onoff board(ox + 2, oy) = onoff board(ox + 2, oy - 1) = onoff END SELECT CASE 6 SELECT CASE orn CASE 1 board(ox, oy) = onoff board(ox + 1, oy) = onoff board(ox + 1, oy - 1) = onoff board(ox + 1, oy - 2) = onoff CASE 2 board(ox, oy) = onoff board(ox + 1, oy) = onoff board(ox + 2, oy) = onoff board(ox, oy - 1) = onoff CASE 3 board(ox, oy) = onoff board(ox, oy - 1) = onoff board(ox, oy - 2) = onoff board(ox + 1, oy - 2) = onoff CASE 4 board(ox, oy - 1) = onoff board(ox + 2, oy) = onoff board(ox + 2, oy - 1) = onoff board(ox + 1, oy - 1) = onoff END SELECT CASE 7 SELECT CASE orn CASE 1 board(ox, oy) = onoff board(ox + 1, oy) = onoff board(ox + 2, oy) = onoff board(ox + 1, oy - 1) = onoff CASE 2 board(ox, oy) = onoff board(ox, oy - 1) = onoff board(ox, oy - 2) = onoff board(ox + 1, oy - 1) = onoff CASE 3 board(ox, oy - 1) = onoff board(ox + 1, oy) = onoff board(ox + 1, oy - 1) = onoff board(ox + 2, oy - 1) = onoff CASE 4 board(ox, oy - 1) = onoff board(ox + 1, oy) = onoff board(ox + 1, oy - 1) = onoff board(ox + 1, oy - 2) = onoff END SELECT END SELECT END SUB SUB MRight d = 0 SELECT CASE obj CASE 1 IF ox >= 27 THEN EXIT SUB d = board(ox + 2, oy) + board(ox + 2, oy - 1) CASE 2 SELECT CASE orn CASE 1 IF ox >= 28 THEN EXIT SUB d = board(ox + 1, oy) + board(ox + 1, oy - 1) + board(ox + 1, oy - 2) + board(ox + 1, oy - 3) CASE 2 IF ox >= 25 THEN EXIT SUB d = board(ox + 4, oy) END SELECT CASE 3 SELECT CASE orn CASE 1 IF ox >= 26 THEN EXIT SUB d = board(ox + 2, oy) + board(ox + 3, oy - 1) CASE 2 IF ox >= 27 THEN EXIT SUB d = board(ox + 2, oy) + board(ox + 2, oy - 1) + board(ox + 1, oy - 2) END SELECT CASE 4 SELECT CASE orn CASE 1 IF ox >= 26 THEN EXIT SUB d = board(ox + 3, oy) + board(ox + 2, oy - 1) CASE 2 IF ox >= 27 THEN EXIT SUB d = board(ox + 1, oy) + board(ox + 2, oy - 1) + board(ox + 2, oy - 2) END SELECT CASE 5 SELECT CASE orn CASE 1 IF ox >= 27 THEN EXIT SUB d = board(ox + 2, oy) + board(ox + 1, oy - 1) + board(ox + 1, oy - 2) CASE 2 IF ox >= 26 THEN EXIT SUB d = board(ox + 1, oy) + board(ox + 3, oy - 1) CASE 3 IF ox >= 27 THEN EXIT SUB d = board(ox + 2, oy) + board(ox + 2, oy - 1) + board(ox + 2, oy - 2) CASE 4 IF ox >= 26 THEN EXIT SUB d = board(ox + 3, oy) + board(ox + 3, oy - 1) END SELECT CASE 6 SELECT CASE orn CASE 1 IF ox >= 27 THEN EXIT SUB d = board(ox + 2, oy) + board(ox + 2, oy - 1) + board(ox + 2, oy - 2) CASE 2 IF ox >= 26 THEN EXIT SUB d = board(ox + 3, oy) + board(ox + 1, oy - 1) CASE 3 IF ox >= 27 THEN EXIT SUB d = board(ox + 1, oy) + board(ox + 1, oy - 1) + board(ox + 2, oy - 2) CASE 4 IF ox >= 26 THEN EXIT SUB d = board(ox + 3, oy) + board(ox + 3, oy - 1) END SELECT CASE 7 SELECT CASE orn CASE 1 IF ox >= 26 THEN EXIT SUB d = board(ox + 3, oy) + board(ox + 2, oy - 1) CASE 2 IF ox >= 27 THEN EXIT SUB d = board(ox + 1, oy) + board(ox + 2, oy - 1) + board(ox + 1, oy - 2) CASE 3 IF ox >= 26 THEN EXIT SUB d = board(ox + 2, oy) + board(ox + 3, oy - 1) CASE 4 IF ox >= 27 THEN EXIT SUB d = board(ox + 2, oy) + board(ox + 2, oy - 1) + board(ox + 2, oy - 2) END SELECT END SELECT IF d = 0 THEN bob = onoff onoff = 0 Move onoff = bob ox = ox + 1 Move END IF END SUB SUB NewBlocks RANDOMIZE (TIMER) obj = INT(7 * RND + 1) orn = 1 onoff = INT(7 * RND + 9) NewBlock = 1 SELECT CASE obj CASE 1 ox = 14 oy = 2 d = board(ox, oy) + board(ox + 1, oy) + board(ox, oy - 1) + board(ox + 1, oy - 1) CASE 2 ox = 14 oy = 4 d = board(ox, oy) + board(ox, oy - 1) + board(ox, oy - 2) + board(ox, oy - 3) CASE 3 ox = 13 oy = 2 d = board(ox, oy) + board(ox + 1, oy) + board(ox + 1, oy - 1) + board(ox + 2, oy - 1) CASE 4 ox = 13 oy = 2 d = board(ox, oy - 1) + board(ox + 1, oy - 1) + board(ox + 1, oy) + board(ox + 2, oy) CASE 5 ox = 14 oy = 3 d = board(ox, oy) + board(ox, oy - 1) + board(ox, oy - 2) + board(ox + 1, oy) CASE 6 ox = 14 oy = 3 d = board(ox, oy) + board(ox + 1, oy) + board(ox + 1, oy - 1) + board(ox + 1, oy - 2) CASE 7 ox = 13 oy = 2 d = board(ox, oy) + board(ox + 1, oy) + board(ox + 1, oy - 1) + board(ox + 2, oy) END SELECT IF d <> 0 THEN gameover = 1 Move END SUB SUB Test FOR LD = 1 TO 23 d = 0 FOR x = 1 TO 28 IF board(x, LD) <> 0 THEN d = d + 1 NEXT x IF d = 28 THEN Lines = Lines + 1 LinDel END IF NEXT LD END SUB SUB Update IF onoff <> 0 THEN FOR x = 1 TO (10 * Delay) NEXT x END IF COLOR 7, 0: LOCATE 3, 32: PRINT "Lines:"; Lines COLOR 7, 0: LOCATE 4, 32: PRINT "ox:"; ox COLOR 7, 0: LOCATE 5, 32: PRINT "oy:"; oy COLOR 7, 0: LOCATE 6, 32: PRINT "orn:"; orn COLOR 7, 0: LOCATE 7, 32: PRINT "obj:"; obj FOR x = 1 TO 28 FOR y = 1 TO 23 IF board(x, y) = 0 THEN LOCATE y + 1, x + 1: PRINT " "; IF board(x, y) <> 0 THEN LOCATE y + 1, x + 1: COLOR board(x, y): PRINT "#"; NEXT y NEXT x END SUB