Public Class Form1
'these variables can be used anywhere in the form
Dim lblDice1, lblDice2, lblDice3, lblDice4, lblDice5 As New Label
Dim WithEvents butRoll As New Button
Dim nYatzee, nFourOfAKind, nThreeOfAKind As New Integer
Dim lblYatzee, lblFourOfAKind, lblThreeOfAKind As New TextBox
Dim rnd As New Random
Private Sub addDice(ByRef lbl As Label, ByVal x As Integer, ByVal y As Integer)
'working on the equation here, so we can call upon it when we need it in other parts of the form
lbl.Text = 0
lbl.Location = New Point(x, y)
lbl.Font = New Drawing.Font("Microsoft Sans Serif", 28.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)
lbl.Height = 40
lbl.Width = 40
End Sub
Private Sub AddCount(ByRef txt As TextBox, ByVal x As Integer, ByVal y As Integer, ByVal z As String)
'putting it in it's own sub so we can call upon it or change it without changing the entire form
txt.Text = z
txt.Location = New Point(x, y)
txt.Width = 150
End Sub
Private Sub BC(ByVal x As Integer, ByVal y As Integer, ByVal z As String)
'keeping it nice and organized
butRoll.Text = z
butRoll.Location = New Point(x, y)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'the place where all the other subs get put into
addDice(lblDice1, 10, 20)
addDice(lblDice2, 70, 20)
addDice(lblDice3, 130, 20)
addDice(lblDice4, 190, 20)
addDice(lblDice5, 250, 20)
AddCount(lblYatzee, 20, 140, "Yatzee: 0")
AddCount(lblFourOfAKind, 20, 180, "Four Of A Kind: 0")
AddCount(lblThreeOfAKind, 20, 220, "Three Of A Kind: 0")
BC(butRoll, 100, 90, "Roll")
Me.Controls.Add(lblDice1)
Me.Controls.Add(lblDice2)
Me.Controls.Add(lblDice3)
Me.Controls.Add(lblDice4)
Me.Controls.Add(lblDice5)
Me.Controls.Add(butRoll)
Me.Controls.Add(lblYatzee)
Me.Controls.Add(lblFourOfAKind)
Me.Controls.Add(lblThreeOfAKind)
End Sub
Private Sub RollDice() Handles butRoll.Click
'where all the magic happends
Dim arrNumbers() As Integer = {0, 0, 0, 0, 0, 0}
lblDice1.Text = rnd.Next(1, 7)
lblDice2.Text = rnd.Next(1, 7)
lblDice3.Text = rnd.Next(1, 7)
lblDice4.Text = rnd.Next(1, 7)
lblDice5.Text = rnd.Next(1, 7)
For Each lbl As Label In Me.Controls.OfType(Of Label)()
arrNumbers(lbl.Text - 1) += 1
Next
For Each i As Integer In arrNumbers
If i = 5 Then
nYatzee += 1
ElseIf i = 4 Then
nFourOfAKind += 1
ElseIf i = 3 Then
nThreeOfAKind += 1
End If
Next
lblYatzee.Text = "Yatzees: " & nYatzee
lblFourOfAKind.Text = "Four Of A Kind: " & nFourOfAKind
lblThreeOfAKind.Text = "Three Of A Kind: " & nThreeOfAKind
End Sub
Private Sub BC(ByVal button As Button, ByVal p2 As Integer, ByVal p3 As Integer, ByVal p4 As String)
Throw New NotImplementedException
End Sub
End Class
Fun
Monday, April 18, 2011
Yatzee!!!2.0
Labels:
vb.net
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment