帮忙用vb语言编一个与电脑玩剪刀石头布游戏,
2个回答
展开全部
VB做控制台程序比较难,你还是用窗口吧.
控制台程序直接用BAT就行了,用记事本存成bat文件.
::SSC版本:0.1.0.0
::2010年9月5日
@echo off
color f0
Setlocal enabledelayedexpansion
:Start
Set NoMax=32767
Set /a No.1=%NoMax% / 3
Goto Main
:EchoM
Cls
Echo ------------------
Echo.
Echo 1.石头
Echo.
Echo 2.剪刀
Echo.
Echo 3.布
Echo.
Echo ------------------
Goto :eof
:EchoR
Cls
IF /i "%1"=="Win" ( Echo You Win )
If /i "%1"=="Lost" ( echo You Lost )
If /i "%1"=="Tp" ( Echo 双方平手 )
Set /p=电脑出的是<nul
If "%2"=="1" Echo 石头
If "%2"=="2" Echo 剪刀
If "%2"=="3" Echo 布
Set /p=你出的是<nul
If "%3"=="1" Echo 石头
If "%3"=="2" Echo 剪刀
If "%3"=="3" Echo 布
Goto :eof
:Main
Call :EchoM
Set App=~
Set /p App=请输入:
If "%APP%"=="1" Goto ex
If "%APP%"=="2" Goto ex
If "%APP%"=="3" Goto ex
Echo 输入错误!
ping /n 2 127.1>nul
Goto Main
:EX
Set /a No.3=%RANDOM% / %No.1% + 1
IF %App% EQU %No.3% (
Call :echor tp %No.3% %App%
) else (
IF %App%==1 ( If %no.3%==3 Set app=4 )
If %no.3%==1 ( If %App%==3 Set no.3=4)
If !app! GTR !No.3! call :echor lost %No.3% %App%
IF !No.3! GTR !app! call :echor win %No.3% %App%
)
Pause>NUL
Goto Main
控制台程序直接用BAT就行了,用记事本存成bat文件.
::SSC版本:0.1.0.0
::2010年9月5日
@echo off
color f0
Setlocal enabledelayedexpansion
:Start
Set NoMax=32767
Set /a No.1=%NoMax% / 3
Goto Main
:EchoM
Cls
Echo ------------------
Echo.
Echo 1.石头
Echo.
Echo 2.剪刀
Echo.
Echo 3.布
Echo.
Echo ------------------
Goto :eof
:EchoR
Cls
IF /i "%1"=="Win" ( Echo You Win )
If /i "%1"=="Lost" ( echo You Lost )
If /i "%1"=="Tp" ( Echo 双方平手 )
Set /p=电脑出的是<nul
If "%2"=="1" Echo 石头
If "%2"=="2" Echo 剪刀
If "%2"=="3" Echo 布
Set /p=你出的是<nul
If "%3"=="1" Echo 石头
If "%3"=="2" Echo 剪刀
If "%3"=="3" Echo 布
Goto :eof
:Main
Call :EchoM
Set App=~
Set /p App=请输入:
If "%APP%"=="1" Goto ex
If "%APP%"=="2" Goto ex
If "%APP%"=="3" Goto ex
Echo 输入错误!
ping /n 2 127.1>nul
Goto Main
:EX
Set /a No.3=%RANDOM% / %No.1% + 1
IF %App% EQU %No.3% (
Call :echor tp %No.3% %App%
) else (
IF %App%==1 ( If %no.3%==3 Set app=4 )
If %no.3%==1 ( If %App%==3 Set no.3=4)
If !app! GTR !No.3! call :echor lost %No.3% %App%
IF !No.3! GTR !app! call :echor win %No.3% %App%
)
Pause>NUL
Goto Main
参考资料: http://tieba.baidu.com/f?kz=881592303
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我写的是一个控制台程序 你执行的时候要按ctrl+f5
Module Module1
Sub Main()
Dim jiandao As String = "Scissors"
Dim shitou As String = "Stone"
Dim bu As String = "Paper"
Dim custom As String
'1 as Scissors,2 as Stone,3 as Paper
Dim computer As Integer
Console.WriteLine("Please enter your choice.")
start: custom = Console.ReadLine()
custom = Trim(custom)
computer = CInt(Rnd() * 3 + 1)
Select Case LCase(custom)
Case "scissors"
If computer = 1 Then
Console.WriteLine("Computer's choice is Scissors.")
Console.WriteLine("The game ends in a tie.")
ElseIf computer = 2 Then
Console.WriteLine("Computer's choice is Stone.")
Console.WriteLine("You lose the game.")
ElseIf computer = 3 Then
Console.WriteLine("Computer's choice is Paper.")
Console.WriteLine("You win the game.")
End If
Case "stone"
If computer = 2 Then
Console.WriteLine("Computer's choice is Stone.")
Console.WriteLine("The game ends in a tie.")
ElseIf computer = 3 Then
Console.WriteLine("Computer's choice is Paper.")
Console.WriteLine("You lose the game.")
ElseIf computer = 1 Then
Console.WriteLine("Computer's choice is Scissors.")
Console.WriteLine("You win the game.")
End If
Case "paper"
If computer = 3 Then
Console.WriteLine("Computer's choice is Paper.")
Console.WriteLine("The game ends in a tie.")
ElseIf computer = 1 Then
Console.WriteLine("Computer's choice is Scissors.")
Console.WriteLine("You lose the game.")
ElseIf computer = 2 Then
Console.WriteLine("Computer's choice is Stone.")
Console.WriteLine("You win the game.")
End If
Case Else
Console.WriteLine("Your input is not correct,please input again.")
End Select
GoTo start
End Sub
End Module
Module Module1
Sub Main()
Dim jiandao As String = "Scissors"
Dim shitou As String = "Stone"
Dim bu As String = "Paper"
Dim custom As String
'1 as Scissors,2 as Stone,3 as Paper
Dim computer As Integer
Console.WriteLine("Please enter your choice.")
start: custom = Console.ReadLine()
custom = Trim(custom)
computer = CInt(Rnd() * 3 + 1)
Select Case LCase(custom)
Case "scissors"
If computer = 1 Then
Console.WriteLine("Computer's choice is Scissors.")
Console.WriteLine("The game ends in a tie.")
ElseIf computer = 2 Then
Console.WriteLine("Computer's choice is Stone.")
Console.WriteLine("You lose the game.")
ElseIf computer = 3 Then
Console.WriteLine("Computer's choice is Paper.")
Console.WriteLine("You win the game.")
End If
Case "stone"
If computer = 2 Then
Console.WriteLine("Computer's choice is Stone.")
Console.WriteLine("The game ends in a tie.")
ElseIf computer = 3 Then
Console.WriteLine("Computer's choice is Paper.")
Console.WriteLine("You lose the game.")
ElseIf computer = 1 Then
Console.WriteLine("Computer's choice is Scissors.")
Console.WriteLine("You win the game.")
End If
Case "paper"
If computer = 3 Then
Console.WriteLine("Computer's choice is Paper.")
Console.WriteLine("The game ends in a tie.")
ElseIf computer = 1 Then
Console.WriteLine("Computer's choice is Scissors.")
Console.WriteLine("You lose the game.")
ElseIf computer = 2 Then
Console.WriteLine("Computer's choice is Stone.")
Console.WriteLine("You win the game.")
End If
Case Else
Console.WriteLine("Your input is not correct,please input again.")
End Select
GoTo start
End Sub
End Module
追问
能稍微变动一下吗,当结果是平局的时候,重新再玩。直到分出胜负为止
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询