乐透游戏(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/lotto-game-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 6 分钟阅读 - 2588 个词 阅读量 0乐透游戏(译文)
原文地址:https://www.codeproject.com/Articles/258737/Lotto-Game
原文作者:rspercy65
译文由本站 robot-v1.0 翻译
前言
Look, Buntt cake, nope, just another Lotto game with the tumbling animation.
瞧,邦德蛋糕,不,这只是另一个带有翻滚动画的乐透游戏.
介绍(Introduction)
你有抽奖的习惯吗?,如果这样,对我来说这是件好事.这是"乔治亚州超级百万彩票"的起飞.对于五个白球,它具有翻滚动画,对于大球,它具有相同的翻滚动画.它的(Do you have a lottery habit?, If so, that is good, for me. This is a take off of the “Georgia State Lottery Mega Millions”. It has tumbling animation for the five white balls and the same for the mega ball. It’s)自由(free)而且不会破坏你的钱包.它显示在(and won’t break your wallet. It displays, in a) DataGridView
,从年初至今的所有中奖号码.我想您可以使用它来查询最常调用的数字,从而在游戏中获得一点优势.(, all the winning numbers from the beginning of the year to date. I suppose you could use this to query the most called numbers for a slight advantage into the game.)
背景(Background)
我看过各种各样的彩票程序,但没有看过动画的翻滚,至少到目前为止还没有.我唯一看到的是一个VB 5示例,我确实使用和升级了用于VB5版本的类文件.我不知道作者是谁,因为示例是印刷的,比污垢大三天,但我仍然知道.(I’ve seen all sorts of lottery programs but none with tumbling animation, at least I haven’t so far. The only one I did see was a VB 5 example and I did use and upgrade the class file that was used for the VB5 version. I do not know who the author is as the example was printed and is three days older than dirt, but I still have it.)
动画(The Animation)
动画发生在两个不同的事件中.的(The animation takes place in two different events. The) tumbleTimer_Tick
事件与(event and the) pnlTumble_Paint
事件.我本来打算使用(event. I originally was going to use a) PictureBox
动画的控件,但受过教育,为什么不使用它,并指向动画的方向(control for the animation but was schooled in why not to use it and was pointed in the direction of the) Panel
控制.的(control. The) PictureBox
用于显示图像.这就对了.的(is for showing images. That is it. The) PictureBox
有我们不需要的额外行李.的代码(has extra baggage that we do not need. The code for the) tumbleTimer_Tick
和(and the) pnlTumble_Paint
事件非常简单,我们确实遵循" Windows事件驱动规则".(events are very straightforward and we do follow the “Windows Event Driven Rules”.)
Private Sub tumbleTimer_Tick(sender As Object, _
e As System.EventArgs) Handles tumbleTimer.Tick
_showGraphic = True
pnlTumble.Invalidate()
End Sub
我们只需设置一个(We simply set a) Boolean
至(to) True
和(and) Invalidate
的(the) Panel
我们正在使用的动画.的(that we are using for the animation. The) Paint
事件是动画的发源地.在 - 的里面(Event is where the meat of the animation takes place. Inside the) Panel
,我们绘制了一个包含圆和居中文本的矩形.我们这样做了56次.我们清除(, we draw a rectangle that holds the circle and the centered text. We do this 56 times. We clear the) Panel
通过将所有内容涂成黑色,处置图形,然后重新开始.(by painting everything black, dispose of the graphics, and start over again.)
Private Sub pnlTumble_Paint(sender As Object, _
e As System.Windows.Forms.PaintEventArgs) Handles pnlTumble.Paint
Dim i As Integer = 0
Dim xPos As Integer
Dim yPos As Integer
Dim rr As New Random
Dim rect As New Rectangle
For i = 1 To 56
xPos = rr.Next(1, 300)
yPos = rr.Next(1, 400)
rect.Height = 50
rect.Width = 50
rect.Location = New Point(xPos, yPos)
e.Graphics.FillEllipse(Brushes.White, rect.X, rect.Y, 50, 50)
Dim f As Font = New Font("Arial", 12, FontStyle.Bold)
Dim StringSize As SizeF = e.Graphics.MeasureString(i.ToString(), f)
e.Graphics.DrawString(i.ToString(), f, Brushes.Black, _
(rect.Left + 25) - (StringSize.Width / 2), _
(rect.Top + 25) - (StringSize.Height / 2))
Next
e.Graphics.Clear(Color.Black)
e.Graphics.Dispose()
End Sub
点击球(Clicking for a Ball)
当您单击以获取第一个球时,您会认为它是来自翻滚动画的,但实际上,该动画只是实际情况的一个立面(发音为" fsäd").在里面(*When you click to get the first ball, you would think that it is coming from the tumbling animation, but in all actuality, the animation is just a facade (pronounced "f·säd") for what is actually going on. In the*)
btnNextBall_Click事件中,我们首先获得所选球的当前计数;如果所有球都被抓住,那么我们重新开始,然后选择下一个唯一的乒乓球(*event, we first get the current count of selected balls; if all the balls are grabbed, then we start over, then we select the next unique ping-pong ball*)
GrabNext(PPBalls) ,然后我们做一些UI化妆品.(*, then we do some UI cosmetics.*)
GrabNext(PPBalls)在这里我们得到乒乓球的随机数.班级(*is where we get random numbers for our ping-pong balls. The class*)
clsRandom` 只有两个属性,三个子项和六个变量.属性是…(has just two properties, three subs, and six variables. The properties are…)
-
Random
-
Randomint
潜艇是…(The Subs are…) -
Shuffle(dX As Double)
-
Zap()
-
Stir(dX As Double)
变量是…(The variables are…) -
Const SIZE
-
MinInt Integer
-
MaxInt Integer
-
BJP(SIZE - 1) Double
-
RSP Integer
-
PJP Integer
的(The)Shuffle
子在(sub is called in the)Form_Load
调用(event which calls the)Zap
子和(sub and the)Stir
子的代码(sub. The code for the)btnNextBall_Click
事件与(event and the)GrabNext(ByVal Ary())
子跟随…(sub follows…)
Private Sub btnNextBall_Click(sender As Object, _
e As System.EventArgs) Handles btnNextBall.Click
If btnNextBall.Text = "Re-Start" Then
btnNextBall.Text = "Next Ball"
tumbleTimer.Start()
End If
Dim i As Integer
i = PPBalls(0)
If i = 5 Then
For i = 0 To 5
PPBalls(i) = 0
Next
Exit Sub
End If
GrabNext(PPBalls)
If PPBalls(0) = 5 Then
btnNextBall.Text = "Re-Start"
tumbleTimer.Stop()
pnlTumble.Hide()
pnlMegaTumbler.Show()
tumbleMegaTimer.Start()
btnNextBall.Location = New Point(593, 546)
btnNextBall.Enabled = False
btnNextBall.Visible = False
btnMegaBall.Location = New Point(594, 547)
btnMegaBall.Enabled = True
btnMegaBall.Visible = True
End If
End Sub
Private Sub GrabNext(ByVal Ary())
Dim i As Integer
Dim j As Integer = 0
Ary(0) = Ary(0) + 1
i = Ary(0)
Do
Ary(i) = r.Randomint
DisplayBall(Ary(i))
If i > 1 Then
For j = 1 To (i - 1)
If Ary(i) = Ary(j) Then
Ary(i) = 0
End If
Next
End If
Loop Until Ary(i)
End Sub
我本来要走偏路,并写一些有关" Windows事件驱动规则"的内容,但是在对该主题进行了一些搜索之后,我发现这本身就是另一篇文章.因此,我将坚持下面的" Windows事件驱动"子句.(I was going to get off track and write a little about “Windows Event Driven Rules” but after doing some searching on the subject, I found that this is another article in itself. So I’ll stick to the “Windows Event Driven” subs that follow.)
的(The) DisplayBall()
子是一个长期拖延(sub is a long-dragged-out) If
,(,) ElseIf
,(,) End If
声明.我们称(statement. We call the) Panel.Invalidate()
命令,依次调用(command, which in turn calls the) Panel.Paint
事件.这遵循Windows事件驱动规则.有关此主题的更多信息,可以在Wikipedia上找到,也可以通过Google搜索显示有关该主题的很多链接.(event. This follows the Windows Event Driven Rules. More on this subject can be found on Wikipedia or by doing a Google Search which displays quite a few links on the subject.)
Private Sub DisplayBall(ByVal ii As Integer)
myBall = Nothing 'Exception Prevention.
If ii = 1 Then
myBall = 1
_showGraphic = True
Me.pnl1.Invalidate()
ElseIf ii = 2 Then
myBall = 2
_showGraphic = True
Me.pnl2.Invalidate()
'Code Continues...
'...
'...
'...
ElseIf ii = 55 Then
myBall = 55
_showGraphic = True
Me.pnl55.Invalidate()
ElseIf ii = 56 Then
myBall = 56
_showGraphic = True
Me.pnl56.Invalidate()
End If
Private Sub pnl1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) _
Handles pnl1.Paint, pnl2.Paint, pnl3.Paint, pnl4.Paint, pnl5.Paint, _
pnl6.Paint, pnl7.Paint, pnl8.Paint, pnl9.Paint, _
pnl10.Paint, pnl11.Paint, pnl12.Paint, pnl13.Paint, _
pnl14.Paint, pnl15.Paint, pnl16.Paint, pnl17.Paint, _
pnl18.Paint, pnl19.Paint, pnl20.Paint, pnl21.Paint, _
pnl22.Paint, pnl23.Paint, pnl24.Paint, pnl25.Paint, _
pnl26.Paint, pnl27.Paint, pnl28.Paint, pnl29.Paint, _
pnl30.Paint, pnl31.Paint, pnl32.Paint, pnl33.Paint, _
pnl34.Paint, pnl35.Paint, pnl36.Paint, pnl37.Paint, _
pnl38.Paint, pnl39.Paint, pnl40.Paint, pnl41.Paint, _
pnl42.Paint, pnl43.Paint, pnl44.Paint, pnl45.Paint, _
pnl46.Paint, pnl47.Paint, pnl48.Paint, pnl49.Paint, _
pnl50.Paint, pnl51.Paint, pnl52.Paint, pnl53.Paint, _
pnl54.Paint, pnl55.Paint, pnl56.Paint
If _showGraphic Then
Dim rect As New Rectangle
rect.Height = 40
rect.Width = 40
rect.Location = New Point(0, 0)
e.Graphics.FillEllipse(Brushes.White, rect.X, rect.Y, 40, 40)
'Dim t As String = myBall.ToString()
Dim f As Font = New Font("Arial", 10, FontStyle.Bold)
Dim StringSize As SizeF = e.Graphics.MeasureString(myBall.ToString(), f)
e.Graphics.DrawString(myBall.ToString(), f, Brushes.Black, _
(rect.Left + 20) - (StringSize.Width / 2), _
(rect.Top + 20) - (StringSize.Height / 2))
e.Graphics.Dispose()
End If
End Sub
MegaBall潜水艇与上面显示的白球潜水艇几乎相同,只是较小的比例,因为我们只称一个球.(The MegaBall subs are pretty much the same as the white ball subs displayed above, except on a smaller scale as we are calling only one ball.) 如果本文中有什么听起来有些多余,可能是多余的,所以请不要像我已经知道的那样留言.(If there is anything in this article that sounds somewhat redundant, it probably is, so please do not leave a message stating this as I already know.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VB.NET VB .NET VS2010 Visual-Studio Dev 新闻 翻译