下載/瀏覽

Download Report

Transcript 下載/瀏覽

計算機程式及實習
期末報告之口頭報告ppt製作
題目:記憶配對
南台科技大學機械工程系
奈米四甲
姓名:黃信德
學號:4A014902
指導老師:謝慶存
題目說明:主題說明與背景
先點選難[難度]鈕,之後會進入檢視圖片時間依難度不同時間也不
同,接著再點選問號圖進行圖片配對,可配對時間為15秒。
依難度不同,完成配對的時候所顯示的對話框也會不同。
當配對時間到了卻還沒完成,也會出現對話框。
表單設計:解題分析
1.新增專案
表單設計:解題分析
2.介面設計
btn2
btn1
lblShow
btn3
lblTime
pic1
pic2
pic3
pic4
pic5
pic6
pic7
pic8
圖片檔
程式碼撰寫:語言程式之實作方法
Public Class Form1
Dim n(8) As Integer
Dim p(8) As PictureBox
Dim hitPic1, hitPic2 As PictureBox
Dim
Dim
Dim
Dim
Dim
Dim
t1, t2 As String
isFirst As Boolean = True
timer1Tot As Integer
timer2Tot As Integer
level As Integer
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
程式碼撰寫:語言程式之實作方法
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
Next
End Sub
程式碼撰寫:語言程式之實作方法
Private Sub pic1_Click(sender As Object, e As 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("錯了>_<")
hitPic1.Image = New Bitmap("q.jpg")
hitPic2.Image = New Bitmap("q.jpg")
End If
If tot = 4 Then
btn1.Enabled = True
btn2.Enabled = True
btn3.Enabled = True
Timer1.Enabled = False
Timer2.Enabled = False
If level = 1 Then
MsgBox("你作弊對吧?")
ElseIf level = 7 Then
MsgBox("馬馬虎虎啦~")
ElseIf level = 20 Then
MsgBox("沒過的話你可以砍掉重練了")
End If
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 = True
timer2Tot = 0
t1 = ""
t2 = ""
tot = 0
hitPic1 = 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
程式碼撰寫:語言程式之實作方法
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
timer1Tot = 1
GameStart()
End Sub
Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
timer1Tot = 7
GameStart()
End Sub
Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
timer1Tot = 20
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
程式碼撰寫:語言程式之實作方法
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
timer2Tot += 1
lblTime.Text = "遊戲時間:" & timer2Tot & " 秒"
If timer2Tot = 15 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
實際展示程式
選擇難度
開始遊戲
實際展示程式
完成配對
未完成配對
參考文獻
Visual Basic 2010基礎必修課 林義証、蔡文龍、
張傑瑞、何叡 著(碁峰資訊股份有限公司)