DECLARE SUB printto (row!, column!, a$)
DECLARE SUB getapic (a$)
DECLARE SUB pause ()


CLS
SCREEN 13

getapic "startup"
CALL pause
CLS
PALETTE

RANDOMIZE TIMER



PRINT "Calculating Computer Speed..."

a = TIMER
b = 16


FOR z = 1 TO 10000
COLOR b + z * .01
PSET (INT(z / 31), 10)
PSET (INT(z / 31), 11)
PSET (INT(z / 31), 12)
PSET (INT(z / 31), 13)
PSET (INT(z / 31), 14)
NEXT z
b = TIMER
COLOR 15
CALL pause

startup:

CLS

FOR z = 1 TO 5
        printto 1, z, ">Please select a speed"
SOUND 0, 1
NEXT z

printto 2, 1, "1. Zzzzzz"
SOUND 0, 1
printto 3, 1, "2. Slow"
SOUND 0, 1
printto 4, 1, "3. Normal"
SOUND 0, 1
printto 5, 1, "4. Fast"
SOUND 0, 1
printto 6, 1, "5. Crash"
SOUND 0, 1
INPUT "Speed Level: ", c

SELECT CASE c
        CASE IS = 1
                d = 1
        CASE IS = 2
                d = 3
        CASE IS = 3
                d = 5
        CASE IS = 4
                d = 10
        CASE IS = 5
                d = 18
        CASE ELSE
                PRINT "Please enter a valid number"
                CALL pause
                GOTO startup
END SELECT

speed = (a / b) / d


PRINT "Press any key to begin..."


CALL pause

main:

CLS

LINE (1, 1)-(1, 200), 15
LINE (1, 1)-(320, 1), 15
LINE (319, 1)-(319, 199), 15
LINE (1, 199)-(319, 199), 15

again:
a = INT(RND * 15) + 1
IF a = 1 OR a = 4 OR a = 15 THEN GOTO again

FOR z = 2 TO 198
        LINE (2, z)-(318, z), a
NEXT z

dir.one$ = "right"
dir.two$ = "left"
new.dir.one$ = "right"
new.dir.two$ = "left"

x1 = 2
y1 = 100
x2 = 318
y2 = 100



DO
a$ = INKEY$
SOUND 0, speed

SELECT CASE dir.one$
        CASE IS = "right"
                x1 = x1 + 1
        CASE IS = "left"
                x1 = x1 - 1
        CASE IS = "down"
                y1 = y1 + 1
        CASE IS = "up"
                y1 = y1 - 1
END SELECT


SELECT CASE dir.two$
        CASE IS = "right"
                x2 = x2 + 1
        CASE IS = "left"
                x2 = x2 - 1
        CASE IS = "down"
                y2 = y2 + 1
        CASE IS = "up"
                y2 = y2 - 1
END SELECT




IF y1 = y2 AND x1 = x2 THEN GOTO three.loss

IF POINT(x1, y1) = 4 OR POINT(x1, y1) = 15 OR POINT(x1, y1) = 1 THEN GOTO one.loss
PSET (x1, y1), 1

IF POINT(x2, y2) = 1 OR POINT(x2, y2) = 15 OR POINT(x2, y2) = 4 THEN GOTO two.loss
PSET (x2, y2), 4

IF y1 = y2 AND x1 = x2 THEN GOTO three.loss

SOUND 0, speed

SELECT CASE a$
        CASE IS = "a"
                IF dir.one$ = "up" THEN new.dir.one$ = "left"
                IF dir.one$ = "down" THEN new.dir.one$ = "right"
                IF dir.one$ = "right" THEN new.dir.one$ = "up"
                IF dir.one$ = "left" THEN new.dir.one$ = "down"
        CASE IS = "z"
                IF dir.one$ = "up" THEN new.dir.one$ = "right"
                IF dir.one$ = "down" THEN new.dir.one$ = "left"
                IF dir.one$ = "right" THEN new.dir.one$ = "down"
                IF dir.one$ = "left" THEN new.dir.one$ = "up"
        CASE IS = "m"
                IF dir.two$ = "up" THEN new.dir.two$ = "left"
                IF dir.two$ = "down" THEN new.dir.two$ = "right"
                IF dir.two$ = "right" THEN new.dir.two$ = "up"
                IF dir.two$ = "left" THEN new.dir.two$ = "down"
        CASE IS = "k"
                IF dir.two$ = "up" THEN new.dir.two$ = "right"
                IF dir.two$ = "down" THEN new.dir.two$ = "left"
                IF dir.two$ = "right" THEN new.dir.two$ = "down"
                IF dir.two$ = "left" THEN new.dir.two$ = "up"
END SELECT

dir.one$ = new.dir.one$
dir.two$ = new.dir.two$

LOOP

one.loss:
PRINT "Player 2 Wins!"
CALL pause
p2.wins = p2.wins + 1
GOTO next.round



two.loss:
PRINT "Player 1 Wins!"
CALL pause
p1.wins = p1.wins + 1
GOTO next.round


three.loss:
PRINT "Both Crashed!"
CALL pause
p1.wins = p1.wins + 1
p2.wins = p2.wins + 1
GOTO next.round



next.round:
CLS
PRINT "Current Score"
PRINT "Player One Wins: "; p1.wins
PRINT "Player Two Wins: "; p2.wins
PRINT "Rounds Played: "; (p1.wins + p2.wins)
PRINT
PRINT "Press G to continue"
PRINT "Press Q to quit"


DO
a$ = INKEY$
IF a$ = "q" THEN GOTO ende
IF a$ = "g" THEN GOTO main
LOOP




ende:
CLS
COLOR 15
PRINT "Thanks for playing Tron!"
CALL pause
CLS
END

SUB getapic (a$)
DEFINT A-Z
DIM Prefix(4095), Suffix(4095), OutStack(4095), shiftout%(8)
DIM Ybase AS LONG, powersof2(11) AS LONG, WorkCode AS LONG

FOR a% = 0 TO 7: shiftout%(8 - a%) = 2 ^ a%: NEXT a%
FOR a% = 0 TO 11: powersof2(a%) = 2 ^ a%: NEXT a%

IF INSTR(a$, ".") = 0 THEN a$ = a$ + ".efx"
OPEN a$ FOR BINARY AS #1
a$ = "      ": GET #1, , a$

GET #1, , TotalX: GET #1, , TotalY: GOSUB GetByte
NumColors = 2 ^ ((a% AND 7) + 1): NoPalette = (a% AND 128) = 0
GOSUB GetByte: Background = a%
GOSUB GetByte: IF a% <> 0 THEN PRINT "Bad screen descriptor.": END
IF NoPalette = 0 THEN P$ = SPACE$(NumColors * 3): GET #1, , P$
DO
    GOSUB GetByte
    IF a% = 44 THEN
        EXIT DO
    ELSEIF a% <> 33 THEN
        PRINT "Unknown extension type.": END
    END IF
    GOSUB GetByte
    DO: GOSUB GetByte: a$ = SPACE$(a%): GET #1, , a$: LOOP UNTIL a% = 0
LOOP
GET #1, , XStart: GET #1, , YStart: GET #1, , XLength: GET #1, , YLength
XEnd = XStart + XLength: YEnd = YStart + YLength: GOSUB GetByte
IF a% AND 128 THEN PRINT "Can't handle local colormaps.": END
Interlaced = a% AND 64: PassNumber = 0: PassStep = 8
GOSUB GetByte
ClearCode = 2 ^ a%
EOSCode = ClearCode + 1
FirstCode = ClearCode + 2: NextCode = FirstCode
StartCodeSize = a% + 1: CodeSize = StartCodeSize
StartMaxCode = 2 ^ (a% + 1) - 1: MaxCode = StartMaxCode

BitsIn = 0: BlockSize = 0: BlockPointer = 1
x% = XStart: y% = YStart: Ybase = y% * 320&

SCREEN 13: DEF SEG = &HA000
IF NoPalette = 0 THEN
    OUT &H3C7, 0: OUT &H3C8, 0
    FOR a% = 1 TO NumColors * 3: OUT &H3C9, ASC(MID$(P$, a%, 1)) \ 4: NEXT a%
END IF
LINE (0, 0)-(319, 199), Background, BF
DO
    GOSUB GetCode
    IF Code <> EOSCode THEN
        IF Code = ClearCode THEN
            NextCode = FirstCode
            CodeSize = StartCodeSize
            MaxCode = StartMaxCode
            GOSUB GetCode
            CurCode = Code: LastCode = Code: LastPixel = Code
            IF x% < 320 THEN POKE x% + Ybase, LastPixel
            x% = x% + 1: IF x% = XEnd THEN GOSUB NextScanLine
        ELSE
            CurCode = Code: StackPointer = 0
            IF Code > NextCode THEN EXIT DO
            IF Code = NextCode THEN
                CurCode = LastCode
                OutStack(StackPointer) = LastPixel
                StackPointer = StackPointer + 1
            END IF

            DO WHILE CurCode >= FirstCode
                OutStack(StackPointer) = Suffix(CurCode)
                StackPointer = StackPointer + 1
                CurCode = Prefix(CurCode)
            LOOP

            LastPixel = CurCode
            IF x% < 320 THEN POKE x% + Ybase, LastPixel
            x% = x% + 1: IF x% = XEnd THEN GOSUB NextScanLine

            FOR a% = StackPointer - 1 TO 0 STEP -1
                IF x% < 320 THEN POKE x% + Ybase, OutStack(a%)
                x% = x% + 1: IF x% = XEnd THEN GOSUB NextScanLine
            NEXT a%

            IF NextCode < 4096 THEN
                Prefix(NextCode) = LastCode
                Suffix(NextCode) = LastPixel
                NextCode = NextCode + 1
                IF NextCode > MaxCode AND CodeSize < 12 THEN
                    CodeSize = CodeSize + 1
                    MaxCode = MaxCode * 2 + 1
                END IF
            END IF
            LastCode = Code
        END IF
    END IF
LOOP UNTIL DoneFlag OR Code = EOSCode
'BEEP
'A$ = INPUT$(1)
CLOSE #1
EXIT SUB

GetByte: a$ = " ": GET #1, , a$: a% = ASC(a$): RETURN

NextScanLine:
    IF Interlaced THEN
        y% = y% + PassStep
        IF y% >= YEnd THEN
            PassNumber = PassNumber + 1
            SELECT CASE PassNumber
            CASE 1: y% = 4: PassStep = 8
            CASE 2: y% = 2: PassStep = 4
            CASE 3: y% = 1: PassStep = 2
            END SELECT
        END IF
    ELSE
        y% = y% + 1
    END IF
    x% = XStart: Ybase = y% * 320&: DoneFlag = y% > 199
RETURN
GetCode:
    IF BitsIn = 0 THEN GOSUB ReadBufferedByte: LastChar = a%: BitsIn = 8
    WorkCode = LastChar \ shiftout%(BitsIn)
    DO WHILE CodeSize > BitsIn
        GOSUB ReadBufferedByte: LastChar = a%
        WorkCode = WorkCode OR LastChar * powersof2(BitsIn)
        BitsIn = BitsIn + 8
    LOOP
    BitsIn = BitsIn - CodeSize
    Code = WorkCode AND MaxCode
RETURN
ReadBufferedByte:
    IF BlockPointer > BlockSize THEN
        GOSUB GetByte: BlockSize = a%
        a$ = SPACE$(BlockSize): GET #1, , a$
        BlockPointer = 1
    END IF
    a% = ASC(MID$(a$, BlockPointer, 1)): BlockPointer = BlockPointer + 1
RETURN

END SUB

DEFSNG A-Z
SUB pause
DO UNTIL INKEY$ <> ""
LOOP
END SUB

SUB printto (row, column, a$)
LOCATE row, column
PRINT a$
END SUB

