temp2

Public Class Form1

    Private Const NUM_SIDES = 6     Private roll As New Random()     Private cash As Integer = 100     Private betAmount As Integer = 10     Private rollCounter As Integer = 0     Private lostRound As Boolean = False     Private wonRound As Boolean = False     Private pointSet As Boolean = False     Private startTime As Date = Date.Now     Private point As Integer = 0

    Private Function SetImage(ByVal dieValue As Integer) As System.Drawing.Bitmap         Select Case dieValue             Case 1                 Return My.Resources.Resource1.dice1             Case 2                 Return My.Resources.Resource1.dice2             Case 3                 Return My.Resources.Resource1.dice3             Case 4                 Return My.Resources.Resource1.dice4             Case 5                 Return My.Resources.Resource1.dice5             Case 6                 Return My.Resources.Resource1.dice6         End Select     End Function

    Private Sub ScrollUp()         Dim ctr As Control = Me.ActiveControl         txtResults.Focus()         txtResults.AppendText("")         txtResults.ScrollToCaret()         ctr.Focus()     End Sub

    Public Sub refreshVariable()         lblPoint.Text = "Points: " & point         lblCash.Text = "Cash: $ " & cash         lblRoll.Text = "Rolls: " & rollCounter     End Sub

    Private Sub RollDice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRoll.Click         Dim roll1 As Integer         Dim roll2 As Integer         Dim rollSum As Integer

        'Visablility if statement for the points         If pointSet = False Then             lblPoint.Visible = True             'Else             '   lblPoint.Visible = True         End If

        'Sound bit for when a roll occures         Dim player As New Media.SoundPlayer(My.Resources.Resource1.dice_roll_sound)         player.Play()

        'Matches the rolled numbers with the image and get the roll total         roll1 = RollDie()         PictureBox1.Image = SetImage(roll1)         roll2 = RollDie()         PictureBox2.Image = SetImage(roll2)

                If cash <= 10 Then             If MessageBox.Show("Do you wish to play again?", _                 "Round over", _                 MessageBoxButtons.YesNo, MessageBoxIcon.Question) _                 = Windows.Forms.DialogResult.Yes Then

                'Refresh the varable                 rollCounter = 0                 cash = 100                 refreshVariable()                 Exit Sub

                'If you dont want to play again             Else                 MessageBox.Show("Game over! " & cash & "$ ")                 Application.Exit()

            End If         End If         rollSum = roll1 + roll2         rollCounter += 1

        If pointSet = False Then             If rollSum = 7 Or rollSum = 11 Then                 txtResults.Text += vbCrLf & "Rolled " & rollSum.ToString & ". You Win!"                 txtResults.Text += vbCrLf & "*************************"                 ScrollUp()                 cash += betAmount                 lblCash.Text = "Cash: $ " & cash                 point = 0                 pointSet = False                 rollCounter = 0

                If MessageBox.Show("Do you wish to play again?", _                     "Round over", _                     MessageBoxButtons.YesNo, MessageBoxIcon.Question) _                     = Windows.Forms.DialogResult.Yes Then                 Else                     MessageBox.Show("You finished with $ " & cash & "!")                     Application.Exit()                 End If

            ElseIf rollSum = 2 Or rollSum = 3 Or rollSum = 12 Then                 txtResults.Text += vbCrLf & "Rolled " & rollSum.ToString & ". Round Lost."                 ScrollUp()                 cash -= betAmount                 lblCash.Text = "Cash: $ " & cash                 point = 0                 pointSet = False                 rollCounter = 0

                If MessageBox.Show("Do you wish to play again?", _                     "Round over", _                     MessageBoxButtons.YesNo, MessageBoxIcon.Question) _                     = Windows.Forms.DialogResult.Yes Then                 Else                     MessageBox.Show("You finished with $ " & cash & "!")                     Application.Exit()                 End If

                'If the numbers are none of the above             Else                 txtResults.Text += vbCrLf & "Rolled " & rollSum.ToString & ". Point Established."                 ScrollUp()                 point = rollSum                 pointSet = True                 Exit Sub             End If         End If

        If pointSet = True Then             If rollSum = 7 Then                 txtResults.Text += vbCrLf & "Rolled " & rollSum.ToString & ". Round Lost."                 txtResults.Text += vbCrLf & "*************************"                 ScrollUp()                 cash -= betAmount                 lblCash.Text = "Cash: $ " & cash                 point = 0                 pointSet = False                 rollCounter = 0

                If MessageBox.Show("Do you wish to play again?", _                      "Round over", _                      MessageBoxButtons.YesNo, MessageBoxIcon.Question) _                     = Windows.Forms.DialogResult.Yes Then                 Else                     MessageBox.Show("You finished with $ " & cash & "!")                     Application.Exit()                 End If

            ElseIf rollSum = point Then                 txtResults.Text += vbCrLf & "Rolled " & rollSum.ToString & ". You Win!"                 txtResults.Text += vbCrLf & "*************************"                 ScrollUp()                 cash += betAmount                 lblCash.Text = "Cash: $ " & cash                 point = 0                 pointSet = False                 rollCounter = 0

                If MessageBox.Show("Do you wish to play again?", _                     "Round over", _                     MessageBoxButtons.YesNo, MessageBoxIcon.Question) _                     = Windows.Forms.DialogResult.Yes Then                 Else                     MessageBox.Show("You finished with $ " & cash & "!")                     Application.Exit()                 End If             Else

                txtResults.Text += vbCrLf & "Rolled " & rollSum.ToString & ". A Pass."                 ScrollUp()             End If         End If         Call refreshVariable()     End Sub

    Private Function RollDie() As Integer         Dim returnRoll As Integer         returnRoll = roll.Next(1, NUM_SIDES + 1)         Return returnRoll     End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load         Timer1.Start()

        lblRoll.Text = "Roll #: " & rollCounter

        lblPoint.Text = "Points: " & point

        lblCash.Text = "Cash: $ " & cash     End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick         Dim timePlayed As TimeSpan = Date.Now.Subtract(startTime)

        lblClock.Text = String.Format("{0}:{1:d2}:{2:d2}", _         timePlayed.Hours, _         timePlayed.Minutes, _         timePlayed.Seconds)     End Sub

    Private Sub btnCashOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCashOut.Click         MessageBox.Show("You finished with $ " & cash)         Application.Exit()     End Sub

    End Class

 

posted @ 2015-06-17 15:38  xymum  阅读(145)  评论(0编辑  收藏  举报