I having some trouble can you help. I need it in Visual Basic. I have allready c
ID: 3600291 • Letter: I
Question
I having some trouble can you help. I need it in Visual Basic. I have allready completed about 80% of my homework but the professor has just added more to it. The question I need answered is after what I have allready completed.. My question is on the bottom below the completed area. ( need in Visual Basic )
Completed:
Option Explicit On
Option Strict On
Option Infer Off
Public Class MainForm
' declare class-level variable
Private points As Integer = 10
Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub goalTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles goalTextBox.KeyPress
' accept only numbers and the Backspace Key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub rollButton_Click(sender As Object, e As EventArgs) Handles rollButton.Click
' simulates the Lucky Number Game
Dim randGen As New Random
Dim random1 As Integer
Dim random2 As Integer
'remove images
firstDiePictureBox.Image = Nothing
secondDiePictureBox.Image = Nothing
'disable Roll 'Em button
rollButton.Enabled = False
'refresh form and then delay execution
Me.Refresh()
System.Threading.Thread.Sleep(1000)
'generate two random integers from 1 through 6
random1 = randGen.Next(1, 7)
random2 = randGen.Next(1, 7)
'display appropriate image in firstDiePictureBox
Select Case random1
Case 1
firstDiePictureBox.Image = dot1PictureBox.Image
Case 2
firstDiePictureBox.Image = dot2PictureBox.Image
Case 3
firstDiePictureBox.Image = dot3PictureBox.Image
Case 4
firstDiePictureBox.Image = dot4PictureBox.Image
Case 5
firstDiePictureBox.Image = dot5PictureBox.Image
Case Else
firstDiePictureBox.Image = dot6PictureBox.Image
End Select
'display appropriate image in secondDiePictureBox
Select Case random2
Case 1
secondDiePictureBox.Image = dot1PictureBox.Image
Case 2
secondDiePictureBox.Image = dot2PictureBox.Image
Case 3
secondDiePictureBox.Image = dot3PictureBox.Image
Case 4
secondDiePictureBox.Image = dot4PictureBox.Image
Case 5
secondDiePictureBox.Image = dot5PictureBox.Image
Case Else
secondDiePictureBox.Image = dot6PictureBox.Image
End Select
'check sum of random numbers
If random1 + random2 = 7 Then
Dim count As Integer = 1
Do While count <= 10
numberLabel.Visible = Not numberLabel.Visible
Me.Refresh()
System.Threading.Thread.Sleep(200)
count += 1
Loop
points += 2
Else
points -= 1
If points = 0 Then
MessageBox.Show("Sorry, you lost all of your points!" &
"Click the Start Over button to try again.",
"Lucky Number Game", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
End If
' display points
pointsLabel.Text = points.ToString
' enable Roll ' Em button
rollButton.Enabled = True
End Sub
Private Sub startOverButton_Click(sender As Object, e As EventArgs) Handles startOverButton.Click
' start a new game
points = 10
pointsLabel.Text = points.ToString
firstDiePictureBox.Image = Nothing
secondDiePictureBox.Image = Nothing
End Sub
End Class
QUESTION :
You will create a modified version of a game called Drop Dead. Start with the Roll ‘Em example at the end of the chapter. You do not need to rename the solution and project.
Rules for our Drop Dead Game (2 person game):
1. Use a textbox on the form to determine the goal for the game. For example, the goal may be to earn 100 points. Use a KeyPress event for this textbox to restrict the data entry to digits, backspace, etc.
2. Player 1 takes a turn rolling 5 die (you will not need the 6th die from the Roll ‘Em chapter example)
Example: Bob rolls 5 die with these results: 4-6-3-1-4
3. If any of the 5 dice rolled includes a 6, Player 1 earns no points for that roll and Player 1’s turn ends. Otherwise, the score for Player 1 is the total of the face values on the die and Player 1 rolls again. This continues (rolling and adding points) until Player 1 rolls a 6.
Example: Bob points = 4+5+3+1+4 = 17
These points are added to Bob’s total and Bob rolls again.
HINT: A loop can be used to roll dice until 6 is rolled.
4. Player 2 follows the same rules.
5. The first player to reach the goal wins.
6. Display the winner of the game.
7. Allow the players to restart the game and play again.
In Visual Basic please
Explanation / Answer
Option Infer Off
Public Class MainForm
' declare class-level variable
Private points As Integer = 10
Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub goalTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles goalTextBox.KeyPress
' accept only numbers and the Backspace Key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub rollButton_Click(sender As Object, e As EventArgs) Handles rollButton.Click
' simulates the Lucky Number Game
Dim randGen As New Random
Dim random1 As Integer
Dim random2 As Integer
'remove images
firstDiePictureBox.Image = Nothing
secondDiePictureBox.Image = Nothing
'disable Roll 'Em button
rollButton.Enabled = False
'refresh form and then delay execution
Me.Refresh()
System.Threading.Thread.Sleep(1000)
'generate two random integers from 1 through 6
random1 = randGen.Next(1, 7)
random2 = randGen.Next(1, 7)
'display appropriate image in firstDiePictureBox
Select Case random1
Case 1
firstDiePictureBox.Image = dot1PictureBox.Image
Case 2
firstDiePictureBox.Image = dot2PictureBox.Image
Case 3
firstDiePictureBox.Image = dot3PictureBox.Image
Case 4
firstDiePictureBox.Image = dot4PictureBox.Image
Case 5
firstDiePictureBox.Image = dot5PictureBox.Image
Case Else
firstDiePictureBox.Image = dot6PictureBox.Image
End Select
'display appropriate image in secondDiePictureBox
Select Case random2
Case 1
secondDiePictureBox.Image = dot1PictureBox.Image
Case 2
secondDiePictureBox.Image = dot2PictureBox.Image
Case 3
secondDiePictureBox.Image = dot3PictureBox.Image
Case 4
secondDiePictureBox.Image = dot4PictureBox.Image
Case 5
secondDiePictureBox.Image = dot5PictureBox.Image
Case Else
secondDiePictureBox.Image = dot6PictureBox.Image
End Select
'check sum of random numbers
If random1 + random2 = 7 Then
Dim count As Integer = 1
Do While count <= 10
numberLabel.Visible = Not numberLabel.Visible
Me.Refresh()
System.Threading.Thread.Sleep(200)
count += 1
Loop
points += 2
Else
points -= 1
If points = 0 Then
MessageBox.Show("Sorry, you lost all of your points!" &
"Click the Start Over button to try again.",
"Lucky Number Game", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
End If
' display points
pointsLabel.Text = points.ToString
' enable Roll ' Em button
rollButton.Enabled = True
End Sub
Private Sub startOverButton_Click(sender As Object, e As EventArgs) Handles startOverButton.Click
' start a new game
points = 10
pointsLabel.Text = points.ToString
firstDiePictureBox.Image = Nothing
secondDiePictureBox.Image = Nothing
End Sub