當前位置:首頁 » 游戲資訊 » 怎麼下vb游戲

怎麼下vb游戲

發布時間: 2023-07-16 05:35:38

Ⅰ VB編寫小游戲的全過程誰告訴我

開始學vb時,並不知道vb可以做出動畫,後來知道通過自編的子函數delay(c的庫函數中的該函數)和cls可以做出許多動畫,但有一個缺點就是太耗內存,就我個人認為構思應該比編程重要,因為一旦有了一個很好的構思剩下的問題都是技術問題,而我就是喜歡發現新的問題然後再想方設法解決它,通過發現問題和解決問題我可以學到許多很有用的知識和技巧。好了,現在有了一個好的構思就開始進入程序的編制。

第一步,要做成這個游戲的話必須能使小球有一個判斷性的運動,然而如何處理小球的運動呢,很顯然delay&cls的方法不再適用,因為整個程序運行時不停的清屏效果將很差,所以我想到了用shape控制項來替代用circle命令畫的小球,接著要使小球運動起來,這個問題很簡單,因為 shape控制項有left和top的屬性,可以通過對這兩個屬性的控制可以很輕松的解決小球運動問題。

第二步,將對小球進行角度控制,角度可以通過shape的屬性left和top來反映,通過timer控制項使小球的left和top值不斷加上一個值或減去一個值,小球的left和top同時改變之後就可以對小球的角度進行控制。到這里已經可以使小球運動起來,接下來的問題就是使小球能進行判斷性運動。

第三步,可以這樣對小球進行判斷性控制,當小球的left大於窗體的scaleleft時小球的left改變成減去一個值,以此類推,小球的高度也可以進行類似的控制,現在已經很方便的對小球進行判斷性運動,到這一步程序已經算是完成了一半。

第四步,既然小球可以自由的運動了,那就可以產生這樣一個想法,當小球的top和left的磚塊的top和left值接近到一定的范圍的條件成立時使磚塊的visible為false,然後小球的top和left加上接觸前相應相反的值,就可以使磚塊消失同時小球改變運動軌跡,這一步的實現需要解決很多技術性問題,可以在form的load事件里定義兩個變數Dwd和Dhd以及兩個Boolean量為Dw和Dh,通過Dwd和Dhd來控制小球向左和向上運動,當小球和窗體的邊界或和磚塊的的邊界接觸時使Dw和Dh的值進行相應的變化,通過對該兩個值的控制可以使小球進行合乎反彈角度的運動,現在程序已經初步成型。

第五步,要做成這樣的一個游戲,必須有一個良好的用戶界面,為了使小球能接受用戶的控制,我在窗體的下邊界放置了一個命令按鈕,該命令按鈕可以通過方向鍵來控制,然後再加上一些判斷語句使得小球command接觸時產生相應的運動,這樣一個用戶界面就解決了。

第六步,現在只剩下程序的最後一步,就是生成磚塊的排列,磚塊可以用命令按鈕來替代,然後用循環語句將設置好的command控制項數組在程序運行時載入進來,好了,現在已經一切完成.

Ⅱ 如何設計一個很簡單的VB程序小游戲

利用vb控制項做個坦克大戰類的游戲即可,炮彈和坦克都用控制項實現就行。唯一難點是控制控制項移動以及炮彈擊中目標的碰撞檢測判斷。給你一個簡單實現代碼
這是一種碰撞檢測方法,下述屬於簡化的矩形碰撞檢測,若是需要復雜碰撞可以用一個數組來記錄大量需要碰撞檢測的物體
image1里讀念則謹入坦克的圖片
image2里讀入地雷的圖片
然後用下面代碼即可實現
Private
Sub
Form_KeyPress(KeyAscii
As
Integer)
'按鍵盤A和D鍵控制貓圖片image1左盯喚右移動
If
KeyAscii
=
97
Then
Image1.Left
=
Image1.Left
-
10
If
KeyAscii
=
100
Then
Image1.Left
=
Image1.Left
+
10
'如果坦克圖片與地雷圖片相遇則提示碰撞到了
If
Image1.Left
+
Image1.Width
>
Image2.Left
Then
If
Image1.Left
<
Image2.Left
+
Image2.Width
Then
If
Image1.Top
+
Image1.Height
>
Image2.Top
Then
If
Image1.Top
<
Image2.Top
+
Image2.Height
Then
MsgBox
"坦克碰到地雷,已經被炸毀了"仔基
End
If
End
If
End
If
End
If
End
Sub

Ⅲ 求VB小游戲,簡單一點,越簡單越好

數字排序小游戲

Option Explicit

Dim Label2X As Integer '記錄標簽控制項數組中要移動的標簽控制項左上角X的位置
Dim Label2Y As Integer '記錄標簽控制項數組中要移動的標簽控制項左上角Y的位置

'讓標簽數組中的每個標簽控制項上顯示的數字是隨機的,無重復的
Private Sub Init()
Randomize
Dim a(7) As Integer
Dim i As Integer, k As Integer

Label1.Caption = ""

For i = 0 To 7
a(i) = i
Next

For i = 0 To 7

k = Int(Rnd * 8)

Do While a(k) = -1 'a(k)=-1表示該數組元素對應的數字已經被使用過了
k = Int(Rnd * 8) '重新生成k的值,直到a(k)的值不等於-1
Loop

Label2(i).Caption = Trim(Str(a(k)))
a(k) = -1 'a(k)的值已經使用了,不能再用,重新賦值為-1與其他的元素值相區別

Next i
End Sub

Private Sub Command1_Click()
Dim x As Integer, y As Integer
Dim z As Integer

Init
Picture1.Enabled = True

'讓空白標簽Label1出現的位置隨機
Randomize
'記錄下空白標簽Label1的位置
x = Label1.Left
y = Label1.Top
z = Int(Rnd * 8)

'將空白標簽Label1和標簽控制項數組任一控制項交換位置
Label1.Move Label2(z).Left, Label2(z).Top
Label2(z).Move x, y

Command1.Enabled = False

End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
Dim i As Integer
Picture1.Enabled = False

'在標簽中顯示游戲說明信息
Label3.Caption = "如左圖所示,將數字按0-7順" & vbCrLf & vbCrLf & "序依次排列,即取得勝利。"

'在標簽中顯示排列規則後的數字順序
Label1.Caption = 0
For i = 0 To 6
Label2(i).Caption = i + 1
Next
End Sub

Private Sub Label1_DragDrop(Source As Control, x As Single, y As Single)

Dim Label1X As Integer '記錄空白控制項Label1左上角X的位置
Dim Label1Y As Integer '記錄空白控制項Label1左上角Y的位置

Dim flag(3) As Boolean

'獲取空白控制項Label1的位置
Label1X = Label1.Left
Label1Y = Label1.Top

'要移動的控制項位於空白控制項Label1的正左側
flag(0) = (Label2X = Label1X - Source.Width) And (Label2Y = Label1Y)

'要移動的控制項位於空白控制項Label1的正右側
flag(1) = (Label2X = Label1X + Source.Width) And (Label2Y = Label1Y)

'要移動的控制項位於空白控制項Label1的正上方
flag(2) = (Label2X = Label1X) And (Label2Y = Label1Y - Source.Height)

'要移動的控制項位於空白控制項Label1的正下方
flag(3) = (Label2X = Label1X) And (Label2Y = Label1Y + Source.Height)

If flag(0) Or flag(1) Or flag(2) Or flag(3) Then
Label1.Move Label2X, Label2Y
Source.Move Label1X, Label1Y
End If

Win
End Sub

Private Sub Label2_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then '如果按下滑鼠左鍵

'記錄下要拖動控制項的位置
Label2X = Label2(Index).Left
Label2Y = Label2(Index).Top

Label2(Index).Drag 1 '啟動拖動操作
End If
End Sub

Private Sub Label2_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
Label2(Index).Drag 2 '結束拖動操作
End Sub

Private Sub Win()
Dim winner As Integer
Dim i As Integer
Dim answer As Integer
'對於給定的標簽控制項數組中的任一標簽控制項,可以落在符合要求(對應位置應顯示對應數字)
'的八個位置中的任一位置
'利用循環語句對標簽控制項數組中的每個標簽控制項進行檢查,如果其落在某一符號要求的位置,
'則變數winner的值加1,如果所有標簽控制項都落在符號要求的位置,則變數winner的值應為8

For i = 0 To 7
If Label2(i).Left = 0 And Label2(i).Top = 0 And _
Label2(i).Caption = 0 Then
winner = winner + 1
ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = 0 And _
Label2(i).Caption = 1 Then
winner = winner + 1
ElseIf Label2(i).Left = 2 * Label2(i).Width And Label2(i).Top = 0 And _
Label2(i).Caption = 2 Then
winner = winner + 1
ElseIf Label2(i).Left = 0 And Label2(i).Top = Label2(i).Height And _
Label2(i).Caption = 3 Then
winner = winner + 1
ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = Label2(i).Height And _
Label2(i).Caption = 4 Then
winner = winner + 1
ElseIf Label2(i).Left = 2 * Label2(i).Width And Label2(i).Top = Label2(i).Height And _
Label2(i).Caption = 5 Then
winner = winner + 1
ElseIf Label2(i).Left = 0 And Label2(i).Top = 2 * Label2(i).Height And _
Label2(i).Caption = 6 Then
winner = winner + 1
ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = 2 * Label2(i).Height And _
Label2(i).Caption = 7 Then
winner = winner + 1
End If
Next i

If winner = 8 Then
MsgBox " 恭喜您,勝利了!", 0 + 64 + 0, "提示"
Picture1.Enabled = False

answer = MsgBox("還繼續嗎?", 4 + 32 + 0, "提示")
If answer = vbYes Then
Command1.Enabled = True
Else
End
End If
End If
End Sub

彈球游戲

Dim x_step As Integer
Dim y_step As Integer

Private Sub command1_Click()
If Timer1.Enabled = True Then
Timer1.Enabled = False
Else
Timer1.Enabled = True
End If

If command1.Caption = "暫停" Then
command1.Caption = "繼續"
Else
command1.Caption = "暫停"
End If

End Sub

Private Sub Form_Load()
x_step = 200
y_step = 200

End Sub

Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = 37 Then

If Line1.X1 < 0 Then

Line1.X1 = 0: Line1.X2 = 2000
Else

Line1.X1 = Line1.X1 - 100: Line1.X2 = Line1.X2 - 100
End If
End If

If KeyCode = 39 Then
If Line1.X1 > Picture1.Width Then
Line1.X1 = Picture1.Width - 2000: line2.X2 = Picture.Width
Else
Line1.X1 = Line1.X1 + 100: Line1.X2 = Line1.X2 + 100
End If
End If

End Sub

Private Sub Timer1_Timer()
If Shape1.Top < 0 Then
Shape1.Top = 0: y_step = -y_step
End If

If Shape1.Left < 0 Then
Shape1.Left = 0
x_step = -x_step
End If

If Shape1.Left > Picture1.Width - Shape1.Width Then
Shape1.Left = Picture1.Width - Shape1.Width
x_step = -x_step
End If

If Shape1.Left >= Line1.X1 And Shape1.Left <= Line1.X2 And Shape1.Top >= Line1.Y1 - Shape1.Height Then
Shape1.Top = Line1.Y1 - Shape1.Height
y_step = -y_step * 1.01
x_step = x_step * 1.01
Label2.Caption = Label2.Caption + 1

End If
Shape1.Top = Shape1.Top + y_step

Shape1.Left = Shape1.Left + x_step

If Shape1.Top >= Picture1.Height - Shape1.Height Then

MsgBox "游戲結束"
command1.Caption = "開始"
Timer1.Enabled = False
Shape1.Top = 1000
Label2.Caption = 0

End If

End Sub
打字游戲

Dim score As Integer
Dim speed As Integer
Dim typetime As Integer

Private Sub init()
Randomize

lblletter1.Caption = Chr(Int(Rnd * 42) + 48)
lblletter1.Left = Int(Rnd * 2800) + 1
lblletter1.Top = 0

End Sub

Private Sub init1()
Randomize
lblletter2.Caption = Chr(Int(Rnd * 25) + 97)
lblletter2.Left = Int(Rnd * 2800) + 1
lblletter2.Top = 0

End Sub

Private Sub Command1_Click()
score = Int(lblscore.Text)
init
init1
Timer1 = True
Timer2 = True
HScroll1.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
HScroll1.Enabled = False

If lbltime.Text <= 0 Then
Timer1 = False
Timer2 = False
lblletter1.Caption = ""
lblletter2.Caption = ""
End If

End Sub

Private Sub Command2_Click()
typetime = InputBox("請輸入打字時間。", "時間設置")
If typetime <= 0 Then
lbltime.Text = 60
End If
lbltime.Text = typetime
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = lblletter1.Caption Then

score = score + 1
lblscore.Text = score
init
End If
If Chr(KeyAscii) = lblletter2.Caption Then
score = score + 1
lblscore.Text = score
init1
End If
End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
lblletter1.AutoSize = True
lblletter2.AutoSize = True
lblletter1.Caption = ""
lblletter2.Caption = ""
lblscore.Text = 0
lblspeed.Caption = 100
lbltime.Text = 60
HScroll1.Max = 200
HScroll1.Min = 20
HScroll1.SmallChange = 5
HScroll1.LargeChange = 20
HScroll1.Value = 100
End Sub

Private Sub HScroll1_Change()
lblspeed.Caption = HScroll1.Value
End Sub

Private Sub Timer1_Timer()
lblletter1.Top = lblletter1.Top + lblspeed.Caption
If lblletter1.Top >= 4335 Then
Call init
End If
lblletter2.Top = lblletter2.Top + lblspeed.Caption
If lblletter2.Top >= 4335 Then
Call init1
End If
End Sub

Private Sub Timer2_Timer()
If lbltime.Text > 0 Then
lbltime.Text = lbltime.Text - 1

Else: Select Case score / (typetime / 60)
Case Is <= 40
MsgBox ("不要放棄再試一次!")
Case 40 To 80
MsgBox ("太棒了,繼續努力!")
Case 80 To 120
MsgBox ("堅持下去,你將成為一個打字高手!")
Case Is > 120
MsgBox ("祝賀你!你已經是一個打字高手!")
End Select
Timer1 = False
Timer2 = False
HScroll1.Enabled = True
Command1.Enabled = True
Command2.Enabled = True
HScroll1.Enabled = True
init
init1
End If

End Sub

點燈游戲

Private Sub Form_Load()
Form1.Scale (0, 12)-(12, 0)
For i = 1 To 11
Line (1, i)-(11, i)
Line (i, 1)-(i, 11)
Next i

End Sub
Sub fill_color(X, Y)
If Point(X, Y) = vbWhite Then
Line (Int(X), Int(Y))-(Int(X + 1), Int(Y + 1)), vbBlack, BF
Else
Line (Int(X), Int(Y))-(Int(X + 1), Int(Y + 1)), vbWhite, BF
End If
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If X >= 1 And X <= 11 And Y >= 1 And Y <= 11 Then

Call fill_color(X, Y)
If X >= 1 And X <= 11 And Y + 1 >= 1 And Y + 1 <= 11 Then
Call fill_color(X, Y + 1)
End If
If X >= 1 And X <= 11 And Y - 1 >= 1 And Y - 1 <= 11 Then
Call fill_color(X, Y - 1)
End If
If X + 1 >= 1 And X + 1 <= 11 And Y >= 1 And Y <= 11 Then
Call fill_color(X + 1, Y)
End If
If X - 1 >= 1 And X - 1 <= 11 And Y >= 1 And Y <= 11 Then
Call fill_color(X - 1, Y)
End If
End If
Call Form_Load
End Sub
猜數字
Dim number As Integer

Private Sub Command1_Click()
Dim guess As Integer, diff As Integer
guess = Val(Text1.Text)
If guess = -1 Then
MsgBox ("要猜的數是" & number)
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
diff = Abs(number - guess)
Select Case diff
Case 0
MsgBox ("恭喜你猜對了!")
Case 2, Is < 2
MsgBox ("接近了,再努力!")
Case 10, Is < 12
MsgBox ("有些遠,再努力!")
Case Else
MsgBox ("太遠了,繼續努力!")
End Select
Select Case diff
Case Is <> 0
Text1.Text = ""
Text1.SetFocus
End Select
End Sub

Private Sub Form_Load()
MsgBox ("計算機產生了一個1~100之間的整數," & Chr(10) & "請您猜出這個數是多少。" & Chr(10) & "如果輸入-1,則停止猜數,並輸出要猜的數。")

number = Int(100 * Rnd) + 1

End Sub

Private Sub Label1_Click()

End Sub
猜笑臉
Private Sub Command1_Click(Index As Integer)
Dim a As Integer, i As Integer
Randomize
a = Int(Rnd * 4)
Command1(a).Enabled = False

Command1(a).DisabledPicture = LoadPicture("267.gif")

If a = Index Then
Label1.Caption = "你猜對啦,真棒!"
Else
Label1.Caption = "你猜錯啦,我在這哩!"
End If

For i = 0 To 3
Command1(i).Enabled = False
Next i

End Sub

Private Sub Command2_Click()
Dim i As Integer
For i = 0 To 3
Command1(i).Enabled = True
Command1(i).DisabledPicture = LoadPicture("")
Next i
Label1.Caption = "猜猜我在哪兒?"
End Sub

Private Sub Command3_Click()
End
End Sub

Ⅳ vb小游戲源代碼

Rem 窗體創建三個單選框按鈕,Option1、Option2、Option3。

小游戲是一個較模糊的概念,它是相對於體積龐大的單機游戲及網路游戲而言的,泛指所有體積較小、玩法簡單的游戲,通常這類游戲以休閑益智類為主,有單機版有網頁版,在網頁上嵌入的多為FLASH格式。

當下小游戲主要是指在線玩的flash版本游戲,統稱小游戲,其實小游戲還包含單機游戲,小型游戲機等。一般游戲大小小於10m的游戲都統稱為小游戲,一些街機類小游戲。因其游戲安裝簡便,耐玩性強,無依賴性而廣受白領及小朋友的喜愛。

小游戲」這個詞的型含義其實很簡單,它不是一些大的游戲,不必花費更多的時間和精力。

小游戲是原始的游戲娛樂方式,小游戲本身是為了叫人們在工作,學習後的一種娛樂、休閑的一種方式,不是為了叫玩家為之花費金錢、花費精力,更不是叫玩家為他痴迷。

小游戲也可以理解為「Flash游戲」,是以SWF為後綴的游戲的總稱.這些游戲是通過Flash軟體和 Flash 編程語言 Flash ActionScript 製作而成。

由於Flash是矢量軟體,所以小游戲放大後幾乎不影響畫面效果。Flash小游戲是一種新興起的游戲形式,以游戲簡單,操作方便,綠色,無需安裝,文件體積小等優點漸漸被廣大網友喜愛。

熱點內容
絕地求生未來之役比賽為什麼進不去 發布:2023-08-31 22:07:08 瀏覽:1236
dota2位置什麼意思 發布:2023-08-31 22:00:04 瀏覽:679
lol電競是什麼樣子 發布:2023-08-31 21:58:40 瀏覽:1134
絕地求生八倍鏡的那個圓圈怎麼弄 發布:2023-08-31 21:58:31 瀏覽:1187
lol龍龜一個多少金幣 發布:2023-08-31 21:55:07 瀏覽:584
王者如何改游戲內名稱 發布:2023-08-31 21:55:06 瀏覽:874
游戲主播打廣告是什麼意思 發布:2023-08-31 21:55:06 瀏覽:1527
絕地求生如何免費拿到ss7賽季手冊 發布:2023-08-31 21:52:13 瀏覽:751
pgg是哪個國家的戰隊lol 發布:2023-08-31 21:52:07 瀏覽:633
一個人的時候才發現游戲很沒意思 發布:2023-08-31 21:49:24 瀏覽:1232