Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a VBA Sub Program to create the snakes and ladders game for two players us

ID: 3606505 • Letter: W

Question

Write a VBA Sub Program to create the snakes and ladders game for two players using one die. The player who reaches the 100th square first wins the game. Below are the rules that you need to keep in mind while building this game.

a. Create a 10 X 10 board and place the snakes and ladders as shown in the next page.   

b. Player 1 will start the game by rolling one die, which is a randomly generated number between 1 and 6 when the button “Player 1” is clicked. He/She should advance his/her token the rolled number of spaces. Similarly, player 2 takes his/her turn when the button “Player 2” is clicked. Players should alternate their turns.   

c. If a player’s token lands on the lower-numbered end of a ladder, the player moves the   token up to the ladder’s higher-numbered square. If the player’s token lands on the highernumbered square of a snake, the token is moved down to the snake’s lower-numbered square.

d. The player who first reaches the 100th square is declared the winner.    f. Create a sub program for Player 1 and Player 2 separately.  

g. Create a sub program to restart the game anytime when the button named “Restart” is clicked.

The blue arrow represents the ladders, and the orange arrow represents the snakes. If a player’s token lands on 18, the player should move up his/her token to 44. If a player’s token lands on 32, the player should move his/her token down to 11.  

Indicate the player’s movement by changing the interior color of the cells. Differentiate the player’s movement with different colors which represent the token as shown below:

i am having trouble doing this i hope someone help me do it.

13 100 998 79659493 92 91 Player 1 53 Player 2 Restart 21 22 23 242526 10 1

Explanation / Answer

Here is Your code(Enjoy):

Option Base 1
Dim c1(10) As Variant
Dim r(10) As Variant

Dim x As Integer
Dim m As Integer
Dim n As Integer
Dim Number As Integer
Dim NumberTotal As Single
Dim NumberTotal1 As Single
Dim participant As Integer
Dim t As Integer


Private Sub Command2_Click()
'Original place movement
Image1(0).Move 10200, 5520
Image1(1).Move 10200, 6480
NumberTotal = 0
NumberTotal1 = 0
Label2.Caption = ""
MMControl1.Command = "close"
End Sub

Private Sub ThirdCommandClick()
End
End Sub

Private Sub Load_Form()
' Assign column and rows

c1(1) = 600
r(1) = 8200
For i = 1 To 9
c1(i + 1) = c1(i) + 800

Next
For j = 1 To 9
r(j + 1) = r(j) - 800
Next
End Sub


'To initiate the ro11ing of dice
Private Sub ro11()
x = x + 10
Randomize Timer
n = Int(1 + Rnd * 6)
For i = 0 To 6
Shape1(i).Visible = False
Next
If n = 1 Then
Shape1(3).Visible = True
Shape2.FillColor = &HC0C0C0

End If
If n = 2 Then
Shape1(2).Visible = True
Shape1(4).Visible = True
Shape2.FillColor = &H8080FF
End If
If n = 3 Then
Shape1(2).Visible = True
Shape1(3).Visible = True
Shape1(4).Visible = True
Shape2.FillColor = &H80FF&
End If
If n = 4 Then
Shape1(0).Visible = True
Shape1(2).Visible = True
Shape1(4).Visible = True
Shape1(6).Visible = True
Shape2.FillColor = &HFFFF00
End If
If n = 5 Then
Shape1(0).Visible = True
Shape1(2).Visible = True
Shape1(3).Visible = True
Shape1(4).Visible = True
Shape1(6).Visible = True
Shape2.FillColor = &HFFFF&
End If
If n = 6 Then
Shape1(0).Visible = True
Shape1(1).Visible = True
Shape1(2).Visible = True
Shape1(4).Visible = True
Shape1(5).Visible = True
Shape1(6).Visible = True
Shape2.FillColor = &HFF00FF
End If
End Sub
Private Sub FirstCommandClick(Index As Integer)

If Index = 0 Then
participant = 1
End If
If Index = 1 Then
participant = 2
End If

Timer1.Enabled = True
x = 0
End Sub

Private Sub Timer1_Timer()
If x < 100 Then
Call ro11
Else
Timer1.Enabled = False

'dice number check

If Shape1(3).Visible = True Then
Number = 1
End If

If (Shape1(2).Visible = True) And (Shape1(4).Visible = True) Then
Number = 2
End If

If (Shape1(2).Visible = True) And (Shape1(3).Visible = True) And (Shape1(4).Visible = True) Then
Number = 3
End If

If (Shape1(0).Visible = True) And (Shape1(2).Visible = True) And (Shape1(4).Visible = True) And (Shape1(6).Visible = True) Then
Number = 4
End If


If (Shape1(0).Visible = True) And (Shape1(2).Visible = True) And (Shape1(3).Visible = True) And (Shape1(4).Visible = True) And (Shape1(6).Visible = True) Then
Number = 5
End If


If (Shape1(0).Visible = True) And (Shape1(1).Visible = True) And (Shape1(2).Visible = True) And (Shape1(4).Visible = True) And (Shape1(5).Visible = True) Then

Number = 6

End If
'participant 1 move
'Movement across column and rows

If participant = 1 Then

NumberTotal = NumberTotal + Number
If NumberTotal < 11 Then
Image1(0).Move c1(NumberTotal), r(1)
If NumberTotal = 10 Then
Image1(0).Move c1(8), r(3)
NumberTotal = 28
End If

End If

If NumberTotal > 10 And NumberTotal < 21 Then
Image1(0).Move c1(21 - NumberTotal), r(2)
If NumberTotal = 17 Then
Image1(0).Move c1(4), r(4)
NumberTotal = 37
End If
End If
If NumberTotal > 20 And NumberTotal < 31 Then
Image1(0).Move c1(NumberTotal - 20), r(3)
End If
If NumberTotal > 30 And NumberTotal < 41 Then
Image1(0).Move c1(41 - NumberTotal), r(4)
If NumberTotal = 34 Then
Image1(0).Move c1(5), r(2)
NumberTotal = 16
End If
If NumberTotal = 31 Then
Image1(0).Move c1(10), r(7)
NumberTotal = 70
End If
End If


If NumberTotal > 40 And NumberTotal < 51 Then
Image1(0).Move c1(NumberTotal - 40), r(5)
If NumberTotal = 45 Then
Image1(0).Move c1(4), r(9)
NumberTotal = 84
End If
If NumberTotal = 44 Then
Image1(0).Move c1(1), r(3)
NumberTotal = 21
End If

End If

If NumberTotal > 50 And NumberTotal < 61 Then
Image1(0).Move c1(61 - NumberTotal), r(6)
End If
If NumberTotal > 60 And NumberTotal < 71 Then
Image1(0).Move c1(NumberTotal - 60), r(7)
If NumberTotal = 68 Then
Image1(0).Move c1(8), r(5)
NumberTotal = 48
End If
End If

If NumberTotal > 70 And NumberTotal < 81 Then
Image1(0).Move c1(81 - NumberTotal), r(8)
If NumberTotal = 79 Then
Image1(0).Move c1(2), r(6)
NumberTotal = 59
End If
If NumberTotal = 78 Then
Image1(0).Move c1(4), r(10)
NumberTotal = 97
End If
End If

If NumberTotal > 80 And NumberTotal < 91 Then
Image1(0).Move c1(NumberTotal - 80), r(9)
End If
If NumberTotal > 90 And NumberTotal < 101 Then
Image1(0).Move c1(101 - NumberTotal), r(10)
If NumberTotal = 95 Then
Image1(0).Move c1(8), r(8)
NumberTotal = 73
End If
End If

If NumberTotal > 100 Or NumberTotal = 100 Then
Image1(0).Move c1(1), r(10)
End If

End If

'participant 2 move

If participant = 2 Then
NumberTotal1 = NumberTotal1 + Number
If NumberTotal1 < 11 Then
Image1(1).Move c1(NumberTotal1), r(1)
If NumberTotal1 = 10 Then
Image1(1).Move c1(8), r(3)
NumberTotal1 = 28
End If
End If
If NumberTotal1 > 10 And NumberTotal1 < 21 Then
Image1(1).Move c1(21 - NumberTotal1), r(2)
If NumberTotal1 = 17 Then
Image1(1).Move c1(4), r(4)
NumberTotal1 = 37
End If
End If
If NumberTotal1 > 20 And NumberTotal1 < 31 Then
Image1(1).Move c1(NumberTotal1 - 20), r(3)
End If
If NumberTotal1 > 30 And NumberTotal1 < 41 Then
Image1(1).Move c1(41 - NumberTotal1), r(4)
If NumberTotal1 = 34 Then
Image1(1).Move c1(5), r(2)
NumberTotal1 = 16
End If
If NumberTotal1 = 31 Then
Image1(1).Move c1(10), r(7)
NumberTotal1 = 70
End If
End If

If NumberTotal1 > 40 And NumberTotal1 < 51 Then
Image1(1).Move c1(NumberTotal1 - 40), r(5)
If NumberTotal1 = 45 Then
Image1(1).Move c1(4), r(9)
NumberTotal1 = 84
End If
If NumberTotal1 = 44 Then
Image1(1).Move c1(1), r(3)
NumberTotal1 = 21
End If
End If


If NumberTotal1 > 50 And NumberTotal1 < 61 Then
Image1(1).Move c1(61 - NumberTotal1), r(6)
End If
If NumberTotal1 > 60 And NumberTotal1 < 71 Then
Image1(1).Move c1(NumberTotal1 - 60), r(7)
If NumberTotal1 = 68 Then
Image1(1).Move c1(8), r(5)
NumberTotal1 = 48
End If
End If
If NumberTotal1 > 70 And NumberTotal1 < 81 Then
Image1(1).Move c1(81 - NumberTotal1), r(8)
If NumberTotal1 = 79 Then
Image1(1).Move c1(2), r(6)
NumberTotal1 = 59
End If
If NumberTotal1 = 78 Then
Image1(1).Move c1(4), r(10)
NumberTotal1 = 97
End If
End If
If NumberTotal1 > 80 And NumberTotal1 < 91 Then
Image1(1).Move c1(NumberTotal1 - 80), r(9)
End If
If NumberTotal1 > 90 And NumberTotal1 < 101 Then
Image1(1).Move c1(101 - NumberTotal1), r(10)
If NumberTotal1 = 95 Then
Image1(1).Move c1(8), r(8)
NumberTotal1 = 73
End If
End If
If NumberTotal1 > 100 Or NumberTotal1 = 100 Then
Image1(1).Move c1(1), r(10)
End If

End If


'applause sound


If (NumberTotal > 100 Or NumberTotal = 100) And NumberTotal1 < 100 Then
Label2.Caption = "Participant 1 Wins"
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:Liew FolderVB programudiopplause.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"

End If
If (NumberTotal1 > 100 Or NumberTotal1 = 100) And NumberTotal < 100 Then
Label2.Caption = "Participant 2 Wins"
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:Liew FolderVB programudiopplause.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"

End If

End If

End Sub

Private Sub Timer2_Timer()
delay
If t < 1000 Then
Else
Timer2.Enabled = False
End If

End Sub

Sub delay()
t = t + 1

End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote