Advertisement
joemch

BoardGame Mulit Jump PJM

Apr 23rd, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.60 KB | None | 0 0
  1. Sub MakeMove(ByRef Board(,) As String, ByRef PlayersPieces(,) As Integer, ByRef OpponentsPieces(,) As Integer, ByVal ListOfMoves() As MoveRecord, ByVal PieceIndex As Integer)
  2.         Dim Piece, MiddlePiece, Answer As String
  3.         Dim NewRow, NewColumn, PlayersPieceIndex, CurrentRow, CurrentColumn, MiddlePieceRow, MiddlePieceColumn, Direction As Integer
  4.         Dim Jumping, CheckedRight, CheckedLeft, JumpAgainRight, JumpAgainLeft As Boolean
  5.         PlayersPieces(0, 0) = PlayersPieces(0, 0) + 1
  6.         If PieceIndex > 0 Then
  7.             Piece = ListOfMoves(PieceIndex).Piece
  8.             NewRow = ListOfMoves(PieceIndex).NewRow
  9.             NewColumn = ListOfMoves(PieceIndex).NewColumn
  10.             If Len(Piece) = 2 Then
  11.                 PlayersPieceIndex = CInt(Right(Piece, 1))
  12.             Else
  13.                 PlayersPieceIndex = CInt(Right(Piece, 2))
  14.             End If
  15.             If Left(Piece, 1).ToUpper = "A" Then
  16.                 Direction = 1
  17.             Else
  18.                 Direction = -1
  19.             End If
  20.             CurrentRow = PlayersPieces(PlayersPieceIndex, Row)
  21.             CurrentColumn = PlayersPieces(PlayersPieceIndex, Column)
  22.             Jumping = ListOfMoves(PieceIndex).CanJump
  23.             MovePiece(Board, PlayersPieces, Piece, NewRow, NewColumn)
  24.             While Jumping
  25.                 MiddlePieceRow = (CurrentRow + NewRow) \ 2
  26.                 MiddlePieceColumn = (CurrentColumn + NewColumn) \ 2
  27.                 MiddlePiece = Board(MiddlePieceRow, MiddlePieceColumn)
  28.                 Console.WriteLine("jumped over " & MiddlePiece)
  29.                 If ValidJump(Board, PlayersPieces, Piece, NewRow + Direction + Direction, NewColumn + 2) Then
  30.                     JumpAgainRight = True
  31.                 End If
  32.                 If ValidJump(Board, PlayersPieces, Piece, NewRow + Direction + Direction, NewColumn - 2) Then
  33.                     JumpAgainLeft = True
  34.                 End If
  35.                 If JumpAgainRight And Not CheckedRight Then
  36.                     DisplayBoard(Board)
  37.                     Console.WriteLine("The selected piece can jump again to the right - do you want to make this move(Y/N)?")
  38.                     Answer = Console.ReadLine
  39.                     If Answer = "Y" Then
  40.                         CheckedRight = False
  41.                         CurrentRow = NewRow
  42.                         CurrentColumn = NewColumn
  43.                         NewRow = NewRow + Direction + Direction
  44.                         NewColumn = NewColumn + 2
  45.                         MovePiece(Board, PlayersPieces, Piece, NewRow, NewColumn)
  46.                     Else
  47.                         CheckedRight = True
  48.                     End If
  49.                     JumpAgainRight = False
  50.                 ElseIf JumpAgainLeft And Not CheckedLeft Then
  51.                     DisplayBoard(Board)
  52.                     Console.WriteLine("The selected piece can jump again to the left - do you want to make this move(Y/N)?")
  53.                     Answer = Console.ReadLine
  54.                     If Answer = "Y" Then
  55.                         CheckedLeft = False
  56.                         CurrentRow = NewRow
  57.                         CurrentColumn = NewColumn
  58.                         NewRow = NewRow + Direction + Direction
  59.                         NewColumn = NewColumn - 2
  60.                         MovePiece(Board, PlayersPieces, Piece, NewRow, NewColumn)
  61.                     Else
  62.                         CheckedLeft = True
  63.                     End If
  64.                     JumpAgainLeft = False
  65.                 Else
  66.                     Jumping = False
  67.                 End If
  68.             End While
  69.  
  70.         End If
  71.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement