Visual Basic 語言撰寫程式設計遊戲專題 計算機程式及實習 遊戲主題:超級記憶王 班級: 車輛一乙 學號: 4A015076 姓名: 劉柏廷 指導老師: 謝慶存
接著開始倒數,時間到開始,依級別不同,有不同的倒數時間! 超級記憶王 先選擇挑戰級別後,開始遊戲,需選擇兩張一樣的圖片做配對 接著開始倒數,時間到開始,依級別不同,有不同的倒數時間!
程式表單設計 設計了三個按鈕、兩個文字標籤、8個圖片,以汽車品牌作為記憶的圖片!
遊戲程式碼 Public Class Form1 Dim n() As Integer = {0, 1, 2, 4, 3, 3, 1, 4, 2} Dim p(18) As PictureBox Dim hitPic1, hitPic2 As PictureBox Dim t1, t2 As String Dim isFirst As Boolean = True Dim timer1Tot As Integer Dim timer2Tot As Integer Dim level As Integer Dim tot As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink lblShow.Text = "請選擇級別進行遊戲" lblTime.Text = "" Timer1.Interval = 1000 Timer2.Interval = 1000
p(1) = pic1 p(2) = pic2 p(3) = pic3 p(4) = pic4 p(5) = pic5 p(6) = pic6 p(7) = pic7 p(8) = pic8 For i = 1 To n.GetUpperBound(0) p(i).Image = New Bitmap("q.jpg") p(i).Tag = n(i) p(i).SizeMode = PictureBoxSizeMode.StretchImage p(i).BorderStyle = BorderStyle.Fixed3D p(i).Enabled = False Next End Sub Private Sub pic1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic8.Click, pic7.Click, pic6.Click, pic5.Click, pic4.Click, pic3.Click, pic2.Click, pic1.Click If isFirst Then hitPic1 = CType(sender, PictureBox) t1 = hitPic1.Tag.ToString
hitPic1.Image = New Bitmap(hitPic1.Tag.ToString & ".jpg") isFirst = False Else hitPic2 = CType(sender, PictureBox) t2 = hitPic2.Tag.ToString hitPic2.Image = New Bitmap(hitPic2.Tag.ToString & ".jpg") isFirst = True If t1 = t2 Then hitPic1.Enabled = False hitPic2.Enabled = False tot += 1 End If If t1 <> t2 Then MsgBox("答ga錯u了F^_|||") hitPic1.Image = New Bitmap("q.jpg") hitPic2.Image = New Bitmap("q.jpg") If tot = 4 Then
btn1.Enabled = True btn2.Enabled = True btn3.Enabled = True Timer1.Enabled = False Timer2.Enabled = False If level = 2 Then MsgBox("過L關o了F...果G然gM是O記XO憶D高Xa手a") ElseIf level = 5 Then MsgBox("過L關o了F...你婢的o記XO憶D力O還U不£錯u") ElseIf level = 10 Then MsgBox("過L關o了F...你婢的o記XO憶D力O還U馬X‥馬X‥乎DG乎DG") End If End Sub
Private Sub GameStart() level = timer1Tot btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False Timer1.Enabled = True timer2Tot = 0 t1 = "" t2 = "" tot = 0 hitPic1 = Nothing hitPic2 = Nothing lblShow.Text = "你婢可Di以DH檢E視go的o時E間!還U有3 " & timer1Tot & "秒i" lblTime.Text = "" For i = 1 To n.GetUpperBound(0) p(i).Image = New Bitmap(n(i) & ".jpg") Next End Sub Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click timer1Tot = 1 GameStart()
Private Sub btn2_Click(ByVal sender As System Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click timer1Tot = 2 GameStart() End Sub Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click timer1Tot = 3 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick timer1Tot -= 1 lblshow.Text = "你婢可Di以DH檢E視go的o時E間!還U有3 " & timer1Tot & "秒i" If timer1Tot = 0 Then Timer1.Enabled = False lblshow.Text = "" Timer2.Enabled = True For i = 1 To n.GetUpperBound(0) p(i).Image = New Bitmap("q.jpg") p(i).Enabled = True Next End If
Private Sub Timer2_Tick(ByVal sender As System Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick timer2Tot += 1 If timer2Tot = 20 Then Timer2.Enabled = False btn1.Enabled = True btn2.Enabled = True btn3.Enabled = True MsgBox("時E間!到Li,A闖o關o失D¢敗粍") lblShow.Text = "請D選i擇U級鮮別屠進i行a遊C戲﹐" lbltime.Text = "" For i = 1 To n.GetUpperBound(0) p(i).Image = New Bitmap("q.jpg") p(i).Enabled = False Next End If End Sub End Class
心得 這次是最後一次繳交期末計算機程式及實習報告了,對於VB程式碼有一定的了解,但還是不是很能完整的運用,尤其是複雜的程式,但利用書籍、網路的搜尋,還是可以克服,希望以後我能任意設計出自己想要的程式,最後感謝老師每次上課都用心、幽默的在教學。