下載/瀏覽Download

Download Report

Transcript 下載/瀏覽Download

題目:拉霸機
南台科技大學
機械系奈米一乙
學號:4A214089
老師:謝慶存
先下注但下注的金額不能超過現有的金幣,再拉下拉桿
之後拉霸機的
會出現亂
數,出來的結果依分數板給與金幣,如右
如果投注金額超過100則會出現訊息提醒玩家,以免賭太
大。
Pic1
Pic2
Pic3
PictureBox1
picBtn
Label1 lblSum
Label2
nudQty
Pic2
Pic3
Pic1
Pic0
Public Class Form1
宣告p(0)~p(3)的PictureBox陣列,可存放用來存放
0.jpg~3.jpg
' 其中p(0)不使用,p(1)~p(3)代表三個拉霸圖示
Dim p(3) As PictureBox
Dim num(3) As Integer
' 宣告num(0)~num(3)的整數陣列,用來存放0~3的數值
' 其中num(0)不使用
Dim t As Integer
宣告t用來計算Timer1共執行幾次
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
使表單無法被調整大小
Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
picBtn.Image = New Bitmap("up.jpg") '使picBtn顯示up.jpg
' 使載入的圖片隨picBtn大小伸縮
picBtn.SizeMode = PictureBoxSizeMode.StretchImage
p(1) = pic1 ' 將pic1指定給p(1)
p(2) = pic2 ' 將pic2指定給p(2)
p(3) = pic3 ' 將pic3指定給p(3)
使用迴圈使pic1~pic3顯示0.jpg圖
For i As Integer = 1 To p.GetUpperBound(0)
p(i).Image = Image.FromFile("0.jpg")
p(i).SizeMode = PictureBoxSizeMode.Zoom
Next
Timer1.Interval = 100 使Timer1計時器每0.1秒執行一次
lblSum.Text = 500
可投注的總數量lblSum為50
End Sub
Private Sub picBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles picBtn.Click
判斷 投注量nudQty.Value是否大於 0
且 投注量nudQty.Value是否大於可投注總數量lblSum.Text
If nudQty.Value > 0 And nudQty.Value <= lblSum.Text Then
Timer1.Enabled = True '計時器Timer1啟動
可投注量減掉本次的的投注題
lblSum.Text = Val(lblSum.Text) - nudQty.Value
nudQty.Enabled = False ' 無法投注
picBtn.Image = New Bitmap("down.jpg") 使picBtn顯示down.jpg
picBtn.Enabled = False ' picBtn圖片按鈕失效
Else 若投注量小於0且投注量大於可投注的總數量
MsgBox("有3投注嗎? ")
End If
If nudQty.Value < 100 And nudQty.Value <= lblSum.Text
Then
判斷 投注量nudQty.Value是否大於100
' 且 投注量
nudQty.Value是否大於可投注總數量lblSum.Text
Else
MsgBox("你賭家當嗎?")
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Timer1.Tick
Dim r As New Random '建立亂數物件r
' 使用迴圈讓pic1~pic3每次執行皆亂數的方式顯示0.jpg~3.jpg
For i As Integer = 1 To p.GetUpperBound(0)
num(i) = r.Next(0, 4) ' 產生 0~3 的亂數並指定給 n(1)~n(3)
' 使pic1~pic3以亂數的方式顯示 0.jpg~3.jpg
p(i).Image = Image.FromFile(num(i).ToString & ".jpg")
Next
t += 1
' 當計時器執行20次時,即馬上判斷是否中獎
If t = 20 Then
Timer1.Enabled = False ' 計時器Timer1停止
nudQty.Enabled = True ' 可以開始投注
picBtn.Enabled = True ' picBtn圖形按鈕可啟用
' 當num(1)=0且num(2)=0且num(3)=0表示pic1~pic3三個圖示皆是荔枝
If num(1) = 0 And num(2) = 0 And num(3) = 0 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 5)).ToString
MsgBox("中獎了! 投注量*5")
ElseIf num(1) = 1 And num(2) = 0 And num(3) = 0 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 3 And num(2) = 0 And num(3) = 0 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 0 And num(2) = 1 And num(3) = 0 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 0 And num(2) = 2 And num(3) = 0 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 0 And num(2) = 3 And num(3) = 0 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 0 And num(2) = 0 And num(3) = 1 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 0 And num(2) = 0 And num(3) = 2 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 0 And num(2) = 0 And num(3) = 3 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
' 當num(1)=1且num(2)=1且num(3)=1表示pic1~pic3三個圖示皆是星星
ElseIf num(1) = 1 And num(2) = 1 And num(3) = 1 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 10)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 0 And num(2) = 1 And num(3) = 1 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 2 And num(2) = 1 And num(3) = 1 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 3 And num(2) = 1 And num(3) = 1 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 1 And num(2) = 0 And num(3) = 1 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 1 And num(2) = 2 And num(3) = 1 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 1 And num(2) = 3 And num(3) = 1 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 1 And num(2) = 1 And num(3) = 0 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 1 And num(2) = 1 And num(3) = 2 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 1 And num(2) = 1 And num(3) = 3 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
' 當num(1)=2且num(2)=2且num(3)=2表示pic1~pic3三個圖示皆是西瓜
ElseIf num(1) = 2 And num(2) = 2 And num(3) = 2 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 15)).ToString
MsgBox("中獎了! 投注量*15")
ElseIf num(1) = 0 And num(2) = 2 And num(3) = 2 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 1 And num(2) = 2 And num(3) = 2 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 3 And num(2) = 2 And num(3) = 2 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 2 And num(2) = 2 And num(3) = 2 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 2 And num(2) = 0 And num(3) = 2 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 2 And num(2) = 1 And num(3) = 2 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 2 And num(2) = 3 And num(3) = 2 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 2 And num(2) = 2 And num(3) = 0 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 2 And num(2) = 2 And num(3) = 1 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 2 And num(2) = 2 And num(3) = 3 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
' 當num(1)=3且num(2)=3且num(3)=3表示pic1~pic3三個圖示皆是BAR
ElseIf num(1) = 3 And num(2) = 3 And num(3) = 3 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 20)).ToString
MsgBox("中獎了! 投注量*20")
ElseIf num(1) = 0 And num(2) = 3 And num(3) = 3 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 1 And num(2) = 3 And num(3) = 3 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 2 And num(2) = 3 And num(3) = 3 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 3 And num(2) = 0 And num(3) = 3 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 3 And num(2) = 1 And num(3) = 3 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 3 And num(2) = 2 And num(3) = 3 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 3 And num(2) = 3 And num(3) = 0 Then
lblSum.Text = (Val(lblSum.Text) + (nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 3 And num(2) = 3 And num(3) = 1 Then
lblSum.Text = (Val(lblSum.Text) +
(nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
ElseIf num(1) = 3 And num(2) = 3 And num(3) = 2
Then
lblSum.Text = (Val(lblSum.Text) +
(nudQty.Value * 2)).ToString
MsgBox("中獎了! 投注量*2")
End If
picBtn.Image = New Bitmap("up.jpg") '使picBtn顯
示up.jpg
t=0
End If
End Sub
End Class
我覺得Visual Basic容易上手且簡單,物件選
項有中文提示,不會讓人看不懂,方便了許
多,我本來看了許多密密麻麻的敘述碼,以
為會很難,但到後來不會這樣了,但是迴圈
還是很難。
Visual Basic 2010基礎必修課(林義証
張傑瑞 何瑞 著 碁峰資訊2010)