求vb高手!!!大一vb课程设计,请解释一下源代码。代码都是干什么的,越详细越好。~~~
越详细越好,从学长那弄到的源代码但是看不懂。。内容是龟兔赛跑。大神们帮忙啊~~http://hi.baidu.com/1990ldc/blog/item/0a87fadc...
越详细越好,从学长那弄到的源代码但是看不懂。。内容是龟兔赛跑。大神们帮忙啊~~
http://hi.baidu.com/1990ldc/blog/item/0a87fadc2158fcaacc11667a.html 代码的门。。刚忘了弄上来了
大神们快来啊~~~ 展开
http://hi.baidu.com/1990ldc/blog/item/0a87fadc2158fcaacc11667a.html 代码的门。。刚忘了弄上来了
大神们快来啊~~~ 展开
展开全部
没有界面,没有按钮的名称,可能部分翻译有部分的出入!
'全局变量,可简化成 Public i,m,n,k As Integer
Public i As Integer, m As Integer, n As Integer, k As Integer
'按钮名称为Command1的单击事件,按钮功能为开局前的变量和控件初始化
Private Sub Command1_Click()
'标签名称为Label1的控件显示 ready 字样
Label1.Caption = "ready"
'设置滚动条的值为200
HScroll1.Value = 200
'两个文本款内的内容设置为 0:00::00 应该是要显示时间
Text2.Text = "0:00:00"
Text1.Text = "0:00:00"
'名称为Timer2和Timer4的两个时间控件的活动状态设置为否。
Timer2.Enabled = False
Timer4.Enabled = False
'将全局变量 n 和 k
n = 0
k = 0
'P3和P4的左边缘在窗体的0像素位
P3.Left = 0
P4.Left = 0
'全局变量 i 赋值 1
i = 1
'Timer1时间空间的活动状态设置为真,开始计时,每隔Interval(Timer1控件该属性的值)毫秒执行一次Timer1_Timer函数
Timer1.Enabled = True
End Sub
'触发a1和Command1控件的单击事件
Private Sub a1_Click()
Command1_Click
End Sub
'退出按钮
Private Sub a2_Click()
End
End Sub
'单击b1按钮时,调用系统自带记事本 打开位于A:\龟兔赛跑\2\readme.txt 文件。你那位学长的系统应该是安装在D盘的!如果你系统安装在C盘只要把D改成C即可,另外A:一般为软驱,将路径指向存在的路径才能正常访问
Private Sub b1_Click()
Shell "d:\windows\notepad.exe A:\龟兔赛跑\2\readme.txt", 1
End Sub
'单击b2按钮时弹出 消息框
Private Sub b2_Click()
MsgBox "版本1.0" & Chr(13) & "初次尝试,不足之处,多多指教", 48, "关于赛跑"
End Sub
'响应Form窗体的键盘按下事件,键盘按下一次运行一次该函数
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim j As Integer
'把HScroll1滚动条的当前值赋给变量 j
j = HScroll1.Value
'定义两个静态变量,第一次创建后在窗体关闭前不会二次重建,也就是说本次函数执行后Blin1的值是True,则再运行本函数时Blin1的初值就是True
Static blin1 As Boolean
Static blin2 As Boolean
'判断按下的按键是不是 A 或者 S ,是则继续判断,否则跳到执行Endif下面的语句
If KeyCode = vbKeyA Or KeyCode = vbKeyS Then
'如果i小于8则继续,否则跳到执行Endif下面的语句
If i < 8 Then
'Text2文本款显示“抢跑”并弹出“犯规”警告框
Text2.Text = "抢跑"
MsgBox "PLAYERONE抢跑", 16, "犯规"
'两个文本框内容重新换为0:00:00
Text2.Text = "0:00:00"
Text1.Text = "0:00:00"
'重新初始化全局变量 n,k,i
n = 0
k = 0
i = 1
’退出该函数
Exit Sub
End If
End If
'判断如果blin1为假,而且i=8则继续,否则跳到对应的Endif
If blin1 = False And i = 8 Then
'如果按下的按键为A则继续,否则跳到对应的Endif
If KeyCode = vbKeyA Then
'P3控件的左边缘在窗体的位置+j个像素
P3.Left = P3.Left + j
'变量blin1和blin2的值自反,原来为真的变为假,原来为假的变为真
blin1 = Not blin1
blin2 = Not blin2
End If
End If
'判断若blin2的值为真且i=8则继续执行,否则跳到对应的Endif语句后的代码
If blin2 = True And i = 8 Then
'如果按下的按钮为 S 则继续,否则……
If KeyCode = vbKeyS Then
'P3控件的左边缘在窗体的位置增加j个像素
P3.Left = P3.Left + j
'blin1和blin2自反,同上一句IF
blin2 = Not blin2
blin1 = Not blin1
End If
End If
'静态变量blin3和blin4
Static blin3 As Boolean
Static blin4 As Boolean
'如果按下按键的ASCII码为222或186,则继续,否则……
If KeyCode = 222 Or KeyCode = 186 Then
'如果i<8则继续,否则……
If i < 8 Then
'Text2显示 “抢跑” 字样,并显示犯规警告
Text2.Text = "抢跑"
MsgBox "PLAYERTWO抢跑", 16, "犯规"
'初始化全局变量和Text2文本框内容
i = 1
Text2.Text = "0:00:00"
n = 0
k = 0
'结束本函数
Exit Sub
End If
End If
'判断blin3的值是否为假 并且 i=8,是则继续,否则……
If blin3 = False And i = 8 Then
'判断按下的按钮的ASCII码是否为186
If KeyCode = 186 Then
'P4控件的左边缘在窗体的位置加j个像素
P4.Left = P4.Left + j
'blin3和blin4自反
blin3 = Not blin3
blin4 = Not blin4
End If
End If
'判断功能同上,只要上面懂了这里也就懂了。功能大致一样。只是响应的控件不一样而已。(上面为P3,这里为P4)
If blin4 = True And i = 8 Then
If KeyCode = 222 Then
P4.Left = P4.Left + j
blin4 = Not blin4
blin3 = Not blin3
End If
End If
'如果P3控件的左边缘大于或者等于P1控件的宽减去P3控件的宽的值则继续,否则……
If P3.Left >= P1.Width - P3.Width Then
'设置Timer4时间控件为不活动的
Timer4.Enabled = False
'P3的左边缘设置为P1控件的宽减P3控件的宽
P3.Left = P1.Width - P3.Width
End If
'功能同上一个IF语句。
If P4.Left >= P2.Width - P4.Width Then
Timer2.Enabled = False
P4.Left = P2.Width - P4.Width
End If
'判断P3控件的左边缘位置是否比P1控件的宽减P3控件的宽的值要大于或等于,并且P4的左边缘也比P2的宽减P4的宽要大于或等于,是则继续,否则……
If P3.Left >= P1.Width - P3.Width And P4.Left >= P2.Width - P4.Width Then
'判断n的值是否比k大,是则继续,否则……
If n > k Then
'弹出窗口,显示获胜者为一号
MsgBox "PLAYERONE 获胜", 48, "比赛 "
'Label1文本控件的可见状态为假(不可见)
Label1.Visible = False
'Timer2和Timer4的活动状态为假
Timer2.Enabled = False
Timer4.Enabled = False
'初始化一下变量和控件文本
k = 0
n = 0
Text1.Text = "0:00:00"
Text2.Text = "0:00:00"
'P3和P4控件左边缘紧贴窗体
P3.Left = 0
P4.Left = 0
End If
'如果k大于n
If k > n Then
'弹出窗口,显示获胜者为二号
MsgBox "PLAYERTWO 获胜", 48, "比赛 "
'此处功能和前一个IF的对应代码段功能相同,此处不再熬述
Label1.Visible = False
Timer2.Enabled = False
Timer4.Enabled = False
k = 0
n = 0
Text1.Text = "0:00:00"
Text2.Text = "0:00:00"
P3.Left = 0
P4.Left = 0
End If
End If
End Sub
'当Timer1时间控件的Enabled属性值为真时,每隔Interval的值(毫秒数)执行一次该函数
Private Sub Timer1_Timer()
'静态变量blins
Static blins As Boolean
'Label1控件的可见性为blins
Label1.Visible = blins
'i的值自增1
i = i + 1
'blins的值自反,自反后每次执行相当于Label1标签会闪烁
blins = Not blins
'如果i=8则触发,否则……
If i = 8 Then
Beep
'label1显示 “开始”
Label1.Caption = "开始"
'label1标签可见
Label1.Visible = True
'timer2和timer4控件为活动状态,timer1为不活动
Timer2.Enabled = True
Timer4.Enabled = True
Timer1.Enabled = False
End If
End Sub
'同上,控件为TIMER2
Private Sub Timer2_Timer()
'n值自增1
n = n + 1
'n0的值取n和60的模
n0 = n Mod 60
'以下是一些赋值的数学计算
n1 = (n \ 60) Mod 60
n2 = ((n \ 60) \ 60) Mod 60
'text1文本框显示("0" & CStr(n2)这段文本的右2位和("0" + CStr(n1)的右2位和("0" & CStr(n0)的右2位,(控制时间的现实格式)
Text1.Text = Right(("0" & CStr(n2)), 2) & ":" & Right(("0" + CStr(n1)), 2) & ":" & Right("0" & CStr(n0), 2)
将时间显示在text1里面
End Sub
'功能同Timer3控件!显示Text2文本框的时间内容,宿舍熄灯,有所不足,见谅!
Private Sub Timer4_Timer()
k = k + 1
k0 = k Mod 60
k1 = (k \ 60) Mod 60
k2 = ((k \ 60) \ 60) Mod 60
Text2.Text = Right(("0" & CStr(k2)), 2) & ":" & Right(("0" + CStr(k1)), 2) & ":" & Right("0" & CStr(k0), 2)
End Sub
'全局变量,可简化成 Public i,m,n,k As Integer
Public i As Integer, m As Integer, n As Integer, k As Integer
'按钮名称为Command1的单击事件,按钮功能为开局前的变量和控件初始化
Private Sub Command1_Click()
'标签名称为Label1的控件显示 ready 字样
Label1.Caption = "ready"
'设置滚动条的值为200
HScroll1.Value = 200
'两个文本款内的内容设置为 0:00::00 应该是要显示时间
Text2.Text = "0:00:00"
Text1.Text = "0:00:00"
'名称为Timer2和Timer4的两个时间控件的活动状态设置为否。
Timer2.Enabled = False
Timer4.Enabled = False
'将全局变量 n 和 k
n = 0
k = 0
'P3和P4的左边缘在窗体的0像素位
P3.Left = 0
P4.Left = 0
'全局变量 i 赋值 1
i = 1
'Timer1时间空间的活动状态设置为真,开始计时,每隔Interval(Timer1控件该属性的值)毫秒执行一次Timer1_Timer函数
Timer1.Enabled = True
End Sub
'触发a1和Command1控件的单击事件
Private Sub a1_Click()
Command1_Click
End Sub
'退出按钮
Private Sub a2_Click()
End
End Sub
'单击b1按钮时,调用系统自带记事本 打开位于A:\龟兔赛跑\2\readme.txt 文件。你那位学长的系统应该是安装在D盘的!如果你系统安装在C盘只要把D改成C即可,另外A:一般为软驱,将路径指向存在的路径才能正常访问
Private Sub b1_Click()
Shell "d:\windows\notepad.exe A:\龟兔赛跑\2\readme.txt", 1
End Sub
'单击b2按钮时弹出 消息框
Private Sub b2_Click()
MsgBox "版本1.0" & Chr(13) & "初次尝试,不足之处,多多指教", 48, "关于赛跑"
End Sub
'响应Form窗体的键盘按下事件,键盘按下一次运行一次该函数
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim j As Integer
'把HScroll1滚动条的当前值赋给变量 j
j = HScroll1.Value
'定义两个静态变量,第一次创建后在窗体关闭前不会二次重建,也就是说本次函数执行后Blin1的值是True,则再运行本函数时Blin1的初值就是True
Static blin1 As Boolean
Static blin2 As Boolean
'判断按下的按键是不是 A 或者 S ,是则继续判断,否则跳到执行Endif下面的语句
If KeyCode = vbKeyA Or KeyCode = vbKeyS Then
'如果i小于8则继续,否则跳到执行Endif下面的语句
If i < 8 Then
'Text2文本款显示“抢跑”并弹出“犯规”警告框
Text2.Text = "抢跑"
MsgBox "PLAYERONE抢跑", 16, "犯规"
'两个文本框内容重新换为0:00:00
Text2.Text = "0:00:00"
Text1.Text = "0:00:00"
'重新初始化全局变量 n,k,i
n = 0
k = 0
i = 1
’退出该函数
Exit Sub
End If
End If
'判断如果blin1为假,而且i=8则继续,否则跳到对应的Endif
If blin1 = False And i = 8 Then
'如果按下的按键为A则继续,否则跳到对应的Endif
If KeyCode = vbKeyA Then
'P3控件的左边缘在窗体的位置+j个像素
P3.Left = P3.Left + j
'变量blin1和blin2的值自反,原来为真的变为假,原来为假的变为真
blin1 = Not blin1
blin2 = Not blin2
End If
End If
'判断若blin2的值为真且i=8则继续执行,否则跳到对应的Endif语句后的代码
If blin2 = True And i = 8 Then
'如果按下的按钮为 S 则继续,否则……
If KeyCode = vbKeyS Then
'P3控件的左边缘在窗体的位置增加j个像素
P3.Left = P3.Left + j
'blin1和blin2自反,同上一句IF
blin2 = Not blin2
blin1 = Not blin1
End If
End If
'静态变量blin3和blin4
Static blin3 As Boolean
Static blin4 As Boolean
'如果按下按键的ASCII码为222或186,则继续,否则……
If KeyCode = 222 Or KeyCode = 186 Then
'如果i<8则继续,否则……
If i < 8 Then
'Text2显示 “抢跑” 字样,并显示犯规警告
Text2.Text = "抢跑"
MsgBox "PLAYERTWO抢跑", 16, "犯规"
'初始化全局变量和Text2文本框内容
i = 1
Text2.Text = "0:00:00"
n = 0
k = 0
'结束本函数
Exit Sub
End If
End If
'判断blin3的值是否为假 并且 i=8,是则继续,否则……
If blin3 = False And i = 8 Then
'判断按下的按钮的ASCII码是否为186
If KeyCode = 186 Then
'P4控件的左边缘在窗体的位置加j个像素
P4.Left = P4.Left + j
'blin3和blin4自反
blin3 = Not blin3
blin4 = Not blin4
End If
End If
'判断功能同上,只要上面懂了这里也就懂了。功能大致一样。只是响应的控件不一样而已。(上面为P3,这里为P4)
If blin4 = True And i = 8 Then
If KeyCode = 222 Then
P4.Left = P4.Left + j
blin4 = Not blin4
blin3 = Not blin3
End If
End If
'如果P3控件的左边缘大于或者等于P1控件的宽减去P3控件的宽的值则继续,否则……
If P3.Left >= P1.Width - P3.Width Then
'设置Timer4时间控件为不活动的
Timer4.Enabled = False
'P3的左边缘设置为P1控件的宽减P3控件的宽
P3.Left = P1.Width - P3.Width
End If
'功能同上一个IF语句。
If P4.Left >= P2.Width - P4.Width Then
Timer2.Enabled = False
P4.Left = P2.Width - P4.Width
End If
'判断P3控件的左边缘位置是否比P1控件的宽减P3控件的宽的值要大于或等于,并且P4的左边缘也比P2的宽减P4的宽要大于或等于,是则继续,否则……
If P3.Left >= P1.Width - P3.Width And P4.Left >= P2.Width - P4.Width Then
'判断n的值是否比k大,是则继续,否则……
If n > k Then
'弹出窗口,显示获胜者为一号
MsgBox "PLAYERONE 获胜", 48, "比赛 "
'Label1文本控件的可见状态为假(不可见)
Label1.Visible = False
'Timer2和Timer4的活动状态为假
Timer2.Enabled = False
Timer4.Enabled = False
'初始化一下变量和控件文本
k = 0
n = 0
Text1.Text = "0:00:00"
Text2.Text = "0:00:00"
'P3和P4控件左边缘紧贴窗体
P3.Left = 0
P4.Left = 0
End If
'如果k大于n
If k > n Then
'弹出窗口,显示获胜者为二号
MsgBox "PLAYERTWO 获胜", 48, "比赛 "
'此处功能和前一个IF的对应代码段功能相同,此处不再熬述
Label1.Visible = False
Timer2.Enabled = False
Timer4.Enabled = False
k = 0
n = 0
Text1.Text = "0:00:00"
Text2.Text = "0:00:00"
P3.Left = 0
P4.Left = 0
End If
End If
End Sub
'当Timer1时间控件的Enabled属性值为真时,每隔Interval的值(毫秒数)执行一次该函数
Private Sub Timer1_Timer()
'静态变量blins
Static blins As Boolean
'Label1控件的可见性为blins
Label1.Visible = blins
'i的值自增1
i = i + 1
'blins的值自反,自反后每次执行相当于Label1标签会闪烁
blins = Not blins
'如果i=8则触发,否则……
If i = 8 Then
Beep
'label1显示 “开始”
Label1.Caption = "开始"
'label1标签可见
Label1.Visible = True
'timer2和timer4控件为活动状态,timer1为不活动
Timer2.Enabled = True
Timer4.Enabled = True
Timer1.Enabled = False
End If
End Sub
'同上,控件为TIMER2
Private Sub Timer2_Timer()
'n值自增1
n = n + 1
'n0的值取n和60的模
n0 = n Mod 60
'以下是一些赋值的数学计算
n1 = (n \ 60) Mod 60
n2 = ((n \ 60) \ 60) Mod 60
'text1文本框显示("0" & CStr(n2)这段文本的右2位和("0" + CStr(n1)的右2位和("0" & CStr(n0)的右2位,(控制时间的现实格式)
Text1.Text = Right(("0" & CStr(n2)), 2) & ":" & Right(("0" + CStr(n1)), 2) & ":" & Right("0" & CStr(n0), 2)
将时间显示在text1里面
End Sub
'功能同Timer3控件!显示Text2文本框的时间内容,宿舍熄灯,有所不足,见谅!
Private Sub Timer4_Timer()
k = k + 1
k0 = k Mod 60
k1 = (k \ 60) Mod 60
k2 = ((k \ 60) \ 60) Mod 60
Text2.Text = Right(("0" & CStr(k2)), 2) & ":" & Right(("0" + CStr(k1)), 2) & ":" & Right("0" & CStr(k0), 2)
End Sub
展开全部
Public i As Integer, m As Integer, n As Integer, k As Integer
Private Sub Command1_Click()
Label1.Caption = "ready"
HScroll1.Value = 200
Text2.Text = "0:00:00"
Text1.Text = "0:00:00"
Timer2.Enabled = False
Timer4.Enabled = False
n = 0
k = 0
P3.Left = 0
P4.Left = 0
i = 1
Timer1.Enabled = True
End Sub
Private Sub a1_Click()
Command1_Click
End Sub
Private Sub a2_Click()
End
End Sub
单击b1按钮时 用记事本打开A:\龟兔赛跑\2\readme.txt 文件
Private Sub b1_Click()
Shell "d:\windows\notepad.exe A:\龟兔赛跑\2\readme.txt", 1
End Sub
单击b2按钮时弹出 消息框
Private Sub b2_Click()
MsgBox "版本1.0" & Chr(13) & "初次尝试,不足之处,多多指教", 48, "关于赛跑"
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim j As Integer
j = HScroll1.Value
Static blin1 As Boolean
Static blin2 As Boolean
If KeyCode = vbKeyA Or KeyCode = vbKeyS Then
If i < 8 Then
Text2.Text = "抢跑"
MsgBox "PLAYERONE抢跑", 16, "犯规"
Text2.Text = "0:00:00"
Text1.Text = "0:00:00"
n = 0
k = 0
i = 1
Exit Sub
End If
End If
If blin1 = False And i = 8 Then
If KeyCode = vbKeyA Then
P3.Left = P3.Left + j
blin1 = Not blin1
blin2 = Not blin2
End If
End If
If blin2 = True And i = 8 Then
If KeyCode = vbKeyS Then
P3.Left = P3.Left + j
blin2 = Not blin2
blin1 = Not blin1
End If
End If
Static blin3 As Boolean
Static blin4 As Boolean
If KeyCode = 222 Or KeyCode = 186 Then
If i < 8 Then
Text2.Text = "抢跑"
MsgBox "PLAYERTWO抢跑", 16, "犯规"
i = 1
Text2.Text = "0:00:00"
n = 0
k = 0
Exit Sub
End If
End If
If blin3 = False And i = 8 Then
If KeyCode = 186 Then
P4.Left = P4.Left + j
blin3 = Not blin3
blin4 = Not blin4
End If
End If
If blin4 = True And i = 8 Then
If KeyCode = 222 Then
P4.Left = P4.Left + j
blin4 = Not blin4
blin3 = Not blin3
End If
End If
If P3.Left >= P1.Width - P3.Width Then
Timer4.Enabled = False
P3.Left = P1.Width - P3.Width
End If
If P4.Left >= P2.Width - P4.Width Then
Timer2.Enabled = False
P4.Left = P2.Width - P4.Width
End If
If P3.Left >= P1.Width - P3.Width And P4.Left >= P2.Width - P4.Width Then
If n > k Then
MsgBox "PLAYERONE 获胜", 48, "比赛 "
Label1.Visible = False
Timer2.Enabled = False
Timer4.Enabled = False
k = 0
n = 0
Text1.Text = "0:00:00"
Text2.Text = "0:00:00"
P3.Left = 0
P4.Left = 0
End If
If k > n Then
MsgBox "PLAYERTWO 获胜", 48, "比赛 "
Label1.Visible = False
Timer2.Enabled = False
Timer4.Enabled = False
k = 0
n = 0
Text1.Text = "0:00:00"
Text2.Text = "0:00:00"
P3.Left = 0
P4.Left = 0
End If
End If
End Sub
Private Sub Timer1_Timer()
Static blins As Boolean
Label1.Visible = blins
i = i + 1
blins = Not blins
If i = 8 Then
Beep
Label1.Caption = "开始"
Label1.Visible = True
Timer2.Enabled = True
Timer4.Enabled = True
Timer1.Enabled = False
End If
End Sub
定义计时器 Timer2 和Timer4
Private Sub Timer2_Timer()
n = n + 1
n0 = n Mod 60
n1 = (n \ 60) Mod 60
n2 = ((n \ 60) \ 60) Mod 60
Text1.Text = Right(("0" & CStr(n2)), 2) & ":" & Right(("0" + CStr(n1)), 2) & ":" & Right("0" & CStr(n0), 2)
将时间显示在text1里面
End Sub
Private Sub Timer4_Timer()
k = k + 1
k0 = k Mod 60
k1 = (k \ 60) Mod 60
k2 = ((k \ 60) \ 60) Mod 60
Text2.Text = Right(("0" & CStr(k2)), 2) & ":" & Right(("0" + CStr(k1)), 2) & ":" & Right("0" & CStr(k0), 2)
End Sub
Private Sub Command1_Click()
Label1.Caption = "ready"
HScroll1.Value = 200
Text2.Text = "0:00:00"
Text1.Text = "0:00:00"
Timer2.Enabled = False
Timer4.Enabled = False
n = 0
k = 0
P3.Left = 0
P4.Left = 0
i = 1
Timer1.Enabled = True
End Sub
Private Sub a1_Click()
Command1_Click
End Sub
Private Sub a2_Click()
End
End Sub
单击b1按钮时 用记事本打开A:\龟兔赛跑\2\readme.txt 文件
Private Sub b1_Click()
Shell "d:\windows\notepad.exe A:\龟兔赛跑\2\readme.txt", 1
End Sub
单击b2按钮时弹出 消息框
Private Sub b2_Click()
MsgBox "版本1.0" & Chr(13) & "初次尝试,不足之处,多多指教", 48, "关于赛跑"
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim j As Integer
j = HScroll1.Value
Static blin1 As Boolean
Static blin2 As Boolean
If KeyCode = vbKeyA Or KeyCode = vbKeyS Then
If i < 8 Then
Text2.Text = "抢跑"
MsgBox "PLAYERONE抢跑", 16, "犯规"
Text2.Text = "0:00:00"
Text1.Text = "0:00:00"
n = 0
k = 0
i = 1
Exit Sub
End If
End If
If blin1 = False And i = 8 Then
If KeyCode = vbKeyA Then
P3.Left = P3.Left + j
blin1 = Not blin1
blin2 = Not blin2
End If
End If
If blin2 = True And i = 8 Then
If KeyCode = vbKeyS Then
P3.Left = P3.Left + j
blin2 = Not blin2
blin1 = Not blin1
End If
End If
Static blin3 As Boolean
Static blin4 As Boolean
If KeyCode = 222 Or KeyCode = 186 Then
If i < 8 Then
Text2.Text = "抢跑"
MsgBox "PLAYERTWO抢跑", 16, "犯规"
i = 1
Text2.Text = "0:00:00"
n = 0
k = 0
Exit Sub
End If
End If
If blin3 = False And i = 8 Then
If KeyCode = 186 Then
P4.Left = P4.Left + j
blin3 = Not blin3
blin4 = Not blin4
End If
End If
If blin4 = True And i = 8 Then
If KeyCode = 222 Then
P4.Left = P4.Left + j
blin4 = Not blin4
blin3 = Not blin3
End If
End If
If P3.Left >= P1.Width - P3.Width Then
Timer4.Enabled = False
P3.Left = P1.Width - P3.Width
End If
If P4.Left >= P2.Width - P4.Width Then
Timer2.Enabled = False
P4.Left = P2.Width - P4.Width
End If
If P3.Left >= P1.Width - P3.Width And P4.Left >= P2.Width - P4.Width Then
If n > k Then
MsgBox "PLAYERONE 获胜", 48, "比赛 "
Label1.Visible = False
Timer2.Enabled = False
Timer4.Enabled = False
k = 0
n = 0
Text1.Text = "0:00:00"
Text2.Text = "0:00:00"
P3.Left = 0
P4.Left = 0
End If
If k > n Then
MsgBox "PLAYERTWO 获胜", 48, "比赛 "
Label1.Visible = False
Timer2.Enabled = False
Timer4.Enabled = False
k = 0
n = 0
Text1.Text = "0:00:00"
Text2.Text = "0:00:00"
P3.Left = 0
P4.Left = 0
End If
End If
End Sub
Private Sub Timer1_Timer()
Static blins As Boolean
Label1.Visible = blins
i = i + 1
blins = Not blins
If i = 8 Then
Beep
Label1.Caption = "开始"
Label1.Visible = True
Timer2.Enabled = True
Timer4.Enabled = True
Timer1.Enabled = False
End If
End Sub
定义计时器 Timer2 和Timer4
Private Sub Timer2_Timer()
n = n + 1
n0 = n Mod 60
n1 = (n \ 60) Mod 60
n2 = ((n \ 60) \ 60) Mod 60
Text1.Text = Right(("0" & CStr(n2)), 2) & ":" & Right(("0" + CStr(n1)), 2) & ":" & Right("0" & CStr(n0), 2)
将时间显示在text1里面
End Sub
Private Sub Timer4_Timer()
k = k + 1
k0 = k Mod 60
k1 = (k \ 60) Mod 60
k2 = ((k \ 60) \ 60) Mod 60
Text2.Text = Right(("0" & CStr(k2)), 2) & ":" & Right(("0" + CStr(k1)), 2) & ":" & Right("0" & CStr(k0), 2)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是一个龟兔赛跑的经典游戏的代码
显然text1.text和text2.text都是分别记录了龟和兔的赛跑时间
我想P3和P4应该是表示兔子和乌龟的两个对象,P2.width应该是跑道的长度
根据keyascci的判断,一个用户用A、S控制兔子、一个用户用;和'控制乌龟,每次要将AS或;'都按一次才能向前跑一个位移。
我想readme.txt应该是程序的说明文件或者是什么很重要的东东吧。
大致就是按某个按钮表示开始(当然在按这个按钮之前跑的人都算犯规),然后开始计时,这时候反正要往前跑就得两个按键轮流按,最先跑道终点的人就算胜利了。整体的主要思想就应该是这样。
显然text1.text和text2.text都是分别记录了龟和兔的赛跑时间
我想P3和P4应该是表示兔子和乌龟的两个对象,P2.width应该是跑道的长度
根据keyascci的判断,一个用户用A、S控制兔子、一个用户用;和'控制乌龟,每次要将AS或;'都按一次才能向前跑一个位移。
我想readme.txt应该是程序的说明文件或者是什么很重要的东东吧。
大致就是按某个按钮表示开始(当然在按这个按钮之前跑的人都算犯规),然后开始计时,这时候反正要往前跑就得两个按键轮流按,最先跑道终点的人就算胜利了。整体的主要思想就应该是这样。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询