Presentation is loading. Please wait.

Presentation is loading. Please wait.

記憶大考驗 機械工程系 四技車輛一甲 學號 :4A015081 老師 : 謝慶存 曾慶宇. + 選擇你要玩的等級就可以開始玩了.

Similar presentations


Presentation on theme: "記憶大考驗 機械工程系 四技車輛一甲 學號 :4A015081 老師 : 謝慶存 曾慶宇. + 選擇你要玩的等級就可以開始玩了."— Presentation transcript:

1 記憶大考驗 機械工程系 四技車輛一甲 學號 :4A015081 老師 : 謝慶存 曾慶宇

2 + 選擇你要玩的等級就可以開始玩了

3 + Public Class Form1 + Dim n(8) As Integer + Dim p(8) As PictureBox + Dim hitPicl, 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 + Sub SetRnd() + Dim ary() As Integer = {0, 1, 1, 2, 2, 3, 3, 4, 4} + Dim max As Integer = n.GetUpperBound(0) + Dim rndObj As New Random + Dim rndNum As Integer + For i As Integer = 1 To n.GetUpperBound(0) + rndNum = rndObj.Next(1, max + 1) + n(i) = ary(rndNum) : ary(rndNum) = ary(max) : max -= 1 + Next + End Sub +

4 + Private Sub Form1_Load(sender As Object, e As 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).SizeMode = PictureBoxSizeMode.StretchImage + p(i).BorderStyle = BorderStyle.Fixed3D + p(i).Enabled = False 'pic1~pic8 失效 + Next + End Sub

5 + 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 + hitPicl = CType(sender, PictureBox) + t1 = hitPicl.Tag.ToString + hitPicl.Image = New Bitmap(hitPicl.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 + hitPicl.Enabled = False + hitPic2.Enabled = False + tot += 1 + My.Computer.Audio.Play("CHIMES.WAV", AudioPlayMode.Background) + End If + If t1 <> t2 Then + MsgBox(" 答錯 ") + hitPicl.Image = New Bitmap("q.jpg") + hitPic2.Image = New Bitmap("q.jpg") + End If

6 + If tot = 4 Then + btn1.Enabled = True + btn2.Enabled = True + btn3.Enabled = True + Timer1.Enabled = False + Timer2.Enabled = False + If level = 2 Then + MsgBox(" 過關了 ") + ElseIf level = 5 Then + MsgBox(" 不錯喔 ") + ElseIf level = 10 Then + MsgBox(" 還好吧 ") + End If + My.Computer.Audio.Play("APPLAUSE.WAV", AudioPlayMode.Background) + End If + End Sub

7 + Private Sub GameStart() + My.Computer.Audio.Stop() + level = timer1Tot + btn1.Enabled = False + btn2.Enabled = False + btn3.Enabled = False + Timer1.Enabled = True + timer2Tot = 0 + t1 = "" + t2 = "" + tot = 0 + hitPicl = Nothing + hitPic2 = Nothing + lblShow.Text = " 你可以檢視的時間還有 " & timer1Tot & " 秒 " + lblTime.Text = "" + SetRnd() + For i = 1 To n.GetUpperBound(0) + p(i).Tag = n(i) + p(i).Image = New Bitmap(n(i) & ".jpg") + Next + End Sub

8 + Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click + timer1Tot = 2 + GameStart() + End Sub + Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click + timer1Tot = 5 + GameStart() + End Sub + Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click + timer1Tot = 10 + GameStart() + End Sub + Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick + timer1Tot -= 1 + lblShow.Text = " 你可以檢視的時間還有 " & timer1Tot & " 秒 " + 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 + End Sub +

9 + Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick + timer2Tot += 1 + lblTime.Text = " 遊戲時間 :" & timer2Tot & " 秒 " + If timer2Tot = 30 Then + Timer2.Enabled = False + btn1.Enabled = True + btn2.Enabled = True + btn3.Enabled = True + MsgBox(" 時間到 失敗 ") + lblShow.Text = " 請按 [ 開始 ] 鈕進行遊戲 " + 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

10 雖然以前就聽過程式語言,但這是第一次操 作這種 VB 程式語言,看似簡單, 但是難度還滿 高的,這學期的 VB 讓我受益良多 還有謝謝老 師


Download ppt "記憶大考驗 機械工程系 四技車輛一甲 學號 :4A015081 老師 : 謝慶存 曾慶宇. + 選擇你要玩的等級就可以開始玩了."

Similar presentations


Ads by Google