赞 | 77 |
VIP | 0 |
好人卡 | 0 |
积分 | 146 |
经验 | 0 |
最后登录 | 2024-11-23 |
在线时间 | 2152 小时 |
Lv4.逐梦者
- 梦石
- 0
- 星屑
- 14629
- 在线时间
- 2152 小时
- 注册时间
- 2016-9-20
- 帖子
- 861
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 ppspssss 于 2023-1-18 21:30 编辑
以下注释为没有整理(很混乱 ,) 该范例年代久远距离10年之久, 但还是翻到旧USB找到, 印象已經十分模糊,
高中一年级电脑课考试 适合没试过编程的人学习 ,
前此好像还要做一个文字记忆游戏范例已丢 , 第一关记1个英文字, 第五关记5个, 第10关记10个
From1.vb 为代码 , 如果已安裝VB2010, NF.sln打开工程
第一步 : 新建工程 , 选择项目 (具体忘了)
学习"宣告" (或称为 "声明") 变量要在使用之前进行宣告, 变量赋值 , (本工程用到文本型String, 整数型Integer )
: 在可视化窗口(Form 把元件拉出来 , 包括 按钮(botton) , 文字列表(ListBox) , 文字框(Label) , 计时器(Timer)
Randomize()
: "功能是初始化随机数发生器" 每次随机数前都要使用这句, " 如果不使用Randomize函数,得到的结果将有规律性"
Select Case
: 变量在"不同值" 情况,
这里为遇到不同怪物, 如随机值为1, 遇到 "准格尔翼龙" 随机值为1, 遇到"祸牛"
计时器 Timer的使用 , 重置
按钮的启用, true 为 可按, false 为 不可按
记事本txt的写入( 用于生成存档 ) 记事本txt的读入(读取存档 )
Public Class Form1 Dim monster, hero, A As String Dim mhp, mAtk, mdef, money, mexp, Def, Lv, monet, exp, hp, atk, mmoney, hurt, T, mhurt, H, O As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Button4.Enabled = False Button2.Enabled = False Button6.Enabled = False Button7.Enabled = False End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click hp = 10000 Label2.Text = hp atk = Int(Rnd() * 1000) + 200 Label3.Text = atk Def = Int(Rnd() * 1000) + 200 Label4.Text = Def exp = 0 Label5.Text = exp Lv = 1 Label7.Text = Lv monet = 0 Label6.Text = monet hero = InputBox("请输入'自己'") Label1.Text = hero Button1.Enabled = False Button4.Enabled = True Button2.Enabled = True Button6.Enabled = False Timer3.Enabled = True Button7.Enabled = True Label12.Text = Lv * 18888 End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click FileOpen(1, My.Computer.FileSystem.CurrentDirectory & "\save1.text", OpenMode.Output) Write(1, hero, hp, atk, Def, exp, monet, Lv) MsgBox("儲存成功了") FileClose(1) End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click FileOpen(1, My.Computer.FileSystem.CurrentDirectory & "\save1.text", OpenMode.Input) Input(1, hero) Input(1, hp) Input(1, atk) Input(1, Def) Input(1, exp) Input(1, monet) Input(1, Lv) Label1.Text = hero Label2.Text = hp Label3.Text = atk Label4.Text = Def Label5.Text = exp Label6.Text = money Label7.Text = Lv Button1.Enabled = False FileClose(1) Button4.Enabled = True Timer3.Enabled = True ListBox1.Items.Add("讀取成功") Label21.Text = Lv * 20000 End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Randomize() A = Int(Rnd() * 10) + 1 Select Case A Case 1 monster = "准格尔翼龙" mAtk = Lv * 100 mdef = Lv * 100 mhp = 50000 mAtk = Int(Rnd() * 1000) + 100 mmoney = Int(Rnd() * 10000000) + 18 mexp = Lv * 100 + 18 Label8.Text = monster Label9.Text = mhp Case 2 monster = "龙" mAtk = Lv * 300 mdef = Lv * 200 mhp = 80000 mAtk = Int(Rnd() * 1000) + 258 mmoney = Int(Rnd() * 10000) + 18 mexp = Lv * 100 + 18 Label8.Text = monster Label9.Text = mhp Case 3 monster = "暴龙" mdef = Lv * 80 mhp = Lv * 1000 mAtk = Int(Rnd() * 188) + 118 mmoney = Int(Rnd() * 10000) + 18 mexp = Lv * 100 + 18 Label8.Text = monster Label9.Text = mhp Case 4 monster = "龙的傳人" mdef = Lv * 300 mhp = 29620 mAtk = Int(Rnd() * 1000) + 135 mmoney = Int(Rnd() * 10000) + 18 mexp = Lv * 100 + 18 Label8.Text = monster Label9.Text = mhp Case 5 monster = "翼龙" mdef = Lv * 250 mhp = 10000 mAtk = Int(Rnd() * 1000) + 789 mmoney = Int(Rnd() * 10000) + 18 mexp = Lv * 100 + 18 Label8.Text = monster Label9.Text = mhp Case 6 monster = "狂龙" mdef = Lv * 90 mhp = Lv * 1000 mAtk = Int(Rnd() * 1000) + 871 mmoney = Int(Rnd() * 10000) + 18 mexp = Lv * 100 + 18 Label8.Text = monster Label9.Text = mhp Case 7 monster = "大怪獸" mdef = Lv * 200 mhp = 100200 mAtk = Int(Rnd() * 1000) + 1568 mmoney = Int(Rnd() * 10000) + 18 mexp = Lv * 100 + 18 Label8.Text = monster Label9.Text = mhp Case 8 monster = "鴨嘴獸" mdef = Lv * 201.3 mhp = Lv * 0.2 * 5000 mAtk = Int(Rnd() * 1000) + 457 mmoney = Int(Rnd() * 80000000) + 18 mexp = Lv * 100 + 18 Label8.Text = monster Label9.Text = mhp Case 9 monster = "大螞蟻" mdef = Lv * 200 mhp = 400000 mAtk = Int(Rnd() * 1000) + 987 mmoney = Int(Rnd() * 10000) + 18 mexp = Lv * 100 + 18 Label8.Text = monster Label9.Text = mhp Case 10 monster = "祸牛" mdef = Lv * 70 mhp = hp * 0.8 mAtk = Int(Rnd() * 1000) + 333 mmoney = Int(Rnd() * 10000) + 18 mexp = Lv * 100 + 18 Label8.Text = monster Label9.Text = mhp End Select Button4.Enabled = False Button3.Enabled = False Label10.Text = mAtk Label11.Text = mdef Button2.Enabled = False Button6.Enabled = True Timer3.Enabled = False Button7.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick T = T - 1 If T < 0 Then hp = hp - mAtk Label2.Text = hp T = T + 8 ListBox1.Items.Add("怪物打击,受到傷害") End If If mhp <= 0 Then monet = mmoney + monet exp = exp + mexp Label5.Text = exp Label6.Text = monet Label7.Text = Lv Timer1.Enabled = False Timer2.Enabled = False Button2.Enabled = True Button3.Enabled = True Button4.Enabled = True ListBox1.Items.Add("怪物死亡") ListBox1.Items.Add("獲得金錢!!!") ListBox1.Items.Add("獲得經驗值!!!!") Label9.Text = 0 Button5.Enabled = True Button6.Enabled = False If exp > 0.2 ^ Lv Then Lv = Lv + 1 hp = hp + Lv * 1 / 10 atk = atk + Lv ^ 1.001 - 2 * Lv Def = Def + Lv ^ 1.001 - 18 Label3.Text = atk Label4.Text = Def ListBox1.Items.Add("獲得升級!!!!") End If End If If hp < 0 Then hp = 0 Label2.Text = hp Button1.Enabled = True Button4.Enabled = False Button2.Enabled = False Button5.Enabled = False Button3.Enabled = True Button6.Enabled = False Timer2.Enabled = False Timer1.Enabled = False Timer3.Enabled = False hp = 0 Label2.Text = hp MsgBox("陣亡...") End If Label21.Text = Lv * 18888 End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick H = H - 1 If H < 0 Then Label9.Text = mhp H = H + 8 mhp = mhp - hurt ListBox1.Items.Add("打击了怪物") End If If hurt <= 0 Then hurt = hurt * -0.25 End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click If monet < Lv * 18888 Then MsgBox("余额不足,无法购买") End If If monet >= 20000 Then monet = monet - Lv * 18888 Label6.Text = monet Label2.Text = hp hp = hp + Lv * 18888 ListBox1.Items.Add("恢復大量血量") Button5.Enabled = False End If End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click End Sub Private Sub Label12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label10.Click End Sub Private Sub Label17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label17.Click End Sub Private Sub Label16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label16.Click End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Button7.Enabled = False Timer3.Enabled = True Button4.Enabled = False Button3.Enabled = False Button2.Enabled = False Button6.Enabled = False Timer1.Enabled = True Timer2.Enabled = True hurt = Int(atk * Rnd() - mdef * Rnd()) End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick O = 9 O = O - 10 If O < 0 Then hp = hp + Lv * 1 Label2.Text = hp End If End Sub Private Sub Button7_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Button4.Enabled = True Timer3.Enabled = True Button6.Enabled = False Button7.Enabled = False End Sub Private Sub Label12_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label12.Click End Sub End Class
Public Class Form1
Dim monster, hero, A As String
Dim mhp, mAtk, mdef, money, mexp, Def, Lv, monet, exp, hp, atk, mmoney, hurt, T, mhurt, H, O As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button4.Enabled = False
Button2.Enabled = False
Button6.Enabled = False
Button7.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
hp = 10000
Label2.Text = hp
atk = Int(Rnd() * 1000) + 200
Label3.Text = atk
Def = Int(Rnd() * 1000) + 200
Label4.Text = Def
exp = 0
Label5.Text = exp
Lv = 1
Label7.Text = Lv
monet = 0
Label6.Text = monet
hero = InputBox("请输入'自己'")
Label1.Text = hero
Button1.Enabled = False
Button4.Enabled = True
Button2.Enabled = True
Button6.Enabled = False
Timer3.Enabled = True
Button7.Enabled = True
Label12.Text = Lv * 18888
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
FileOpen(1, My.Computer.FileSystem.CurrentDirectory & "\save1.text", OpenMode.Output)
Write(1, hero, hp, atk, Def, exp, monet, Lv)
MsgBox("儲存成功了")
FileClose(1)
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
FileOpen(1, My.Computer.FileSystem.CurrentDirectory & "\save1.text", OpenMode.Input)
Input(1, hero)
Input(1, hp)
Input(1, atk)
Input(1, Def)
Input(1, exp)
Input(1, monet)
Input(1, Lv)
Label1.Text = hero
Label2.Text = hp
Label3.Text = atk
Label4.Text = Def
Label5.Text = exp
Label6.Text = money
Label7.Text = Lv
Button1.Enabled = False
FileClose(1)
Button4.Enabled = True
Timer3.Enabled = True
ListBox1.Items.Add("讀取成功")
Label21.Text = Lv * 20000
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Randomize()
A = Int(Rnd() * 10) + 1
Select Case A
Case 1
monster = "准格尔翼龙"
mAtk = Lv * 100
mdef = Lv * 100
mhp = 50000
mAtk = Int(Rnd() * 1000) + 100
mmoney = Int(Rnd() * 10000000) + 18
mexp = Lv * 100 + 18
Label8.Text = monster
Label9.Text = mhp
Case 2
monster = "龙"
mAtk = Lv * 300
mdef = Lv * 200
mhp = 80000
mAtk = Int(Rnd() * 1000) + 258
mmoney = Int(Rnd() * 10000) + 18
mexp = Lv * 100 + 18
Label8.Text = monster
Label9.Text = mhp
Case 3
monster = "暴龙"
mdef = Lv * 80
mhp = Lv * 1000
mAtk = Int(Rnd() * 188) + 118
mmoney = Int(Rnd() * 10000) + 18
mexp = Lv * 100 + 18
Label8.Text = monster
Label9.Text = mhp
Case 4
monster = "龙的傳人"
mdef = Lv * 300
mhp = 29620
mAtk = Int(Rnd() * 1000) + 135
mmoney = Int(Rnd() * 10000) + 18
mexp = Lv * 100 + 18
Label8.Text = monster
Label9.Text = mhp
Case 5
monster = "翼龙"
mdef = Lv * 250
mhp = 10000
mAtk = Int(Rnd() * 1000) + 789
mmoney = Int(Rnd() * 10000) + 18
mexp = Lv * 100 + 18
Label8.Text = monster
Label9.Text = mhp
Case 6
monster = "狂龙"
mdef = Lv * 90
mhp = Lv * 1000
mAtk = Int(Rnd() * 1000) + 871
mmoney = Int(Rnd() * 10000) + 18
mexp = Lv * 100 + 18
Label8.Text = monster
Label9.Text = mhp
Case 7
monster = "大怪獸"
mdef = Lv * 200
mhp = 100200
mAtk = Int(Rnd() * 1000) + 1568
mmoney = Int(Rnd() * 10000) + 18
mexp = Lv * 100 + 18
Label8.Text = monster
Label9.Text = mhp
Case 8
monster = "鴨嘴獸"
mdef = Lv * 201.3
mhp = Lv * 0.2 * 5000
mAtk = Int(Rnd() * 1000) + 457
mmoney = Int(Rnd() * 80000000) + 18
mexp = Lv * 100 + 18
Label8.Text = monster
Label9.Text = mhp
Case 9
monster = "大螞蟻"
mdef = Lv * 200
mhp = 400000
mAtk = Int(Rnd() * 1000) + 987
mmoney = Int(Rnd() * 10000) + 18
mexp = Lv * 100 + 18
Label8.Text = monster
Label9.Text = mhp
Case 10
monster = "祸牛"
mdef = Lv * 70
mhp = hp * 0.8
mAtk = Int(Rnd() * 1000) + 333
mmoney = Int(Rnd() * 10000) + 18
mexp = Lv * 100 + 18
Label8.Text = monster
Label9.Text = mhp
End Select
Button4.Enabled = False
Button3.Enabled = False
Label10.Text = mAtk
Label11.Text = mdef
Button2.Enabled = False
Button6.Enabled = True
Timer3.Enabled = False
Button7.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
T = T - 1
If T < 0 Then
hp = hp - mAtk
Label2.Text = hp
T = T + 8
ListBox1.Items.Add("怪物打击,受到傷害")
End If
If mhp <= 0 Then
monet = mmoney + monet
exp = exp + mexp
Label5.Text = exp
Label6.Text = monet
Label7.Text = Lv
Timer1.Enabled = False
Timer2.Enabled = False
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
ListBox1.Items.Add("怪物死亡")
ListBox1.Items.Add("獲得金錢!!!")
ListBox1.Items.Add("獲得經驗值!!!!")
Label9.Text = 0
Button5.Enabled = True
Button6.Enabled = False
If exp > 0.2 ^ Lv Then
Lv = Lv + 1
hp = hp + Lv * 1 / 10
atk = atk + Lv ^ 1.001 - 2 * Lv
Def = Def + Lv ^ 1.001 - 18
Label3.Text = atk
Label4.Text = Def
ListBox1.Items.Add("獲得升級!!!!")
End If
End If
If hp < 0 Then
hp = 0
Label2.Text = hp
Button1.Enabled = True
Button4.Enabled = False
Button2.Enabled = False
Button5.Enabled = False
Button3.Enabled = True
Button6.Enabled = False
Timer2.Enabled = False
Timer1.Enabled = False
Timer3.Enabled = False
hp = 0
Label2.Text = hp
MsgBox("陣亡...")
End If
Label21.Text = Lv * 18888
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
H = H - 1
If H < 0 Then
Label9.Text = mhp
H = H + 8
mhp = mhp - hurt
ListBox1.Items.Add("打击了怪物")
End If
If hurt <= 0 Then
hurt = hurt * -0.25
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If monet < Lv * 18888 Then
MsgBox("余额不足,无法购买")
End If
If monet >= 20000 Then
monet = monet - Lv * 18888
Label6.Text = monet
Label2.Text = hp
hp = hp + Lv * 18888
ListBox1.Items.Add("恢復大量血量")
Button5.Enabled = False
End If
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
End Sub
Private Sub Label12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label10.Click
End Sub
Private Sub Label17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label17.Click
End Sub
Private Sub Label16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label16.Click
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Button7.Enabled = False
Timer3.Enabled = True
Button4.Enabled = False
Button3.Enabled = False
Button2.Enabled = False
Button6.Enabled = False
Timer1.Enabled = True
Timer2.Enabled = True
hurt = Int(atk * Rnd() - mdef * Rnd())
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
O = 9
O = O - 10
If O < 0 Then
hp = hp + Lv * 1
Label2.Text = hp
End If
End Sub
Private Sub Button7_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Button4.Enabled = True
Timer3.Enabled = True
Button6.Enabled = False
Button7.Enabled = False
End Sub
Private Sub Label12_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label12.Click
End Sub
End Class
opiuny.rar
(126.98 KB, 下载次数: 1)
|
评分
-
查看全部评分
|