1 / 11

南台科技大學 機械工程系 自控一甲 學號 :4A212049 老師 : 黃婉竺

計算機程式及實習 期末報告 ppt 製作 題目 : 打磚塊. 南台科技大學 機械工程系 自控一甲 學號 :4A212049 老師 : 黃婉竺. 開始介面. 這是一開始的遊戲介面,按 START 按鈕,開始進行遊戲。. 按此開始、暫停. 按此結束. 按此開始進行打磚塊遊戲. 遊戲執行介面. 用滑鼠操控,按住彈板不放,進行水平拖曳。. 程式碼設計. Public Class 打磚塊 ‘ 宣告 Vx 為馬莉歐一次移動的水平距離 Dim Vx As Single = 10 ‘ 宣告 Vy 為馬莉歐一次移動的垂直距離

Download Presentation

南台科技大學 機械工程系 自控一甲 學號 :4A212049 老師 : 黃婉竺

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 計算機程式及實習 期末報告ppt製作 題目:打磚塊 南台科技大學 機械工程系 自控一甲 學號:4A212049 老師:黃婉竺

  2. 開始介面 • 這是一開始的遊戲介面,按START按鈕,開始進行遊戲。 按此開始、暫停 按此結束 按此開始進行打磚塊遊戲

  3. 遊戲執行介面 • 用滑鼠操控,按住彈板不放,進行水平拖曳。

  4. 程式碼設計 Public Class 打磚塊 ‘ 宣告Vx為馬莉歐一次移動的水平距離 Dim Vx As Single = 10 ‘ 宣告Vy為馬莉歐一次移動的垂直距離 Dim Vy As Single = 10

  5. ‘ 用於重複呼叫產生畫面磚塊副程式 Sub Brick(ByVal X As Integer, ByVal Y As Integer) ‘ 宣告Q為一個新的LABEL物件 Dim Q As New Label ‘ 設定Q的相關參數 Q.Image = Image.FromFile("磚塊.jpg") With Q .Width = 100 .Height = 50 .BorderStyle = BorderStyle.FixedSingle .Left = X .Top = Y End With ‘ 將Q(磚塊)新增到畫面相對位置上 Me.Controls.Add(Q) End Sub

  6. ‘當每次計數器觸發時所需執行之動作副程式 Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick B.Left += Vx B.Top += Vy ‘當馬莉歐移動到邊界時改變移動方向 If B.Left < 0 Then Vx = Math.Abs(Vx) If B.Right > Me.ClientSize.Width Then Vx = -Math.Abs(Vx) If B.Top < 0 Then Vy = Math.Abs(Vy) Dim C As Single = (B.Left + B.Right) / 2 ‘當馬莉歐碰到擊球板時改變移動方向並發出音效 If B.Bottom > P.Top And C > P.Left And C < P.Right Then '擊球音效 My.Computer.Audio.Play(My.Resources.stomp, AudioPlayMode.Background) Vy = -Math.Abs(Vy) Dim F As Single = (C - P.Left) / P.Width If Vx < 0 Then F = 1 - F Vx = Vx * (F + 0.5) End If

  7. ‘當漏接時所做反應 If B.Top > Me.ClientSize.Height Then Timer1.Stop() '漏接音效 My.Computer.Audio.Play(My.Resources.mariodie, AudioPlayMode.Background) MsgBox("Game over!") START.Visible = True End If '檢查磚塊碰撞情況 For Each q In Me.Controls If TypeOf (q) Is Label Then If chkHit(q) Then '破磚音效 My.Computer.Audio.Play(My.Resources.kick, AudioPlayMode.Background) End If End If Next End Sub

  8. ‘遊戲開始初始化布置 Private Sub START_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles START.Click ‘隱藏開始按鈕 START.Visible = False ‘顯示馬莉歐 B.Visible = True ‘顯示反彈跳板 P.Visible = True ‘布置磚塊 For i As Integer = 0 To 9 For j As Integer = 0 To 9 Brick(100 * i, 50 * j) Next Next

  9. ‘設置畫面大小 Me.Width = (Me.Width - Me.ClientSize.Width) + 200 * 5 Me.Height = (Me.Height - Me.ClientSize.Height) + 100 * 5 + 150 ‘設置馬莉歐畫面位置 B.Top = 100 * 5 + 100 B.Left = (Me.ClientSize.Width - B.Width) / 2 ‘設置跳板畫面位置 P.Top = Me.ClientSize.Height - 25 P.Left = (Me.ClientSize.Width - P.Width) / 2 ‘開始計時 Timer1.Start() ‘設置遊戲進行中按鈕位置 Time.Top = 10 Time.Left = Me.ClientSize.Width - B.Width Play.Top = 10 Play.Left = Me.ClientSize.Width - B.Width End1.Top = 50 End1.Left = Me.ClientSize.Width - B.Width End Sub

  10. 心得 VB真的是不好學習,聽到要做期末報告而且還是用VB製作遊戲,簡直是一個頭兩個大阿,在網路上找了許多的範例還有如何製作,不過比我想像中難找,後來決定找班上同學幫忙,同學也很有心的教我,雖然我還是聽不太懂,過程中程式碼一直出問題,修改了好久,好不容易完成了打磚塊,看到成品真的好感動,真的很感謝同學耐心的教導。

  11. 參考文獻 1.Visual Basic 2010實力養成暨評量解題秘笈 桂思強 編 碁峰 2010 2.Visual Basic 2010教學範本古頤榛 編著 碁峰資訊2009 3.Visual Basic 6中文版教學手冊古頤榛 碁峰 2006 4.學會寫程式Visual Basic 2008( Idea 3小組 碁峰 2010 5.Visual Basic 2010 程式設計作者: 葉倍宏 全華2010 6.Visual Basic程式設計余忠潔 全華2010 7.Visual Basic 2005程式設計許華菁 普林斯頓2008 8.Visual Basic 2010基礎必修課

More Related