Я должен создать игру змей и лестниц для проекта. У меня есть 30 мест на моей доске. Если маркер проходит мимо 30 сбои приложений с:Змеи и лестницы
«Необработанное исключение типа„System.NullReferenceException“произошло в appCounter.exe
Дополнительная информация: Ссылка на объект не указывает на экземпляр объекта.»
Я хочу Marker, чтобы остаться там, где она есть, если число проката доведет его прошлым 30.
здесь мой код:
Public Class frmBoard
Dim intScore As Integer
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
'declartions
Dim intValue As Integer
Dim strCounterName As String
Dim roll As New Random()
Dim intRoll = roll.Next(1, 7)
'make the current counter visible
If intScore > 0 Then
strCounterName = "lblCounter" & intScore
Me.Controls(strCounterName).Visible = False
End If
'input
intValue = intRoll
intScore = intScore + intValue
strCounterName = "lblcounter" & intScore.ToString
'output
txtMove.Text = intRoll
Me.Controls(strCounterName).Visible = True
If intScore = 3 Then
lblCounter3.Visible = False
lblCounter22.Visible = True
intScore = 22
End If
If intScore = 5 Then
lblCounter5.Visible = False
lblCounter8.Visible = True
intScore = 8
End If
If intScore = 11 Then
lblCounter11.Visible = False
lblCounter26.Visible = True
intScore = 26
End If
If intScore = 20 Then
lblCounter20.Visible = False
lblCounter29.Visible = True
intScore = 29
End If
If intScore = 17 Then
lblCounter17.Visible = False
lblCounter4.Visible = True
intScore = 4
End If
If intScore = 19 Then
lblCounter19.Visible = False
lblCounter7.Visible = True
intScore = 7
End If
If intScore = 21 Then
lblCounter21.Visible = False
lblCounter9.Visible = True
intScore = 9
End If
If intScore = 27 Then
lblCounter27.Visible = False
lblCounter1.Visible = True
intScore = 1
End If
If intScore = 31 Then
lblCounter31.Visible = False
lblCounter1.Visible = True
intScore = 1
End If
If intScore = 32 Then
lblCounter32.Visible = False
lblCounter1.Visible = True
intScore = 1
End If
If intScore = 33 Then
lblCounter33.Visible = False
lblCounter1.Visible = True
intScore = 1
End If
If intScore = 30 Then
MsgBox("Winner")
End If
If intScore > 30 Then
MsgBox("OvErBoArD")
End If
End Sub
End Class
Заметим, что 'vba' не то же самое, как' vb.net'. –
Вам нужно будет добавить какую-то проверку, когда вы добавите «бросок кубика» пользователя, чтобы увидеть «Если roll + intScore> 30» Затем «оставьте счетчик один», «Еще добавьте рулон в счетчик». – Chrismas007
Я новичок в этом, и мой учитель не вникает в объяснение, извините Bjorn –