南台科技大學 機械工程系 自控一甲 學號:49912080 姓名:林亮宇 拉霸遊戲機 南台科技大學 機械工程系 自控一甲 學號:49912080 姓名:林亮宇
拉霸遊戲機 拉霸遊戲機與機率有關,而我所做的拉霸機是九個圖框的,設計過程跟三個的差不多, 只是在加以應用, 打打幾行程式而已。
系統功能說明 一.拉霸機遊戲規則: 1.在開始時,先設定投注量,投注量最多為100元,如果投注超過以100計。 2. 投注完後, 請按上方摩托車圖片(它是拉霸),然後拉霸機開始轉動,每個圖框裡都是亂數排定。
大約過數秒後,拉霸機停止轉動,程式會 判斷是否有中獎。 中獎條件如下: 中間橫列,只要圖片一樣,投注量得15倍。 重左上到右下(斜向),只要圖片一樣,投注量得10倍。 重右上到左下(斜向),只要圖片一樣,投注量得10倍。
中間橫列,只要出現兩張 或 或 ,投注量得5倍。 中間橫列,若出現兩張 或 ,投注量扣5倍。
二.系統分析 1.拉霸遊戲機需先設計一張背景圖當表單背景,在表單建立九個圖片方塊和一個拉霸摩托車圖片,然後再用一個標籤控制項來顯示投注總量和一個數字按鈕控制項來設定每次投注數。
2.拉霸機上面九個圖則是為了方便用迴圈來讀取圖片,將表單的九個圖片方塊設成控制項陣列,將圖檔變成檔名尾端含有連續數字檔。 之後再建立一個陣列為PictureBox圖片方塊陣列。
3. 使用計時器由圖片控制項中隨取圖片,所以當拉霸機啟動時,Timer1 計時器的 Tick 事件即開始計時,然後於指定時間內,挑出九張圖片。
將四張圖分別設定代碼: 0. 1. 2. 3. 4. 5.
輸入介面設計
開始時需先設定投注數金額,按拉霸(摩托車圖片)即開始遊戲。最高投注金額為100元。
未中獎時,必須由目前投注金額扣除總金額。
斜向中獎,投注金額得到10倍 依中獎規則指定倍數賠
不幸的!倒扣投注金額*-5
程式碼設計 Public Class Form1 ' 宣告p(0)~p(3)的PictureBox陣列,可存放用來存放0.jpg~9.jpg Dim p(9) As PictureBox ' 宣告num(0)~num(9)的整數陣列,用來存放0~39的數值 ' 其中num(0)不使用 Dim num(9) As Integer Dim t As Integer ' 宣告t用來計算Timer1共執行幾次 '表單載入時執行Form1_Load事件處理程序
Private Sub Form1_Load(ByVal sender As System Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' 使表單無法被調整大小 Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink pbB.Image = New Bitmap("up.jpg") '使pbB顯示up.jpg ' 使載入的圖片隨pbB大小伸縮 pbB.SizeMode = PictureBoxSizeMode.StretchImage p(1) = pb1 ' 將pb1指定給p(1) p(2) = pb2 ' 將pb2指定給p(2) p(3) = pb3 ' 將pb3指定給p(3) p(4) = pb4 ' 將pb4指定給p(4) p(5) = pb5 ' 將pb5指定給p(5)
p(6) = pb6 ' 將pb6指定給p(6) p(7) = pb7 ' 將pb7指定給p(7) p(8) = pb8 ' 將pb8指定給p(8) p(9) = pb9 ' 將pb9指定給p(9) ' 使用迴圈使pb1~pb9顯示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 = 200 ' 使Timer1計時器每0.2秒執行一次 lblsum.Text = 700 ' 可投注的總數量lblSum為700 End Sub
' 按下picBtn鈕時會執行picBtn_Click事件處理函式 Private Sub pbB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbB.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 ' 無法投注 pbB.Image = New Bitmap("down.jpg") ' 使pbB顯示down.jpg pbB.Enabled = False ' pbB圖片按鈕失效 Else '若投注量小於0且投注量大於可投注的總數量 MsgBox("投注錯誤") End If End Sub
' 當Timer1啟動時,每0.1秒皆會執行Timer1_Tick事件處理程序一次 Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim r As New Random '建立亂數物件r ' 使用迴圈讓pic1~pic9每次執行皆亂數的方式顯示1.jpg~5.jpg For i As Integer = 1 To p.GetUpperBound(0) num(i) = r.Next(1, 6) ' 產生 1~5 的亂數並指定給 n(1)~n(9) ' 使pic1~pic9以亂數的方式顯示 1.jpg~5.jpg p(i).Image = Image.FromFile(num(i).ToString & ".jpg") Next t += 1 ' 當計時器執行15次時,即馬上判斷是否中獎 If t = 15 Then Timer1.Enabled = False ' 計時器Timer1停止 nudQty.Enabled = True ' 可以開始投注 pbB.Enabled = True ' picBtn圖形按鈕可啟用 ' 當num(1)=1且num(2)=1且num(3)=1表示pb1~pb3三個圖示皆是趙雲 If num(4) = 1 And num(5) = 1 And num(6) = 1 Then lblsum.Text = (Val(lblsum.Text) + (nudQty.Value * 15)).ToString MsgBox("中獎! 投注數*15")
ElseIf num(4) = 2 And num(5) = 2 And num(6) = 2 Then ' 當num(1)=2且num(2)=2且num(3)=2表示pb1~pb3三個圖示皆是王元姬 ElseIf num(4) = 2 And num(5) = 2 And num(6) = 2 Then lblsum.Text = (Val(lblsum.Text) + (nudQty.Value * 15)).ToString MsgBox("中獎! 投注數*15") ' 當num(1)=3且num(2)=3且num(3)=3表示pb1~pb3三個圖示皆是夏侯淳 ElseIf num(4) = 3 And num(5) = 3 And num(6) = 3 Then ' 當num(1)=4且num(2)=4且num(3)=4表示pb1~pb3三個圖示皆是曹丕 ElseIf num(4) = 4 And num(5) = 4 And num(6) = 4 Then ' 當num(1)=5且num(2)=5且num(3)=5表示pb1~pb3三個圖示皆是陸遜 ElseIf num(4) = 5 And num(5) = 5 And num(6) = 5 Then
ElseIf num(1) = 1 And num(5) = 1 And num(9) = 1 Then lblsum.Text = (Val(lblsum.Text) + (nudQty.Value * 10)).ToString MsgBox("中獎! 投注數*10") ElseIf num(1) = 2 And num(5) = 2 And num(9) = 2 Then ElseIf num(1) = 3 And num(5) = 3 And num(9) = 3 Then ElseIf num(1) = 4 And num(5) = 4 And num(9) = 4 Then ElseIf num(1) = 5 And num(5) = 5 And num(9) = 5 Then
ElseIf num(3) = 1 And num(5) = 1 And num(7) = 1 Then lblsum.Text = (Val(lblsum.Text) + (nudQty.Value * 10)).ToString MsgBox("中獎! 投注數*10") ElseIf num(3) = 2 And num(5) = 2 And num(7) = 2 Then ElseIf num(3) = 3 And num(5) = 3 And num(7) = 3 Then ElseIf num(3) = 4 And num(5) = 4 And num(7) = 4 Then ElseIf num(3) = 5 And num(5) = 5 And num(7) = 5 Then
ElseIf num(4) = 1 And num(5) = 2 And num(6) = 1 Then lblsum.Text = (Val(lblsum.Text) + (nudQty.Value * 5)).ToString MsgBox("中獎! 投注數*5") ElseIf num(4) = 1 And num(5) = 3 And num(6) = 1 Then ElseIf num(4) = 1 And num(5) = 4 And num(6) = 1 Then ElseIf num(4) = 1 And num(5) = 5 And num(6) = 1 Then ElseIf num(4) = 2 And num(5) = 1 And num(6) = 2 Then lblsum.Text = (Val(lblsum.Text) + (nudQty.Value * -5)).ToString MsgBox("不幸的! 倒扣投注數*5") ElseIf num(4) = 2 And num(5) = 3 And num(6) = 2 Then ElseIf num(4) = 2 And num(5) = 4 And num(6) = 2 Then ElseIf num(4) = 2 And num(5) = 5 And num(6) = 2 Then
ElseIf num(4) = 3 And num(5) = 1 And num(6) = 3 Then lblsum.Text = (Val(lblsum.Text) + (nudQty.Value * 5)).ToString MsgBox("中獎! 投注數*5") ElseIf num(4) = 3 And num(5) = 2 And num(6) = 3 Then ElseIf num(4) = 3 And num(5) = 4 And num(6) = 3 Then ElseIf num(4) = 3 And num(5) = 5 And num(6) = 3 Then ElseIf num(4) = 4 And num(5) = 1 And num(6) = 4 Then lblsum.Text = (Val(lblsum.Text) + (nudQty.Value * -5)).ToString MsgBox("不幸的! 倒扣投注數*5") ElseIf num(4) = 4 And num(5) = 2 And num(6) = 4 Then ElseIf num(4) = 4 And num(5) = 3 And num(6) = 4 Then ElseIf num(4) = 4 And num(5) = 5 And num(6) = 4 Then
ElseIf num(4) = 5 And num(5) = 1 And num(6) = 5 Then lblsum.Text = (Val(lblsum.Text) + (nudQty.Value * 5)).ToString MsgBox("中獎! 投注數*5") ElseIf num(4) = 5 And num(5) = 2 And num(6) = 5 Then ElseIf num(4) = 5 And num(5) = 3 And num(6) = 5 Then ElseIf num(4) = 5 And num(5) = 4 And num(6) = 5 Then End If pbB.Image = New Bitmap("up.jpg") '使pbB顯示up.jpg t = 0 End Sub End Class
參考資料 99-期末報告ppt製作-2-拉霸遊戲機
心得感想 坦白講,遊戲好玩是好玩,但要設計出一款好玩的遊戲真的很不容易,就算有參考範例來做這個拉霸機也真的很不容易,由其是那倍率的安排還有中獎的安排真的有點麻煩,可想而知如果再好玩一點的遊戲,設計起來就更加複雜與困難,當然做完之後自己在那玩,也挺有榮譽感的。玩遊戲簡單,作遊戲難呀﹗