大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
你这个问题不怎么号回答,实际上一个项目可以分成N个小项目,具体如何划分需要根据经验以及具体情况具体分析,这方面有专门的书籍来论述,不是一两句能讲清楚。这里只是讲一下划,下图,rocket项目划分为bootcode rbuild......等5个子项目,每个子项目可以完成自己功能 ,总项目调用这些子项目的功能。
10年积累的成都做网站、网站设计、外贸营销网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先建设网站后付款的网站建设流程,更有马边彝族免费网站建设让你可以放心的选择与我们合作。
随手做了个打地鼠,代码拿去吧。
下图是10x10超大窗体“打地鼠”
直接新建个窗体,覆盖全部代码,不需要拖控件,全部动态创建了。
参数都在前面几行,可以随便改。
格子宽和高是70,间距20,因此横格子和竖格子不要超过10,不然窗体会扩张到非常大的程度。
调整时钟的Interval可决定地鼠的出现频率,你可以修改变化概率 = 15这句话改变出现几率。
Public Class Form1
Dim 横格子 = 4
Dim 竖格子 = 4
Dim 背景色 = Color.Bisque
Dim 打中色 = Color.LawnGreen
Dim 失误色 = Color.Red
Dim 按钮(横格子, 竖格子) As Button
Public WithEvents 时钟 As New Timer With {.Interval = 400}
Public WithEvents 分数板 As New Label With {.AutoSize = False, .Width = 120,
.Height = 26}
Dim 字体 = New Font("黑体", 14)
Dim 随机数 As New Random
Dim 打中数 As Integer = 0
Dim 分数 As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Font = 字体
For x = 1 To 横格子
For y = 1 To 竖格子
按钮(x, y) = New Button()
Me.Controls.Add(按钮(x, y))
按钮(x, y).Width = 70
按钮(x, y).Height = 70
按钮(x, y).Text = ""
按钮(x, y).Location = New Point((x - 1) * (按钮(x, y).Width + 20) +
20, (y - 1) * (按钮(x, y).Height + 20) + 20)
按钮(x, y).Name = String.Format("Button_{0}_{1}", x, y)
按钮(x, y).BackColor = 背景色
按钮(x, y).FlatStyle = FlatStyle.Flat
按钮(x, y).Tag = 0
AddHandler 按钮(x, y).Click, AddressOf 按钮点击
Next
Next
Me.Text = "打地鼠" " [空格键暂停]"
Me.KeyPreview = True
Dim k = 按钮(横格子, 竖格子)
Me.Width = k.Left + k.Width + 40
Me.Height = k.Top + k.Height + 65
Me.Controls.Add(分数板)
分数板.Location = New Point(Me.Width / 2 - 25, 0)
分数板.Text = "分数牌"
时钟.Enabled = True
End Sub
Private Sub 按钮点击(sender As Object, e As EventArgs)
If 时钟.Enabled = False Then Exit Sub
Dim 控件名 = CType(sender, Button).Name.Split("_")
Dim x = CInt(控件名(1)) '截取_分割的第二部分Button_{0}_{1}
Dim y = CInt(控件名(2)) '截取_分割的第三部分Button_{0}_{1}
If 按钮(x, y) IsNot Nothing Then
If 按钮(x, y).Text = "地鼠" Then
打中数 = 打中数 + 1
分数 = 分数 + 20
按钮(x, y).Text = 打中数 "!"
分数板.Text = "得分:" 分数
按钮(x, y).BackColor = 打中色
按钮(x, y).Tag = 1
ElseIf 按钮(x, y).Text = "" Then
分数 = 分数 - 20
If 分数 0 Then 分数 = 0
分数板.Text = "得分:" 分数
按钮(x, y).Text = "乱打!"
按钮(x, y).BackColor = 失误色
按钮(x, y).Tag = 2
End If
End If
End Sub
Private Sub 时钟_Tick(sender As Object, e As EventArgs) Handles 时钟.Tick
For x = 1 To 横格子
For y = 1 To 竖格子
Dim 变化概率 = 随机数.Next(1, 100)
If 变化概率 = 40 Then
If 按钮(x, y).Tag = 1 Or 按钮(x, y).Tag = 2 Then
按钮(x, y).Text = ""
按钮(x, y).BackColor = 背景色
按钮(x, y).Tag = 0
End If
End If
If 变化概率 = 15 Then
If 按钮(x, y).Text = "地鼠" Then
按钮(x, y).Text = ""
ElseIf 按钮(x, y).Text = "" Then
按钮(x, y).Text = "地鼠"
End If
End If
Next
Next
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles
MyBase.KeyUp
If e.KeyCode = Keys.Space Then 时钟.Enabled = Not 时钟.Enabled
End Sub
End Class
如满意,请采纳,谢谢。
随机生成2-5阶方阵:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim d(,) As Integer
Dim n As Integer
Dim i As Integer
Dim j As Integer
Randomize()
n = Int(4 * Rnd() + 2)
ReDim d(n, n)
Label1.Text = ""
For i = 1 To n
For j = 1 To n
d(i, j) = Int(Rnd() + 0.5)
Label1.Text = Label1.Text d(i, j) " "
Next
Label1.Text = Label1.Text vbCrLf
Next
End Sub
这是个vb6的BINGO小游戏的代码 如果要源程序 去我资料里找我网盘的地址 下载bingo.rar
因为没有任何第三方控件,可以直接转成vb.net的!~
Option Explicit
Private iSumA As IntegerPrivate iSumB As Integer
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Call S_Clear(1)
If F_CheckAll = False Then Exit Sub
For j = 0 To 3
For i = 0 To 3
If Val(Text(j).Text) = Val(Label(i).Caption) Then
If i = j Then
iSumA = iSumA + 1
Else
iSumB = iSumB + 1
End If
End If
Next
Next
Call S_Show
End Sub
Private Sub S_Clear(Optional iKB As Integer = 0)
Dim i As Integer
If iKB = 0 Then
For i = 0 To 3
Label(i).Caption = ""
Text(i).Text = ""
Next
End If
iSumA = 0
iSumB = 0
Label5.Caption = ""
End Sub
Private Sub S_Start()
Dim i As Integer
For i = 0 To 3
Label(i).Visible = False
Label(i).Caption = F_iGetRandomize(i)
Next
End Sub
Private Sub S_Show()
Dim stemp As String
Dim i As Integer
For i = 1 To iSumA
stemp = stemp "A"
Next
For i = 1 To iSumB
stemp = stemp "B"
Next
If iSumA + iSumB = 0 Then
Label5.Caption = "0000"
Else
Label5.Caption = stemp
End If
If iSumA = 4 Then
For i = 0 To 3
Label(i).Visible = False
Label(i).Caption = F_iGetRandomize(i)
Next
MsgBox "Bingo", vbOKOnly, "Flying Frog"
Command2.Value = True
DoEvents
Text(0).SetFocus
End If
End Sub
Private Sub Command2_Click()
Call S_Clear
Call S_Start
End Sub
Private Sub Form_Load()
Call S_Clear
Call S_Start
End Sub
Private Function F_iGetRandomize(ByVal iKB As Integer) As Integer
Dim num As Integer
Start:
Randomize
num = Rnd * (9 - 1) + 1
Select Case iKB
Case 0
F_iGetRandomize = num
Case 1
If num Val(Label(0).Caption) And _
num Val(Label(2).Caption) And _
num Val(Label(3).Caption) Then
F_iGetRandomize = num
Else
GoTo Start
End If
Case 2
If num Val(Label(0).Caption) And _
num Val(Label(2).Caption) And _
num Val(Label(3).Caption) Then
F_iGetRandomize = num
Else
GoTo Start
End If
Case 3
If num Val(Label(0).Caption) And _
num Val(Label(1).Caption) And _
num Val(Label(2).Caption) Then
F_iGetRandomize = num
Else
GoTo Start
End If
End Select
End Function
Private Function F_CheckText(ByVal iIndex As Integer) As Boolean
F_CheckText = False
If Val(Text(iIndex).Text) = 0 Then
Text(iIndex).SetFocus
MsgBox "Must Input", vbCritical, "Flying Frog"
Exit Function
End If
Select Case iIndex
Case 0
If Val(Text(iIndex).Text) = Val(Text(1).Text) Or _
Val(Text(iIndex).Text) = Val(Text(2).Text) Or _
Val(Text(iIndex).Text) = Val(Text(3).Text) Then
Text(iIndex).SetFocus
MsgBox "Same Number", vbCritical, "Flying Frog"
Exit Function
End If
Case 1
If Val(Text(iIndex).Text) = Val(Text(0).Text) Or _
Val(Text(iIndex).Text) = Val(Text(2).Text) Or _
Val(Text(iIndex).Text) = Val(Text(3).Text) Then
Text(iIndex).SetFocus
MsgBox "Same Number", vbCritical, "Flying Frog"
Exit Function
End If
Case 2
If Val(Text(iIndex).Text) = Val(Text(0).Text) Or _
Val(Text(iIndex).Text) = Val(Text(1).Text) Or _
Val(Text(iIndex).Text) = Val(Text(3).Text) Then
Text(iIndex).SetFocus
MsgBox "Same Number", vbCritical, "Flying Frog"
Exit Function
End If
Case 3
If Val(Text(iIndex).Text) = Val(Text(0).Text) Or _
Val(Text(iIndex).Text) = Val(Text(1).Text) Or _
Val(Text(iIndex).Text) = Val(Text(2).Text) Then
Text(iIndex).SetFocus
MsgBox "Same Number", vbCritical, "Flying Frog"
Exit Function
End If
End Select
F_CheckText = True
End Function
Private Function F_CheckAll() As Boolean
Dim i As Integer
F_CheckAll = False
For i = 0 To 3
If F_CheckText(i) = False Then Exit Function
Next
F_CheckAll = True
End Function
Private Sub Text_GotFocus(Index As Integer)
Text(Index).SelStart = 0
Text(Index).SelLength = Len(Text(Index).Text)
End Sub
Private Sub Text_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
If F_CheckText(Index) = False Then Exit Sub
End If
S_gKeySend (KeyCode)
End Sub
Private Sub Text_KeyPress(Index As Integer, KeyAscii As Integer)
KeyAscii = F_gKeypressNumber(Text(Index), KeyAscii, 1)
End Sub
在任意form类或模块中都可以创建类,跟建立函数和过程一样。
示例:
public class form1
‘创建一个属于form的子类,名称为【类名】。
public class 类名
’定义类成员text
public text as string
end class
‘定义一个【类名】类的公共变量。
dim 类名1 as 类名
’定义一个过程,使用【类名】类的text成员
public sub 过程
‘实例化【类名1】
类名1=new 类名
类名1.text=“赋值”
’定义一个【新类】类的私用变量,并实例化。
dim 新类1 as new 新类
新类1.name=“一个字符串”
新类1.age=12
end sub
end class
‘’‘创建一个与form同级的类,名称为【新类】
public class 新类
public sub new()
end sub
public name as string
public age as integer
end class
在模块中使用:
public class module1
dim a as new form1.类名
end module