So i need to make this board game called candy land and so far i am missing a thing where i need to make that everytime the user which is Player 1 or player 2 roll there must be a label showing the roll that they get for example it's random number between 1-12 and if they get 7 then the label should show 7 but i can't seem to figure that out and also that there are several special box such as to move 1 step forward, 1 step back, 2 steps forward, and 2 steps back and i need to make it whnever the user land on those special box it will do as instructed but other than that i have manage to get the player 1 and player 2 working:
Dim lblArray(35) As Label 'array of labels that make up the game board
Dim intRules(35) As Integer 'parallel array containing rules for the squares corresponding to lblArray entries
Dim blnP1Turn As Boolean = True 'switches indicating whose turn it is
Dim blnP2Turn As Boolean = False
Dim intP1Position As Integer 'position of player 1 on board
Dim intP2Position As Integer 'position of player 2 on board
Dim blnDoubleOccupancy As Boolean = False 'True if both players on same square
Dim LblP1num, lblP2num As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'This is the size of each square (Label) in the game
Const intSQUARE_SIZE As Integer = 40
' this is the array of labels that make up the game board
'This for..Next Loop sets properties of each label in the array. The Select..Case statement
'places the labels around the edges of the form
For intCount = 0 To 35
lblArray(intCount) = New Label
lblArray(intCount).Size = New System.Drawing.Size(intSQUARE_SIZE, intSQUARE_SIZE)
lblArray(intCount).BorderStyle = BorderStyle.FixedSingle
lblArray(intCount).Name = "lbl" & intCount
lblArray(intCount).Visible = True
'The following line display the array index on each square
'You probably will want to comment it out
lblArray(intCount).Text = intCount.ToString
Select Case intCount
Case Is < 10
lblArray(intCount).Location = New System.Drawing.Point(intSQUARE_SIZE * intCount, 0)
Case 10 To 18
lblArray(intCount).Location =
New System.Drawing.Point(intSQUARE_SIZE * 9, intSQUARE_SIZE * (intCount - 9))
Case 19 To 27
lblArray(intCount).Location =
New System.Drawing.Point(intSQUARE_SIZE * 9 - intSQUARE_SIZE * (intCount - 18), intSQUARE_SIZE * 9)
Case 28 To 35
lblArray(intCount).Location =
New System.Drawing.Point(0, intSQUARE_SIZE * 9 - intSQUARE_SIZE * (intCount - 27))
End Select
' Set colors of the labels
Select Case intCount Mod 5
Case 0
lblArray(intCount).BackColor = Color.MediumOrchid
Case 1
lblArray(intCount).BackColor = Color.OrangeRed
lblArray(intCount).ForeColor = Color.White
Case 2
lblArray(intCount).BackColor = Color.Salmon
Case 3
lblArray(intCount).BackColor = Color.Turquoise
Case 4
lblArray(intCount).BackColor = Color.Yellow
lblArray(intCount).ForeColor = Color.Plum
End Select
Controls.Add(lblArray(intCount))
Next
'Initialize special squares
SetRules()
End Sub
Private Sub SetRules()
'Initialize special squares
lblArray(0).Text = "Start"
lblArray(lblArray.Length - 1).Text = "Finish Line"
lblArray(7).Text = "2 steps back"
intRules(7) = -2
lblArray(13).Text = "1 step forward"
intRules(13) = 1
lblArray(19).Text = "2 steps forward"
intRules(19) = 2
lblArray(32).Text = "1 step back"
intRules(32) = -1
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Randomize()
Dim intDice As Integer = CInt(Fix(Rnd() * 7) + 1)
If blnP1Turn = True Then
lblArray(LblP1num).Text = CStr(LblP1num)
intP1Position += intDice
LblP1num = intP1Position
If intP1Position >= 35 Then
lblArray(35).Text = "P1"
MessageBox.Show("Player One Wins!")
Else
If intP1Position = intP2Position Then
lblArray(intP1Position).Text = "P1 P2"
Else
lblArray(intP1Position).Text = "P1"
End If
End If
blnP1Turn = False
blnP2Turn = True
Else
MessageBox.Show("It's Not Your Turn.")
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Randomize()
Dim intDice As Integer = CInt(Fix(Rnd() * 7) + 1)
If blnP2Turn = True Then
lblArray(lblP2num).Text = CStr(lblP2num)
intP2Position += intDice
lblP2num = intP2Position
If intP2Position >= 35 Then
lblArray(35).Text = "P2"
MessageBox.Show("Player Two Wins!")
Else
If intP1Position = intP2Position Then
lblArray(intP2Position).Text = "P1 P2"
Else
lblArray(intP2Position).Text = "P2"
End If
End If
blnP1Turn = True
blnP2Turn = False
Else
MessageBox.Show("It's Not Your Turn.")
End If
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Question
atyemail
So i need to make this board game called candy land and so far i am missing a thing where i need to make that everytime the user which is Player 1 or player 2 roll there must be a label showing the roll that they get for example it's random number between 1-12 and if they get 7 then the label should show 7 but i can't seem to figure that out and also that there are several special box such as to move 1 step forward, 1 step back, 2 steps forward, and 2 steps back and i need to make it whnever the user land on those special box it will do as instructed but other than that i have manage to get the player 1 and player 2 working:
candy land game.zip
Link to comment
Share on other sites
5 answers to this question
Recommended Posts