誰會用microsoft visual studio 2005寫一ㄍ簡單ㄉ記憶遊戲ㄉ程式
並告訴我怎ㄇ寫阿謝啦各位大哥大姐
2006-12-19 10:36:48 · 1 個解答 · 發問者 ? 1 in 電腦與網際網路 ➔ 程式設計
' 猜配對的格子
' 猜對了就把字留下來
' 猜錯了就把字清除掉
' 螢幕上要有 10 x 10 Text1 的陣列 (從 0 到 99)
Dim prev_n As Integer, a(100) As Integer ' 整體性變數
Private Sub Form_Load()
Dim i As Integer, j As Integer, b As Integer
Dim n As Integer
' 兩個 1, 兩個 2, 兩個 3, ..., 兩個 50
n = 100
For i = 1 To n / 2
a(2 * i - 1) = i
a(2 * i) = i
Next i
' 重新洗牌
Randomize
For i = 1 To n
j = (Int(Rnd() * n) + 1)
b = a(i)
a(i) = a(j)
a(j) = b
Next i
prev_n = -1
End Sub
Private Sub Text1_Click(Index As Integer)
If (Text1(Index).Text <> "") Then Exit Sub ' 這一格猜過了
Text1(Index).Text = a(Index + 1) ' 秀出那一格的數字
If (prev_n = -1) Then ' 猜第一格
prev_n = Index ' 記錄第一格的位置
Else ' 猜第二格
If a(prev_n + 1) = Text1(Index).Text Then
MsgBox "你猜對了"
Else
MsgBox "你猜錯了"
Text1(Index).Text = "" ' 清除猜錯的格子
Text1(prev_n).Text = ""
End If
prev_n = -1 ' 變成還沒猜的情形
End If
End Sub
2006-12-23 08:12:47 · answer #1 · answered by JJ 7 · 0⤊ 0⤋