/-\ " VB 寫既小遊戲..............)_( 好苦惱~求救中~

2007-05-30 9:07 am
救命牙/O\\有冇人可以幫下我牙。好灰牙!0!

我有個GAME 類似射擊Game,( 有11個格仔既,每個格仔都可能會出兩幅公仔既其中一幅)

如果我想係11個格仔入面 random 搵一個格仔出黎, 再係個格到random出一幅圖點整牙??

Dim RandomNumber As New Random

' Random a number from 0 to 10
WhichBox = RandomNumber.Next(0, 11)

' Random a number from 0 to 1
WhichPicture = RandomNumber.Next(0, 2)
更新1:

其實呢...就咁既= =" 我隻game 由Timer1 控制的。 一"禁"START 個 Timer1 先會random出個11個picturebox既其中一個,而且係個個picturebox到出埋個張圖

更新2:

個11個picturebox我本身已經加入左係個interface到啦

回答 (1)

2007-05-30 10:20 am
✔ 最佳答案
Public Class Form1

Private PictureBox1(10) As PictureBox
Private Image1(1) As Image

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim i As Integer
For i = 0 To 10
InitializePictureBox(PictureBox1(i), 60 * (i + 1), 100)
Next

Image1(0) = System.Drawing.Image.FromFile("Image1.bmp")
Image1(1) = System.Drawing.Image.FromFile("Image2.bmp")
End Sub

Private Sub InitializePictureBox(ByRef picbox, ByVal left, ByVal top)

picbox = New PictureBox

' Set the location and size of the PictureBox control.
picbox.Location = New System.Drawing.Point(left, top)
picbox.Size = New System.Drawing.Size(60, 60)
picbox.TabStop = False

' Set the SizeMode property to the AutoSize value.
picbox.SizeMode = PictureBoxSizeMode.AutoSize

' Set the border style to a three-dimensional border.
picbox.BorderStyle = BorderStyle.Fixed3D

' Add the PictureBox to the form.
Me.Controls.Add(picbox)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim RandomNumber As New Random
Dim WhichBox As Integer, WhichPicture As Integer

' Random a number from 0 to 10
WhichBox = RandomNumber.Next(0, 11)

' Random a number from 0 to 1
WhichPicture = RandomNumber.Next(0, 1)
PictureBox1(WhichBox).Image = Image1(WhichPicture)
End Sub

End Class

2007-05-31 05:06:46 補充:
http://hk.knowledge.yahoo.com/question/?qid=7007053002428答左你


收錄日期: 2021-04-25 20:33:19
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070530000051KK00229

檢視 Wayback Machine 備份