vb.net实现“快乐十分”

前端之家收集整理的这篇文章主要介绍了vb.net实现“快乐十分”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
今天在论坛上看到一个帖子内容如下:
vb.net高手指点一下

我想搞个“快乐十分”彩票的一种,就是1-21,每次随机产生5个数,可以21选2,21选3,21选4,21选5,比如21选2吧,就是你所选的两个数要是产生5个数中任意的两个,这样就是中奖了,否则不中,中一个数不算,算不中奖,嘿嘿,然后选3,选4,5都是这样,,大虾们,麻烦了

http://bbs.bccn.net/viewthread.php?tid=303774&page=1#pid1758429

上午花了时间 来写出来了。但是感觉写得太复杂了。没有一点逻辑的感觉。很多地方都需要修改。自己都有点看不过去的想法了。但降低标准,功能还是基本上实现了。

里面的判断条件自己写的太那。。。。。。,得修改修改才行呀。

在这里做个记录,方便以后进行修改学习。

Public Class Form1

Dim num As Integer
Dim result(4) As Integer

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) _
Handles RadioButton1.CheckedChanged,RadioButton2.CheckedChanged,RadioButton3.CheckedChanged,RadioButton4.CheckedChanged
Dim radio As RadioButton = sender
If radio.Name = "RadioButton1" Then
changeState(1)
ElseIf radio.Name = "RadioButton2" Then
changeState(2)
ElseIf radio.Name = "RadioButton3" Then
changeState(3)
ElseIf radio.Name = "RadioButton4" Then
changeState(4)
End If
GroupBox3.Visible = False
End Sub

Private Sub changeState(ByVal num As Int16)
If num = 1 Then
ComboBox3.Visible = False
ComboBox4.Visible = False
ComboBox5.Visible = False
ElseIf num = 2 Then
ComboBox3.Visible = True
ComboBox4.Visible = False
ComboBox5.Visible = False
ElseIf num = 3 Then
ComboBox3.Visible = True
ComboBox4.Visible = True
ComboBox5.Visible = False
ElseIf num = 4 Then
ComboBox3.Visible = True
ComboBox4.Visible = True
ComboBox5.Visible = True
End If
Me.num = num
End Sub


Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click '兑奖
checkvalue() '产生数字
'判断所选 数字是否有相同的。
Dim find As Boolean
find = False
Dim zjgs As Integer
zjgs = 0
Dim i As Integer
Select Case num
Case 1
If ComboBox1.Text = ComboBox2.Text Then
MsgBox("所选数字不能相同")
find = True
Else
'判断是否中奖
For i = 0 To 4
If Integer.Parse(ComboBox1.Text) = result(i) Or _
Integer.Parse(ComboBox2.Text) = result(i) Then
zjgs += 1
End If
Next
End If
Case 2
If ComboBox1.Text = ComboBox2.Text Or ComboBox1.Text = ComboBox3.Text Or ComboBox2.Text = ComboBox3.Text Then
MsgBox("所选数字不能相同")
find = True
Else
'判断是否中奖
For i = 0 To 4
If Integer.Parse(ComboBox1.Text) = result(i) Or _
Integer.Parse(ComboBox2.Text) = result(i) Or _
Integer.Parse(ComboBox3.Text) = result(i) Then
zjgs += 1
End If
Next
End If
Case 3
If ComboBox1.Text = ComboBox2.Text Or ComboBox1.Text = ComboBox3.Text Or ComboBox1.Text = ComboBox4.Text Or _
ComboBox2.Text = ComboBox3.Text Or ComboBox2.Text = ComboBox4.Text Or ComboBox3.Text = ComboBox4.Text Then
MsgBox("所选数字不能相同")
find = True
Else
'判断是否中奖
For i = 0 To 4
If Integer.Parse(ComboBox1.Text) = result(i) Or _
Integer.Parse(ComboBox2.Text) = result(i) Or _
Integer.Parse(ComboBox3.Text) = result(i) Or _
Integer.Parse(ComboBox4.Text) = result(i) Then
zjgs += 1
End If
Next
End If
Case 4
If ComboBox1.Text = ComboBox2.Text Or ComboBox1.Text = ComboBox3.Text Or ComboBox1.Text = ComboBox4.Text Or ComboBox1.Text = ComboBox5.Text Or _
ComboBox2.Text = ComboBox3.Text Or ComboBox2.Text = ComboBox4.Text Or ComboBox2.Text = ComboBox5.Text Or ComboBox3.Text = ComboBox4.Text Or _
ComboBox3.Text = ComboBox5.Text Or ComboBox5.Text = ComboBox4.Text Then
MsgBox("所选数字不能相同")
find = True
Else
'判断是否中奖
For i = 0 To 4
If Integer.Parse(ComboBox1.Text) = result(i) Or _
Integer.Parse(ComboBox2.Text) = result(i) Or _
Integer.Parse(ComboBox3.Text) = result(i) Or _
Integer.Parse(ComboBox4.Text) = result(i) Or _
Integer.Parse(ComboBox5.Text) = result(i) Then
zjgs += 1
End If
Next
End If
Case 0
MsgBox("请选择抽奖类型")
find = True
End Select
If find = False Then
GroupBox3.Visible = True
If zjgs = num + 1 Then
Label2.Text = "恭喜你,中将了"
Else
Label2.Text = "很失败,你还差一点就中奖了"
End If
End If

For i = 0 To 4
result(i) = 0
Next

End Sub

Private Sub checkvalue()
Label1.Text = ""

While Not ((result(0) <> result(1) And result(0) <> result(2) And result(0) <> result(3) And result(0) <> result(4) And _
result(1) <> result(2) And result(1) <> result(3) And result(1) <> result(4) And result(2) <> result(3) And _
result(2) <> result(4) And result(3) <> result(4)))
Dim generator As New Random()
result(0) = generator.Next(1,99999) Mod 21 + 1
result(1) = generator.Next(1,99999) Mod 21 + 1
result(2) = generator.Next(1,99999) Mod 21 + 1
result(3) = generator.Next(1,99999) Mod 21 + 1
result(4) = generator.Next(1,99999) Mod 21 + 1

End While
Label1.Text = "中奖号码是:" + result(0).ToString + "," + result(1).ToString + "," + result(2).ToString + "," + result(3).ToString + "," + result(4).ToString
End Sub


Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object,ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Process.Start("IExplore.exe","mailto:ouxianzhi520@163.com")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.Text = "1" ComboBox2.Text = "1" ComboBox3.Text = "1" ComboBox4.Text = "1" ComboBox5.Text = "1" GroupBox3.Visible = False End SubEnd Class

猜你在找的VB相关文章