SOGO論壇
  登入   註冊   找回密碼
查看: 936|回覆: 2
列印 上一主題 下一主題

[程式設計] 如何計算msgbox出現的次數 [複製連結]

Rank: 2

狀態︰ 離線
跳轉到指定樓層
1
發表於 2009-5-6 22:35:00 |只看該作者 |倒序瀏覽
現在我想要讓小精靈在撞到牆3次就結速遊戲,要怎修改呢?麻煩知道的大哥教一下><
程式內容如下
Public Class form1
   Dim d As String
   Dim xx, yy, stp, j As Integer
   Dim mopen As Boolean
   Dim a(10) As PictureBox
   Dim aeat(10), apple(3) As Boolean
   Dim t1, t2 As Date

   Private Sub form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.forms.KeyEventArgs) Handles Me.KeyDown
       Select Case e.KeyCode
           Case Keys.Right
               d = "R"
           Case Keys.Down
               d = "D"
           Case Keys.Left
               d = "L"
           Case Keys.Up
               d = "U"
       End Select
       mopen = Not mopen
       wdir()
       wlocation()
       wimage()
       a_eat()
       gameover()

   End Sub

   Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       xx = 0 : yy = 0 : stp = 25
       t1 = Now
       mopen = False
       rapple()
       PictureBox1.Location = New Point(xx, yy)
   End Sub
   Private Sub wdir()
       Select Case d
           Case "R"
               If xx >= 420 Then xx = 420 = MsgBox("頭破血流")
           Case "D"
               If yy >= 400 Then yy = 400 = MsgBox("頭破血流")
           Case "L"
               If xx <= 20 Then xx = 20 = MsgBox("頭破血流")
           Case "U"
               If yy <= 20 Then yy = 20 = MsgBox("頭破血流")
       End Select
   End Sub
   Private Sub wlocation()
       Select Case d
           Case "R"
               xx = xx + stp
           Case "D"
               yy = yy + stp
           Case "L"
               xx = xx - stp
           Case "U"
               yy = yy - stp
       End Select
       PictureBox1.Location = New Point(xx, yy)
   End Sub
   Private Sub wimage()
       Select Case True
           Case d = "R" And mopen
               PictureBox1.Image = My.Resources.ghost_r_o
           Case d = "R" And Not mopen
               PictureBox1.Image = My.Resources.ghost_r_c
           Case d = "D" And mopen
               PictureBox1.Image = My.Resources.ghost_d_o
           Case d = "D" And Not mopen
               PictureBox1.Image = My.Resources.ghost_d_c
           Case d = "L" And mopen
               PictureBox1.Image = My.Resources.ghost_l_o
           Case d = "L" And Not mopen
               PictureBox1.Image = My.Resources.ghost_l_c
           Case d = "U" And mopen
               PictureBox1.Image = My.Resources.ghost_u_o
           Case d = "U" And Not mopen
               PictureBox1.Image = My.Resources.ghost_u_c
       End Select
   End Sub
   Private Sub rapple()
       For i = 1 To 10
           apple_location()
           a(i) = New PictureBox
           With a(i)
               .Image = My.Resources.apple1
               .Size = New Size(50, 50)
               .SizeMode = PictureBoxSizeMode.StretchImage
               .Visible = True
               .Location = New Point(xx, yy)
           End With
           Me.Controls.Add(a(i))
       Next
   End Sub
   Private Sub apple_location()
       Randomize()
       xx = Int(Rnd() * 400 / 50) * 50
       yy = Int(Rnd() * 400 / 50) * 50
   End Sub
   Private Sub a_eat()
       For i = 1 To 10
           If PictureBox1.Location = a(i).Location Then
               aeat(i) = True
               a(i).Visible = False
           End If
       Next
   End Sub
   Private Sub gameover()
       Dim cnt As Integer
       cnt = 0
       For i = 1 To 10
           If aeat(i) = True Then cnt = cnt + 1
       Next
       If cnt = 10 Then
           t2 = Now
           MsgBox("game over" & Chr(13) & "總計時間" & (t2 - t1).TotalSeconds & "秒")
       End If
   End Sub
   Private Sub gameover1()
       Dim cnt As Integer
       cnt = 0
       For i = 1 To 3
           If apple(i) = (xx And yy) Then cnt = cnt + 1
       Next
       If cnt = 3 Then
           t2 = Now
           MsgBox("game over" & Chr(13) & "總計時間" & (t2 - t1).TotalSeconds & "秒")
       End If
   End Sub
End Class
喜歡嗎?分享這篇文章給親朋好友︰
               感謝作者     

Rank: 5Rank: 5

狀態︰ 離線
2
發表於 2009-5-7 18:48:52 |只看該作者
沒有仔細看你的程式碼,不過概念大概如下:

增加一個變數負責記錄撞到幾次牆

每次開始遊戲的時候要記得歸零

如果撞到牆的時候此變數就加一

if ( 變數=3 ) then 結束遊戲

Rank: 2

狀態︰ 離線
3
發表於 2009-5-7 21:20:24 |只看該作者
感謝指導,我做出來了
雖然不是很完美
請注意︰利用多帳號發表自問自答的業配文置入性行銷廣告者,將直接禁訪或刪除帳號及全部文章!
您需要登錄後才可以回覆 登入 | 註冊


本論壇為非營利自由討論平台,所有個人言論不代表本站立場。文章內容如有涉及侵權,請通知管理人員,將立即刪除相關文章資料。侵權申訴或移除要求:abuse@oursogo.com

GMT+8, 2024-4-30 23:36

© 2004-2024 SOGO論壇 OURSOGO.COM
回頂部