Transcript 下載/瀏覽
計算機程式及實習
題目:記憶大考驗
期末報告
南台科技大學
機械工程系
車輛一乙
4015015
張軒瑞
老師:謝慶存
記憶大考驗遊戲操作說明
• 按下級別按鈕選出兩個一樣的圖片全翻出
來顯示你贏了如果翻出一對不同的牌顯示
你翻錯了
說明圖
記憶遊戲圖片檔
1
2
3
4
q
記憶大考驗程式說明
•
•
•
•
•
•
•
•
•
•
•
Dim n() As Integer = {0, 1, 2, 4, 3, 3, 1, 4, 2}
Dim p(8) As PictureBox
Dim hitPic1, hitPic2 As PictureBox
Dim t1, t2 As String
Dim isFirst As Boolean = Dim timer1Tot As
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")
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
My.Computer.Audio.Play("CHIMES.WAV", AudioPlayMode.Background)
End If
If t1 <> t2 Then
MsgBox
hitPic1.Image = New Bitmap("q.jpg")
hitPic2.Image = New Bitmap("q.jpg")
End If
記憶大考驗程式說明
•
•
•
•
•
•
•
•
If tot = 4 Then
'btn1. btn2. btn3
btn1.Enabled = True
btn2.Enabled = True
btn3.Enabled = True
Timer1.Enabled = False 'Timer1
Timer2.Enabled = False 'Timer2i
If level = 2 Then
• ElseIf level = 5 Then
•
• ElseIf level = 10 Then
• MsgBox
• End If
My.Computer.Audio.Play("APPLAUSE.WAV", AudioPlayMode.Background)
• End If
• End If
• End Sub
記憶大考驗程式說明
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Private Sub GameStart()
My.Computer.Audio.Stop() μ
level = timer1Tot
btn1.Enabled = False
btn2.Enabled = False
btn3.Enabled = False
Timer1.Enabled = 1
timer2Tot = 0
t1 = “”
t2 = ""
tot = 0
hitPic1 = Nothing
hitPic2 = Nothing
lblShow.Text = “你可以檢視的時間" & 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 = 2
GameStart()
End Sub
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btn2.Click
timer1Tot = 5
GameStart()
End Sub
Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btn3.Click
timer1Tot = 10
GameStart()
End Sub
記憶大考驗程式說明
•
•
•
•
•
•
•
•
•
•
•
•
•
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
timer1Tot -= 1
lblShow.Text = “你還可以檢視的時間還有” & timer1Tot & “秒"
If timer1Tot = 0 Then
Timer1.Enabled = False
lblShow.Text = ""
Timer2.Enabled = True 'Timer2
For i = 1 To n.GetUpperBound(0)
p(i).Image = New Bitmap("q.jpg")
p(i).Enabled = True
Next
End If
End Sub
記憶大考驗程式說明
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer2.Tick
timer2Tot += 1
lblTime.Text = “遊戲時間" & timer2Tot & " 秒i"
If timer2Tot = 30 Then
Timer2.Enabled = False
btn1.Enabled = True
btn2.Enabled = True
btn3.Enabled = True
MsgBox(“時間到闖關失敗")
lblShow.Text = “請按開始紐進行遊戲”
Next
End If
End Sub
心得
• 當我寫完vb後有很多問題還好有很多人幫
我這個報告才能如期完成所以我還有很多
要學習的並且要多練習才能摸清處程式的
寫法還有我學到多多利用手邊的資源例如:
書所以這一次的報告讓我體會到有些事情
要靠朋友來幫忙地所以還要變得更強去幫
助他們才行
參考文獻
• Visual basic 2008基礎必修課
碁峰出版