Author Topic: Hex Board Game  (Read 2898 times)

0 Members and 1 Guest are viewing this topic.

Offline Donald Foster

  • Newbie
  • Posts: 63
    • View Profile
Hex Board Game
« on: December 15, 2021, 10:16:48 pm »
 
Hex Screenshot.png


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: QB64: [Select]
  1. _Title "Connection Board Game - Programmed by Donald L. Foster Jr. 2020-2021"
  2.  
  3. Screen _NewImage(1095, 735, 256)
  4.  
  5. _PaletteColor 1, _RGB32(0, 142, 223) '   Medium Blue
  6. _PaletteColor 2, _RGB32(235, 30, 54) '   Medium Red
  7. _PaletteColor 3, _RGB32(215, 215, 215) ' Grey
  8. _PaletteColor 4, _RGB32(0, 167, 248) '   Light Blue
  9. _PaletteColor 5, _RGB32(0, 117, 198) '   Dark Blue
  10. _PaletteColor 6, _RGB32(255, 55, 74) '   Light Red
  11. _PaletteColor 7, _RGB32(205, 5, 24) '    Dark Red
  12. _PaletteColor 9, _RGB32(1, 1, 1)
  13.  
  14. Dim As Integer Player, Opponent, Row, Column, Progress, Counter
  15. Dim As Integer Z, Y, X, W, V, X1, X2, X3
  16. Dim As Integer BoardX(13, 13), BoardY(13, 13), BoardPlayer(13, 13), Checked(13, 13)
  17. Dim As Integer PlayerColor(3), StepRow(30), StepColumn(30)
  18.  
  19. Player = 1: Opponent = 2: Counter = 1: StartingX = 456: StartingY = 67
  20. PlayerColor(1) = 1: PlayerColor(2) = 2
  21.  
  22. BoardHex$ = "C0TA0BL33D19TA60D38TA120D38TA180D38TA240D38TA300D38TA0D19"
  23.  
  24. Cls , 15
  25.  
  26. ' Draw Game Board
  27. PSet (43, 74), 0: Draw "TA0D37TA60D36TA0D37TA60D36TA0D37TA60D35TA0D37TA60D36TA0D37TA60D36TA0D37TA60D36TA0D37TA60D36TA0D37TA60D35TA0D37TA60D36TA0D37TA60D36TA0D38"
  28. Draw "TA60D37TA120D37TA60D36TA120D36TA60D36TA120D36TA60D37TA120D37TA60D36TA120D36TA60D36TA120D36TA60D37TA120D37TA60D36TA120D36TA60D37TA120D37TA60D36TA120D36TA60D36TA120D37"
  29. Draw "TA0U37TA240D36TA0U37TA240D35TA0U36TA240D36TA0U37TA240D36TA0U37TA240D36TA0U37TA240D36TA0U37TA240D37TA0U37TA240D36TA0U37TA240D36TA0U37TA240D36TA0U39"
  30. Draw "TA240D36TA300D36TA240D36TA300D36TA240D36TA300D36TA240D36TA300D37TA240D37TA300D36TA240D36TA300D36TA240D37TA300D37TA240D36TA300D36TA240D36TA300D37TA240D37TA300D36TA240D36TA300D37"
  31. Draw "TA240D20TA330D30TA29.5D699TA150ND30TA0R699TA330U30TA240ND28TA330U28TA29.5U699TA150NU30TA0L699TA330D30TA0BD10P1,0BE20P2,0BR695P1,0BD630P2,0"
  32. Paint (200, 100), 9, 0
  33. X = 92: Increase = 0: Indent = 0
  34. For Z = 1 To 11
  35.     Starting = 75
  36.     For Y = 1 To 11
  37.         PSet (Starting + Indent + Increase, X), 15: Draw "C0TA0BL31BU18D36TA60D36TA120D36TA180D36TA240D36TA300D36BR10P3,0"
  38.         '   CIRCLE (Starting + Indent + Increase, X), 28, 0
  39.         BoardX(Z, Y) = Starting + Indent + Increase: BoardY(Z, Y) = X
  40.         If Y = 11 Then Indent = Indent + 31: Increase = 0 Else Increase = Increase + 63
  41.     Next
  42.     X = X + 55
  43.  
  44. StartGame:
  45. ' Draw Player Indicator
  46. Color 0, 15: Locate 3, 97: Print "H  E  X    B  O  A  R  D    G  A  M  E";
  47. PSet (943, 100), 15: Draw BoardHex$: Paint (943, 100), PlayerColor(Player), 0
  48. X1 = 943: X2 = 100: X3 = Player: GoSub DrawPiece
  49. Locate 10, 115: Print "Player"; Player;
  50.  
  51. Locate 44, 5: Print "Choose Location to Place Your Piece";
  52.  
  53. GetLocation:
  54.     For Z = 1 To 11
  55.         For Y = 1 To 11
  56.             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
  57.             If _MouseButton(1) = -1 And BoardPlayer(Z, Y) = 0 And Selected = 1 Then
  58.                 GoSub ReleaseButton: BoardPlayer(Z, Y) = Player: X1 = BoardX(Z, Y): X2 = BoardY(Z, Y): X3 = Player: GoSub DrawPiece: Row = Z: Column = Y: GoTo CheckForWinner
  59.             End If
  60.         Next
  61.     Next
  62. 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
  63. GoTo GetLocation
  64.  
  65. CheckForWinner:
  66. For V = 1 To 11
  67.     For Z = 1 To 11: For Y = 1 To 11: Checked(Z, Y) = 0: Next: Next
  68.  
  69.     If Player = 1 Then Row = V: Column = 1 Else Row = 1: Column = V
  70.  
  71.     If BoardPlayer(Row, Column) = Player Then
  72.         Progress = 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1
  73.  
  74.         CheckWinner: If (Player = 1 And Column = 11) Or (Player = 2 And Row = 11) GoTo Winner
  75.  
  76.         ' Check Right
  77.         If Column + 1 <= 11 Then
  78.             If BoardPlayer(Row, Column + 1) = Player And Checked(Row, Column + 1) = 0 Then
  79.                 Progress = Progress + 1: Column = Column + 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
  80.             End If
  81.         End If
  82.  
  83.         ' Check Down
  84.         If Row + 1 <= 11 Then
  85.             If BoardPlayer(Row + 1, Column) = Player And Checked(Row + 1, Column) = 0 Then
  86.                 Progress = Progress + 1: Row = Row + 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
  87.             End If
  88.         End If
  89.  
  90.         ' Check Left
  91.         If Column - 1 >= 1 Then
  92.             If BoardPlayer(Row, Column - 1) = Player And Checked(Row, Column - 1) = 0 Then
  93.                 Progress = Progress + 1: Column = Column - 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
  94.             End If
  95.         End If
  96.  
  97.         ' Check Up
  98.         If Row - 1 >= 1 Then
  99.             If BoardPlayer(Row - 1, Column) = Player And Checked(Row - 1, Column) = 0 Then
  100.                 Progress = Progress + 1: Row = Row - 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
  101.             End If
  102.         End If
  103.  
  104.         ' Check Down Left
  105.         If Row + 1 <= 11 And Column - 1 >= 1 Then
  106.             If BoardPlayer(Row + 1, Column - 1) = Player And Checked(Row + 1, Column - 1) = 0 Then
  107.                 Progress = Progress + 1: Row = Row + 1: Column = Column - 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
  108.             End If
  109.         End If
  110.  
  111.         ' Check Up Right
  112.         If Row - 1 >= 1 And Column + 1 <= 11 Then
  113.             If BoardPlayer(Row - 1, Column + 1) = Player And Checked(Row - 1, Column + 1) = 0 Then
  114.                 Progress = Progress + 1: Row = Row - 1: Column = Column + 1: StepRow(Progress) = Row: StepColumn(Progress) = Column: Checked(Row, Column) = 1: GoTo CheckWinner
  115.             End If
  116.         End If
  117.     End If
  118.  
  119.     If Progress > 1 Then Progress = Progress - 1: GoTo CheckWinner
  120.  
  121.  
  122. Swap Player, Opponent: GoTo StartGame
  123.  
  124. ReleaseButton:
  125.     If _MouseButton(1) = 0 Then Return
  126.  
  127. GoTo ReleaseButton
  128.  
  129.  
  130. DrawPiece:
  131. If X3 = 1 Then W = 1 Else W = 2
  132. Paint (X1, X2), W, 0
  133.  
  134. Winner:
  135. PSet (BoardX(StepRow(1), StepColumn(1)), BoardY(StepRow(1), StepColumn(1))), 15
  136. For Z = 2 To Progress: Line -(BoardX(StepRow(Z), StepColumn(Z)), BoardY(StepRow(Z), StepColumn(Z))), 15: Next
  137.  
  138. If Player = 1 Then
  139.     PSet (BoardX(StepRow(1), StepColumn(1)), BoardY(StepRow(1), StepColumn(1))), 15: Draw "TA300D35"
  140.     PSet (BoardX(StepRow(Progress), StepColumn(Progress)), BoardY(StepRow(Progress), StepColumn(Progress))), 15: Draw "TA120D35"
  141.     PSet (BoardX(StepRow(1), StepColumn(1)), BoardY(StepRow(1), StepColumn(1))), 15: Draw "TA0U35"
  142.     PSet (BoardX(StepRow(Progress), StepColumn(Progress)), BoardY(StepRow(Progress), StepColumn(Progress))), 15: Draw "TA0D35"
  143.  
  144. Locate 42, 5: Print "     Player"; Player; "is the Winner!";
  145. Locate 44, 5: Print "     Play Another Game?  Y or N      ";
  146.  
  147. GetYorN:
  148. A$ = UCase$(InKey$): If A$ = "" GoTo GetYorN
  149. If A$ = "Y" Then Run
  150. If A$ = "N" Then System
  151. If Asc(A$) = 27 And FullScreen = 0 Then FullScreen = -1: _FullScreen _SquarePixels , _Smooth Else If Asc(A$) = 27 Then FullScreen = 0: _FullScreen _Off
  152. GoTo GetYorN
  153.  
  154.