VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



snake and ladders

by bryan ace guanlao (2 Submissions)
Category: Games
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Sun 28th September 2008
Date Added: Mon 8th February 2021
Rating: (1 Votes)

snake and ladders

API Declarations


Dim ctr, ctr2, p1loop, p2loop As Integer
Dim roll, p1, p2 As Boolean
Dim turn As Integer
Dim abante1, adtras1, abante2, adtras2 As Boolean
Dim defaultTop1, defaultLeft1, defaultTop2, defaultLeft2 As Integer
Dim msgdelay As Integer

Rate snake and ladders



Option Explicit
Private Sub cmdroll_Click()
roll = True
cmdstop.Visible = True
cmdroll.Visible = False
End Sub

Private Sub cmdstop_Click()
lblTurn.Caption = "Turn: Player " & turn
If turn = 0 Then lblTurn.Caption = "Turn: Player 2"
roll = False
cmdroll.Visible = True
cmdstop.Visible = False
turn = turn + 1
If turn > 2 Then turn = 1
'player 1
If turn = 1 Then
p1 = True
abante1 = True
End If

'player 2
If turn = 2 Then
p2 = True
abante2 = True
End If

End Sub

Private Sub Form_Load()
roll = False
p1 = False
p2 = False
p1value = 0
p2value = 0
ctr = 17
ctr2 = 26
defaultTop1 = Player(1).Top
defaultLeft1 = Player(1).Left
defaultTop2 = Player(2).Top
defaultLeft2 = Player(2).Left
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
shpExit.BackColor = &H8000&
End Sub

Private Sub lblEnd_Click()
End
End Sub

Private Sub lblEnd_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
shpExit.BackColor = &HC0FFC0
End Sub

Private Sub Timer1_Timer()
If roll = True Then
diceValue = Int(Rnd * 6) + 1
dice.Picture = LoadPicture(App.Path & "\Image\" & diceValue & ".bmp")
End If
End Sub

Private Sub Timer2_Timer()
msgdelay = msgdelay + 1
If msgdelay >= 5 Then
lblMessage.Visible = False
msgdelay = 0
Timer2.Enabled = False
End If
End Sub

Private Sub tmrAnimateMove_Timer()
'player1
If p1 = True Then
cmdroll.Enabled = False

If abante1 = True Then
adtras1 = False
p1value = p1value + 1
If p1value > 100 Then
p1value = 100
abante1 = False
adtras1 = True
End If
End If

If adtras1 = True Then
p1value = p1value - 1
End If

Player(1).Top = coordinate(p1value).Top
Player(1).Left = coordinate(p1value).Left
lblPlayer1.Caption = "Player 1: " & p1value
pointer1.Top = Player(1).Top - pointer1.Height
pointer1.Left = Player(1).Left - 8
p1loop = p1loop + 1

If p1loop >= diceValue Then
cmdroll.Enabled = True
p1 = False
p1loop = 0
If p1value = 100 Then
MsgBox "Player 1 Win", vbOKOnly
new_game
End If
If p1value = 6 Then
six1
End If
If p1value = 48 Then
fourtyeight1
End If
If p1value = 79 Then
seventynine1
End If
If p1value = 37 Then
thirtyseven1
End If
If p1value = 50 Then
fifty1
End If
If p1value = 67 Then
sixtyseven1
End If
If p1value = 96 Then
ninetysix1
End If


End If

End If

'player2
If p2 = True Then
cmdroll.Enabled = False

If abante2 = True Then
p2value = p2value + 1
adtras2 = False
If p2value > 100 Then
p2value = 100
abante2 = False
adtras2 = True
End If
End If
If adtras2 = True Then
p2value = p2value - 1
End If
Player(2).Top = coordinate(p2value).Top
Player(2).Left = coordinate(p2value).Left
lblPlayer2.Caption = "Player 2: " & p2value
pointer2.Top = Player(2).Top - pointer2.Height
pointer2.Left = Player(2).Left - 8
p2loop = p2loop + 1

If p2loop >= diceValue Then
cmdroll.Enabled = True
p2 = False
p2loop = 0
If p2value = 100 Then
MsgBox "Player 2 Win", vbOKOnly
new_game
End If
If p2value = 6 Then
six2
End If
If p2value = 48 Then
fourtyeight2
End If
If p2value = 79 Then
seventynine2
End If
If p2value = 37 Then
thirtyseven2
End If
If p2value = 50 Then
fifty2
End If
If p2value = 67 Then
sixtyseven2
End If
If p2value = 96 Then
ninetysix2
End If
End If

End If
End Sub

Private Sub tmrAnimatePointer_Timer()
ctr = ctr + 1
If ctr > 27 Then ctr = 17

ctr2 = ctr2 + 1
If ctr2 > 27 Then ctr2 = 17

pointer1.Height = ctr
pointer2.Height = ctr2
End Sub
Sub new_game()
Player(1).Top = defaultTop1
Player(1).Left = defaultLeft1
pointer1.Top = Player(1).Top - pointer1.Height
pointer1.Left = Player(1).Left - 8
p1value = 0
Player(2).Top = defaultTop2
Player(2).Left = defaultLeft2
pointer2.Top = Player(2).Top - pointer2.Height
pointer2.Left = Player(2).Left - 8
p2value = 0
End Sub
Sub six1()
p1value = 26
Player(1).Top = coordinate(p1value).Top
Player(1).Left = coordinate(p1value).Left
pointer1.Top = Player(1).Top - pointer1.Height
pointer1.Left = Player(1).Left - 8
lblMessage.Caption = "Player 1 used ladder"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub six2()
p2value = 26
Player(2).Top = coordinate(p2value).Top
Player(2).Left = coordinate(p2value).Left
pointer2.Top = Player(2).Top - pointer2.Height
pointer2.Left = Player(2).Left - 8
lblMessage.Caption = "Player 2 used ladder"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub fourtyeight1()
p1value = 12
Player(1).Top = coordinate(p1value).Top
Player(1).Left = coordinate(p1value).Left
pointer1.Top = Player(1).Top - pointer1.Height
pointer1.Left = Player(1).Left - 8
lblMessage.Caption = "Player 1 eat by a snake"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub fourtyeight2()
p2value = 12
Player(2).Top = coordinate(p2value).Top
Player(2).Left = coordinate(p2value).Left
pointer2.Top = Player(2).Top - pointer2.Height
pointer2.Left = Player(2).Left - 8
lblMessage.Caption = "Player 2 eat by a snake"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub thirtyseven1()
p1value = 57
Player(1).Top = coordinate(p1value).Top
Player(1).Left = coordinate(p1value).Left
pointer1.Top = Player(1).Top - pointer1.Height
pointer1.Left = Player(1).Left - 8
lblMessage.Caption = "Player 1 used ladder"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub thirtyseven2()
p2value = 57
Player(2).Top = coordinate(p2value).Top
Player(2).Left = coordinate(p2value).Left
pointer2.Top = Player(2).Top - pointer2.Height
pointer2.Left = Player(2).Left - 8
lblMessage.Caption = "Player 2 used ladder"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub seventynine1()
p1value = 43
Player(1).Top = coordinate(p1value).Top
Player(1).Left = coordinate(p1value).Left
pointer1.Top = Player(1).Top - pointer1.Height
pointer1.Left = Player(1).Left - 8
lblMessage.Caption = "Player 1 eat by a snake"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub seventynine2()
p2value = 43
Player(2).Top = coordinate(p2value).Top
Player(2).Left = coordinate(p2value).Left
pointer2.Top = Player(2).Top - pointer2.Height
pointer2.Left = Player(2).Left - 8
lblMessage.Caption = "Player 2 eat by a snake"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub fifty1()
p1value = 72
Player(1).Top = coordinate(p1value).Top
Player(1).Left = coordinate(p1value).Left
pointer1.Top = Player(1).Top - pointer1.Height
pointer1.Left = Player(1).Left - 8
lblMessage.Caption = "Player 1 used ladder"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub fifty2()
p2value = 72
Player(2).Top = coordinate(p2value).Top
Player(2).Left = coordinate(p2value).Left
pointer2.Top = Player(2).Top - pointer2.Height
pointer2.Left = Player(2).Left - 8
lblMessage.Caption = "Player 2 used ladder"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub sixtyseven1()
p1value = 87
Player(1).Top = coordinate(p1value).Top
Player(1).Left = coordinate(p1value).Left
pointer1.Top = Player(1).Top - pointer1.Height
pointer1.Left = Player(1).Left - 8
lblMessage.Caption = "Player 1 used ladder"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub sixtyseven2()
p2value = 87
Player(2).Top = coordinate(p2value).Top
Player(2).Left = coordinate(p2value).Left
pointer2.Top = Player(2).Top - pointer2.Height
pointer2.Left = Player(2).Left - 8
lblMessage.Caption = "Player 2 used ladder"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub ninetysix1()
p1value = 66
Player(1).Top = coordinate(p1value).Top
Player(1).Left = coordinate(p1value).Left
pointer1.Top = Player(1).Top - pointer1.Height
pointer1.Left = Player(1).Left - 8
lblMessage.Caption = "Player 1 eat by a snake"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub
Sub ninetysix2()
p2value = 66
Player(2).Top = coordinate(p2value).Top
Player(2).Left = coordinate(p2value).Left
pointer2.Top = Player(2).Top - pointer2.Height
pointer2.Left = Player(2).Left - 8
lblMessage.Caption = "Player 2 eat by a snake"
Timer2.Enabled = True
lblMessage.Visible = True
End Sub


Download this snippet    Add to My Saved Code

snake and ladders Comments

No comments have been posted about snake and ladders. Why not be the first to post a comment about snake and ladders.

Post your comment

Subject:
Message:
0/1000 characters