Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hex Board Game
#1
[Image: index.php?action=dlattach;topic=4488.0;attach=17214]

Hello All,

    Hex is a 2 player abstract strategy board game. The goal is to be the first player to make a continuous connection of pieces that connect the ends of the board. Player 1, the blue pieces, is trying to connect the left side of the board while player 2, the red pieces, is trying to connect the top of the board to the bottom. you can use ESC to alternate between window and full screen.

Hope you enjoy playing

Donald

Code: (Select All)
_Title "Connection Board Game - Programmed by Donald L. Foster Jr. 2020-2021"

Screen _NewImage(1095, 735, 256)

_PaletteColor 1, _RGB32(0, 142, 223) '  Medium Blue
_PaletteColor 2, _RGB32(235, 30, 54) '  Medium Red
_PaletteColor 3, _RGB32(215, 215, 215) ' Grey
_PaletteColor 4, _RGB32(0, 167, 248) '  Light Blue
_PaletteColor 5, _RGB32(0, 117, 198) '  Dark Blue
_PaletteColor 6, _RGB32(255, 55, 74) '  Light Red
_PaletteColor 7, _RGB32(205, 5, 24) '    Dark Red
_PaletteColor 9, _RGB32(1, 1, 1)

Dim As Integer Player, Opponent, Row, Column, Progress, Counter
Dim As Integer Z, Y, X, W, V, X1, X2, X3
Dim As Integer BoardX(13, 13), BoardY(13, 13), BoardPlayer(13, 13), Checked(13, 13)
Dim As Integer PlayerColor(3), StepRow(30), StepColumn(30)

Player = 1: Opponent = 2: Counter = 1: StartingX = 456: StartingY = 67
PlayerColor(1) = 1: PlayerColor(2) = 2

BoardHex$ = "C0TA0BL33D19TA60D38TA120D38TA180D38TA240D38TA300D38TA0D19"

Cls , 15

' Draw Game Board
PSet (43, 74), 0: Draw "TA0D37TA60D36TA0D37TA60D36TA0D37TA60D35TA0D37TA60D36TA0D37TA60D36TA0D37TA60D36TA0D37TA60D36TA0D37TA60D35TA0D37TA60D36TA0D37TA60D36TA0D38"
Draw "TA60D37TA120D37TA60D36TA120D36TA60D36TA120D36TA60D37TA120D37TA60D36TA120D36TA60D36TA120D36TA60D37TA120D37TA60D36TA120D36TA60D37TA120D37TA60D36TA120D36TA60D36TA120D37"
Draw "TA0U37TA240D36TA0U37TA240D35TA0U36TA240D36TA0U37TA240D36TA0U37TA240D36TA0U37TA240D36TA0U37TA240D37TA0U37TA240D36TA0U37TA240D36TA0U37TA240D36TA0U39"
Draw "TA240D36TA300D36TA240D36TA300D36TA240D36TA300D36TA240D36TA300D37TA240D37TA300D36TA240D36TA300D36TA240D37TA300D37TA240D36TA300D36TA240D36TA300D37TA240D37TA300D36TA240D36TA300D37"
Draw "TA240D20TA330D30TA29.5D699TA150ND30TA0R699TA330U30TA240ND28TA330U28TA29.5U699TA150NU30TA0L699TA330D30TA0BD10P1,0BE20P2,0BR695P1,0BD630P2,0"
Paint (200, 100), 9, 0
X = 92: Increase = 0: Indent = 0
For Z = 1 To 11
    Starting = 75
    For Y = 1 To 11
        PSet (Starting + Indent + Increase, X), 15: Draw "C0TA0BL31BU18D36TA60D36TA120D36TA180D36TA240D36TA300D36BR10P3,0"
        '  CIRCLE (Starting + Indent + Increase, X), 28, 0
        BoardX(Z, Y) = Starting + Indent + Increase: BoardY(Z, Y) = X
        If Y = 11 Then Indent = Indent + 31: Increase = 0 Else Increase = Increase + 63
    Next
    X = X + 55
Next

StartGame:
' Draw Player Indicator
Color 0, 15: Locate 3, 97: Print "H  E  X    B  O  A  R  D    G  A  M  E";
PSet (943, 100), 15: Draw BoardHex$: Paint (943, 100), PlayerColor(Player), 0
X1 = 943: X2 = 100: X3 = Player: GoSub DrawPiece
Locate 10, 115: Print "Player"; Player;

Locate 44, 5: Print "Choose Location to Place Your Piece";

GetLocation:
Do While _MouseInput
    For Z = 1 To 11
        For Y = 1 To 11
            If _MouseX > BoardX(Z, Y) - 30 And _MouseX < BoardX(Z, Y) + 30 And _MouseY > BoardY(Z, Y) - 30 And _MouseY < BoardY(Z, Y) + 30 Then Selected = 1 Else Selected = 0
            If _MouseButton(1) = -1 And BoardPlayer(Z, Y) = 0 And Selected = 1 Then
                GoSub ReleaseButton: BoardPlayer(Z, Y) = Player: X1 = BoardX(Z, Y): X2 = BoardY(Z, Y): X3 = Player: GoSub DrawPiece: Row = Z: Column = Y: GoTo CheckForWinner
            End If
        Next
    Next
Loop
A$ = InKey$: If A$ <> "" Then If Asc(A$) = 27 And FullScreen = 0 Then FullScreen = -1: _FullScreen _SquarePixels , _Smooth Else If Asc(A$) = 27 Then FullScreen = 0: _FullScreen _Off
GoTo GetLocation

CheckForWinner:
For V = 1 To 11
    For Z = 1 To 11: For Y = 1 To 11: Checked(Z, Y) = 0: Next: Next

    If Player = 1 Then Row = V: Column = 1 Else Row = 1: Column = V

    If BoardPlayer(Row, Column) = Player Then
        Progress = 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1

        CheckWinner: If (Player = 1 And Column = 11) Or (Player = 2 And Row = 11) GoTo Winner

        ' Check Right
        If Column + 1 <= 11 Then
            If BoardPlayer(Row, Column + 1) = Player And Checked(Row, Column + 1) = 0 Then
                Progress = Progress + 1: Column = Column + 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
            End If
        End If

        ' Check Down
        If Row + 1 <= 11 Then
            If BoardPlayer(Row + 1, Column) = Player And Checked(Row + 1, Column) = 0 Then
                Progress = Progress + 1: Row = Row + 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
            End If
        End If

        ' Check Left
        If Column - 1 >= 1 Then
            If BoardPlayer(Row, Column - 1) = Player And Checked(Row, Column - 1) = 0 Then
                Progress = Progress + 1: Column = Column - 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
            End If
        End If

        ' Check Up
        If Row - 1 >= 1 Then
            If BoardPlayer(Row - 1, Column) = Player And Checked(Row - 1, Column) = 0 Then
                Progress = Progress + 1: Row = Row - 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
            End If
        End If

        ' Check Down Left
        If Row + 1 <= 11 And Column - 1 >= 1 Then
            If BoardPlayer(Row + 1, Column - 1) = Player And Checked(Row + 1, Column - 1) = 0 Then
                Progress = Progress + 1: Row = Row + 1: Column = Column - 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
            End If
        End If

        ' Check Up Right
        If Row - 1 >= 1 And Column + 1 <= 11 Then
            If BoardPlayer(Row - 1, Column + 1) = Player And Checked(Row - 1, Column + 1) = 0 Then
                Progress = Progress + 1: Row = Row - 1: Column = Column + 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
            End If
        End If
    End If

    If Progress > 1 Then Progress = Progress - 1: GoTo CheckWinner

Next

Swap Player, Opponent: GoTo StartGame

ReleaseButton:
Do While _MouseInput
    If _MouseButton(1) = 0 Then Return
Loop

GoTo ReleaseButton


DrawPiece:
If X3 = 1 Then W = 1 Else W = 2
Paint (X1, X2), W, 0
Return

Winner:
PSet (BoardX(StepRow(1), StepColumn(1)), BoardY(StepRow(1), StepColumn(1))), 15
For Z = 2 To Progress: Line -(BoardX(StepRow(Z), StepColumn(Z)), BoardY(StepRow(Z), StepColumn(Z))), 15: Next

If Player = 1 Then
    PSet (BoardX(StepRow(1), StepColumn(1)), BoardY(StepRow(1), StepColumn(1))), 15: Draw "TA300D35"
    PSet (BoardX(StepRow(Progress), StepColumn(Progress)), BoardY(StepRow(Progress), StepColumn(Progress))), 15: Draw "TA120D35"
Else
    PSet (BoardX(StepRow(1), StepColumn(1)), BoardY(StepRow(1), StepColumn(1))), 15: Draw "TA0U35"
    PSet (BoardX(StepRow(Progress), StepColumn(Progress)), BoardY(StepRow(Progress), StepColumn(Progress))), 15: Draw "TA0D35"
End If

Locate 42, 5: Print "    Player"; Player; "is the Winner!";
Locate 44, 5: Print "    Play Another Game?  Y or N      ";

GetYorN:
A$ = UCase$(InKey$): If A$ = "" GoTo GetYorN
If A$ = "Y" Then Run
If A$ = "N" Then System
If Asc(A$) = 27 And FullScreen = 0 Then FullScreen = -1: _FullScreen _SquarePixels , _Smooth Else If Asc(A$) = 27 Then FullScreen = 0: _FullScreen _Off
GoTo GetYorN
Reply




Users browsing this thread: 1 Guest(s)