Problem: In this lab, you will be using visual Studio to implement the classic g
ID: 3792543 • Letter: P
Question
Problem: In this lab, you will be using visual Studio to implement the classic game of Craps. Craps is a game of numbers and dice. The challenge is that when the user rolls the dice there are two sets of rules to follow depending on whether the roll is the users first roll to set the point/goal or it is one of potentially many rolls after the point/goal has been set. The rules are detailed below PART A The rules for the craps game are below. The Rules THERE ARE A FEW DIFFERENT VARIATIONS OF CRAPS N THIS VERSION, THE PLAYER ROLLS Two DICE AND THE SPOTS ON THE DICE ARE ADDED TOGETHER. THE PLAYER WINS ON THE FIRST ROLL. IF THE DICE SHOW A TOTAL OF 7 OR 11. THE PLAYER LOSESIF THE TOTAL IS 2, 3, OR 12. lF ANOTHER NUMBER IS THROWN ON THE FIRST ROLL FOR EXAMPLE, A 10-THAT NUMBER BECOMES THE POINT, OR THE GOAL. OF SUBSEQUENT TOSSES. THE PLAYER CONTINUES TO ROLLTHE DICE UNTIL THE POINT OR A 7 APPEARS. THROWING A TOTAL EQUAL TO THE POINT MEANS THE PLAYER wiNS AND THROWNGA 7 MEANS THE PLAYER LOSES. THIS IS THE VERSION OF CRAPS USUALLY PLAYED IN CASINOS.Explanation / Answer
Public Class Form1
Private Sub btnPlay_Click(sender As Object, e As EventArgs) Handles btnPlay.Click
Randomize()
Dim roll1 = CInt(Int((6 * Rnd()) + 1)) 'Random the dice
Select Case roll1
Case 1
picPlay1.Image = My.Resources.Image_1
lblroll1.Text = "1"
Case 2
picPlay1.Image = My.Resources.Image_2
lblroll1.Text = "2"
Case 3
picPlay1.Image = My.Resources.Image_3
lblroll1.Text = "3"
Case 4
picPlay1.Image = My.Resources.Image_4
lblroll1.Text = "4"
Case 5
picPlay1.Image = My.Resources.Image_5
lblroll1.Text = "5"
Case 6
picPlay1.Image = My.Resources.Image_6
lblroll1.Text = "6"
End Select
Dim roll2 = CInt(Int((6 * Rnd()) + 1)) 'Random the dice
Select Case roll2
Case 1
picPlay2.Image = My.Resources.Image_1
lblroll2.Text = "1"
Case 2
picPlay2.Image = My.Resources.Image_2
lblroll2.Text = "2"
Case 3
picPlay2.Image = My.Resources.Image_3
lblroll2.Text = "3"
Case 4
picPlay2.Image = My.Resources.Image_4
lblroll2.Text = "4"
Case 5
picPlay2.Image = My.Resources.Image_5
lblroll2.Text = "5"
Case 6
picPlay2.Image = My.Resources.Image_6
lblroll2.Text = "6"
End Select
Dim numbertotal = roll1 + roll2
Select Case numbertotal
Case 7, 11
statusBar.Text = "You WIN! Start Over!"
Case 2, 3, 12
statusBar.Text = "You LOSE!"
Case 4, 5, 6, 8, 9, 10
statusBar.Text = "Roll Again!"
btnRoll.Enabled = True
btnPlay.Enabled = False
picRoll1.Visible = True
picRoll2.Visible = True
Dim numbertotal2 As New Label 'To Display the current point
numbertotal2.Text = numbertotal.ToString
picRoll1.Image = picPlay1.Image
picRoll2.Image = picPlay2.Image
groupboxPoint.Text = "Point is" & Space(1) & numbertotal2.Text
End Select
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnRoll_Click(sender As Object, e As EventArgs) Handles btnRoll.Click
statusBar.Text = "" 'Clear tooltip
Randomize()
Dim roll3 = CInt(Int((6 * Rnd()) + 1)) 'Random the dice
Select Case roll3
Case 1
picPlay1.Image = My.Resources.Image_1
Case 2
picPlay1.Image = My.Resources.Image_2
Case 3
picPlay1.Image = My.Resources.Image_3
Case 4
picPlay1.Image = My.Resources.Image_4
Case 5
picPlay1.Image = My.Resources.Image_5
Case 6
picPlay1.Image = My.Resources.Image_6
End Select
Dim roll4 = CInt(Int((6 * Rnd()) + 1)) 'Random the dice
Select Case roll4
Case 1
picPlay2.Image = My.Resources.Image_1
Case 2
picPlay2.Image = My.Resources.Image_2
Case 3
picPlay2.Image = My.Resources.Image_3
Case 4
picPlay2.Image = My.Resources.Image_4
Case 5
picPlay2.Image = My.Resources.Image_5
Case 6
picPlay2.Image = My.Resources.Image_6
End Select
Dim dice1 As Integer
Dim dice2 As Integer
dice1 = CInt(lblroll1.Text) 'Convert the label text into integer
dice2 = CInt(lblroll2.Text)
Dim numbertotal = roll3 + roll4
Dim numbertotal2 = dice1 + dice2
Select Case numbertotal
Case 7
statusBar.Text = "YOU LOSE!"
Case numbertotal2
statusBar.Text = "Congratulation!"
If MessageBox.Show("Do you want to play again?", "Congratulation!", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Application.Restart()
End If
End Select
End Sub
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.