_Title "Trespass Board Game 1979 - Programmed by Donald L. Foster Jr. 2021"

Screen _NewImage(1300, 735, 256)

_PaletteColor 1, _RGB32(0, 127, 183) '    Background Color
_PaletteColor 2, _RGB32(40, 40, 40) '     Board Frame Color
_PaletteColor 3, _RGB32(170, 160, 0) '    Yellow Striker Piece
_PaletteColor 4, _RGB32(30, 30, 30) '     Black Blocker Piece
_PaletteColor 5, _RGB32(225, 20, 20) '    Red Attacker Piece

Dim Player As Integer
Dim Opponent As Integer
Dim Row As Integer
Dim Column As Integer
Dim NewRow As Integer
Dim NewColumn As Integer
Dim PieceColor As Integer
Dim Attackers As Integer
Dim Playable As Integer
Dim Piece As Integer

Dim Z As Integer
Dim Y As Integer
Dim X As Integer
Dim W As Integer
Dim V As Integer
Dim X1 As Integer
Dim X2 As Integer
Dim X3 As Integer

Dim StorageX(11) As Integer
Dim StorageY(11) As Integer

Dim BoardX(7, 11) As Integer
Dim BoardY(7, 11) As Integer
Dim BoardPiece(7, 11) As Integer
Dim Playable(7, 11) As Integer

Player = 1: Opponent = 2: Attackers = 11
PieceColor(1) = 5: PieceColor(2) = 4: PieceColor(3) = 3

For Z = 1 To 11: BoardPiece(7, Z) = 1: Next: BoardPiece(2, 4) = 2: BoardPiece(2, 5) = 2: BoardPiece(2, 6) = 3: BoardPiece(2, 7) = 2: BoardPiece(2, 8) = 2

fontpath$ = Environ$("SYSTEMROOT") + "\fonts\Segoeuib.ttf"

Cls , 1
' Draw Board
Line (10, 10)-(1016, 725), 2, BF
X = 58
For Z = 1 To 7
    W = 58
    For Y = 1 To 11
        X1 = W: X2 = X: X3 = BoardPiece(Z, Y): GoSub DrawPiece
        BoardX(Z, Y) = W: BoardY(Z, Y) = X
        W = W + 91
    Next
    If Z = 1 Or Z = 6 Then X = X + 127 Else X = X + 91
Next
Line (16, 106)-(1010, 136), 4, BF: Line (16, 597)-(1010, 627), 4, BF
Line (46, 106)-(980, 136), 3, BF: Line (46, 597)-(980, 627), 3, BF

Color 0, 1: font& = _LoadFont(fontpath$, 25): _Font font&: _PrintString (1050, 10), "T  R  E  S  P  A  S  S"

' Get Captured Piece Storage
X2 = 220: X3 = 1: For Z = 1 To 11 Step 2: StorageX(Z) = 1100: StorageY(Z) = X2: X2 = X2 + 81: Next
X2 = 260: X3 = 1: For Z = 2 To 10 Step 2: StorageX(Z) = 1216: StorageY(Z) = X2: X2 = X2 + 81: Next

StartGame:
' Display Player Indicator(s)
Line (1057, 42)-(1259, 128), 1, BF

If Player = 1 Then
    X1 = 1158: X2 = 85: X3 = 1: GoSub DrawPiece
Else
    X1 = 1100: X2 = 85: X3 = 2: GoSub DrawPiece
    X1 = 1216: X2 = 85: X3 = 3: GoSub DrawPiece
End If

font& = _LoadFont(fontpath$, 20): _Font font&: _PrintString (1115, 135), "Player: " + Str$(Player)

GetPlayables:
For Z = 1 To 7: For Y = 1 To 11: Playable(Z, Y) = 0: Next: Next
If Player = 1 Then
    For Z = 1 To 7
        For Y = 1 To 11
            If BoardPiece(Z, Y) = 1 Then If Z > 1 Then If BoardPiece(Z - 1, Y) = 0 Then Playable(Z, Y) = 1
        Next
    Next
End If

ChooseAPiece:
font& = _LoadFont(fontpath$, 18): _Font font&: _PrintString (1040, 700), "    Choose a Piece to Move    "

GetBoardPiece:
Do While _MouseInput
    For Z = 1 To 7
        For Y = 1 To 11
            If (Player = 1 And Playable(Z, Y) = 1) Or (Player = 2 And BoardPiece(Z, Y) > 1) Then
                If _MouseX > BoardX(Z, Y) - 32 And _MouseX < BoardX(Z, Y) + 32 And _MouseY > BoardY(Z, Y) - 32 And _MouseY < BoardY(Z, Y) + 32 And _MouseButton(1) = -1 Then
                    GoSub ButtonRelease: Row = Z: Column = Y: Line (BoardX(Z, Y) - 44, BoardY(Z, Y) - 44)-(BoardX(Z, Y) + 44, BoardY(Z, Y) + 44), 15, B: GoTo SetupMove
                End If
            End If
        Next
    Next
Loop
A$ = InKey$: If A$ <> "" Then If Asc(A$) = 27 And Full = 0 Then _FullScreen _SquarePixels , _Smooth: Full = 1 Else If Asc(A$) = 27 Then _FullScreen _Off: Full = 0
GoTo GetBoardPiece

SetupMove:
' Remove Playables
For Z = 1 To 7: For Y = 1 To 11: Playable(Z, Y) = 0: Next: Next

' Setup Playables for Move
Playable(Row, Column) = 1: Piece = BoardPiece(Row, Column)

Select Case Piece
    Case 1:
        Playable(Row - 1, Column) = 1
    Case 2:
        X = 1
        Dir1: If Row - X >= 2 Then If BoardPiece(Row - X, Column) = 0 Then Playable(Row - X, Column) = 1: X = X + 1: GoTo Dir1
        X = 1
        Dir2: If Row + X <= 6 Then If BoardPiece(Row + X, Column) = 0 Then Playable(Row + X, Column) = 1: X = X + 1: GoTo Dir2
        X = 1
        Dir3: If Column - X >= 1 Then If BoardPiece(Row, Column - X) = 0 Then Playable(Row, Column - X) = 1: X = X + 1: GoTo Dir3
        X = 1
        Dir4: If Column + X <= 11 Then If BoardPiece(Row, Column + X) = 0 Then Playable(Row, Column + X) = 1: X = X + 1: GoTo Dir4
        X = 1
        Dir5: If Row - X >= 2 And Column - X >= 1 Then If BoardPiece(Row - X, Column - X) = 0 Then Playable(Row - X, Column - X) = 1: X = X + 1: GoTo Dir5
        X = 1
        Dir6: If Row + X <= 6 And Column + X <= 11 Then If BoardPiece(Row + X, Column + X) = 0 Then Playable(Row + X, Column + X) = 1: X = X + 1: GoTo Dir6
        X = 1
        Dir7: If Row - X >= 2 And Column + X <= 11 Then If BoardPiece(Row - X, Column + X) = 0 Then Playable(Row - X, Column + X) = 1: X = X + 1: GoTo Dir7
        X = 1
        Dir8: If Row + X <= 6 And Column - X >= 1 Then If BoardPiece(Row + X, Column - X) = 0 Then Playable(Row + X, Column - X) = 1: X = X + 1: GoTo Dir8
    Case 3:
        If Row - 1 >= 2 Then If BoardPiece(Row - 1, Column) < 2 Then Playable(Row - 1, Column) = 1
        If Row + 1 <= 6 Then If BoardPiece(Row + 1, Column) < 2 Then Playable(Row + 1, Column) = 1
        If Column - 1 >= 1 Then If BoardPiece(Row, Column - 1) < 2 Then Playable(Row, Column - 1) = 1
        If Column + 1 <= 11 Then If BoardPiece(Row, Column + 1) < 2 Then Playable(Row, Column + 1) = 1
        If Row - 1 >= 2 And Column - 1 >= 1 Then If BoardPiece(Row - 1, Column - 1) < 2 Then Playable(Row - 1, Column - 1) = 1
        If Row + 1 <= 6 And Column + 1 <= 11 Then If BoardPiece(Row + 1, Column + 1) < 2 Then Playable(Row + 1, Column + 1) = 1
        If Row - 1 >= 2 And Column + 1 <= 11 Then If BoardPiece(Row - 1, Column + 1) < 2 Then Playable(Row - 1, Column + 1) = 1
        If Row + 1 <= 6 And Column - 1 >= 1 Then If BoardPiece(Row + 1, Column - 1) < 2 Then Playable(Row + 1, Column - 1) = 1
End Select

font& = _LoadFont(fontpath$, 18): _Font font&: _PrintString (1040, 700), "Choose Location to Move to"

GetLocation:
Do While _MouseInput
    For Z = 1 To 7
        For Y = 1 To 11
            If Playable(Z, Y) = 1 Then
                If _MouseX > BoardX(Z, Y) - 32 And _MouseX < BoardX(Z, Y) + 32 And _MouseY > BoardY(Z, Y) - 32 And _MouseY < BoardY(Z, Y) + 32 And _MouseButton(1) = -1 Then
                    GoSub ButtonRelease: NewRow = Z: NewColumn = Y:: GoTo Location
                End If
            End If
        Next
    Next
Loop
A$ = InKey$: If A$ <> "" Then If Asc(A$) = 27 And Full = 0 Then _FullScreen _SquarePixels , _Smooth: Full = 1 Else If Asc(A$) = 27 Then _FullScreen _Off: Full = 0
GoTo GetLocation

Location:
Line (BoardX(Row, Column) - 44, BoardY(Row, Column) - 44)-(BoardX(Row, Column) + 44, BoardY(Row, Column) + 44), 2, B

' Check for Change Piece
If NewRow = Row And NewColumn = Column GoTo GetPlayables

' Check for Attacker Captured by Striker
Piece = BoardPiece(Row, Column)
If Piece = 3 And BoardPiece(NewRow, NewColumn) = 1 Then
    Attackers = Attackers - 1
    X1 = StorageX(11 - Attackers): X2 = StorageY(11 - Attackers): X3 = 1: GoSub DrawPiece
End If

' Move Piece to New Location
BoardPiece(Row, Column) = 0: X1 = BoardX(Row, Column): X2 = BoardY(Row, Column): X3 = 0: GoSub DrawPiece
BoardPiece(NewRow, NewColumn) = Piece: X1 = BoardX(NewRow, NewColumn): X2 = BoardY(NewRow, NewColumn): X3 = Piece: GoSub DrawPiece

' Check for Winner
If Player = 1 Then
    X = 0
    For Z = 1 To 11
        If BoardPiece(1, Z) = 1 Then X = 1
    Next
Else
    V = 1: X = 0: If Attackers = 0 Then X = 1
    For Z = 1 To 7
        For Y = 1 To 11
            If BoardPiece(Z, Y) = 1 Then If Z > 1 Then If BoardPiece(Z - 1, Y) = 0 Then V = 0
        Next
    Next
    If V = 1 Then X = 1
End If
If X = 1 GoTo winner

Swap Player, Opponent: GoTo StartGame

ButtonRelease:
Do While _MouseInput
    If _MouseButton(1) = 0 Then Return
Loop
GoTo ButtonRelease

DrawPiece:
If X3 = 0 Then V = 1 Else V = 0
Line (X1 - 42, X2 - 42)-(X1 + 42, X2 + 42), V, BF
If X3 > 0 Then Line (X1 - 37, X2 - 37)-(X1 + 37, X2 + 37), PieceColor(X3), BF: PSet (X1 + 37, X2 - 37), 15: Draw "L74D74R1U73R73"
Return

winner:
font& = _LoadFont(fontpath$, 18): _Font font&: _PrintString (1040, 700), String$(50, 32)
Color 0, 1: font& = _LoadFont(fontpath$, 16): _Font font&
_PrintString (1070, 690), "Player " + Str$(Player) + " is the Winner!"
_PrintString (1050, 712), "Play Another Game?   Y or N"
GetYorN:
A$ = UCase$(InKey$): If A$ = "" GoTo GetYorN
If Asc(A$) = 27 And Full = 0 Then _FullScreen _SquarePixels , _Smooth: Full = 1 Else If Asc(A$) = 27 Then _FullScreen _Off: Full = 0
If A$ = "Y" Then Run
If A$ = "N" Then System
GoTo winner

