use*_*760 7 goto batch-file windows-7
此代码旨在类似于Pokemon战斗游戏的简单版本.我只是在攻击中编码.我一直在彻底测试,并且每当用户确认他们的攻击时发现错误消息(此时Goto是意外的).警告!!代码长96行.最后,我将把问题部分,所以你可以跳过这第一个巨大的块.
@echo off
Set H1=20
Set A1=8
Set D1=6
Set S1=5
Set H2=14
Set A2=5
Set D2=4
Set S2=8
:Begin
CLS
Echo Bulbasur
Echo %H2%/14 /\
Echo (__) ___
Echo l __lo.ol
Echo l_\ l_\"
Echo.
Echo _
Echo * / \
Echo \\l )
Echo \\__l Charmander
Echo %H1%/20
Echo -Attack -Capture
Echo -Item -Run
Set /p Move=Action?
If %move%==Attack goto Attack
If %move%==Catpure goto capture
If %move%==Item goto Item
If %move%==Run Goto Run
Echo I'm sorry, Charmander can't do that.
Pause
goto Begin
:Attack
ClS
Echo Attacks
Echo 1)Tackle
Echo 2)Growl
Echo 3)Ember
Echo 4)Scratch
Set /p attack=Which one?
If %attack%==Tackle goto Tackle
If %attack%==1 goto Tackle
If %attack%==Growl Goto Growl
If %attack%==2 goto Growl
If %attack%==Ember goto Ember
If %attack%==3 goto Ember
If %attack%==Scratch goto Scratch
If %attack%==4 goto Scratch
If %attack%==Cancel goto Begin
Echo I didn't get that
Goto Attack
:Tackle
CLS
Echo Tackle Hits The opponent where it hurts. EVERYWHERE.
Echo Do you want to?
set /p accept=Yes/No?
If %acccept%==Yes goto Combat
If %acccept%==No goto Begin
Echo I didn't get that.
goto Tackle
:Growl
CLS
Echo Growl lowers the opponents attack.
Echo Do you want to?
set /p accept=Yes/No?
If %acccept%==Yes goto Status
If %acccept%==No goto Begin
Echo I didn't get that.
goto Growl
:Scratch
CLS
Echo Scratch hits the foe with a claw.
Echo Do you want to?
set /p accept=Yes/No?
If %acccept%==Yes goto Combat
If %acccept%==No goto Begin
Echo I didn't get that.
goto Scratch
:Ember
CLS
Echo Ember hits the opponent with a small fire.
Echo Do you want to?
set /p accept=Yes/No?
If %acccept%==Yes goto Combat
If %acccept%==No goto Begin
Echo I didn't get that.
goto Ember
:Combat
CLS
If NOT %attack%==Growl If NOT %attack%==2 set /a H2=%H2%-(%A1%^2/%D2%)
set /a H1=%H1%-(%A2%^2/%D1%)
goto Begin
:Status
CLS
Set /a A1=%A1%-1
goto Combat
Run Code Online (Sandbox Code Playgroud)
问题领域:
:Tackle
CLS
Echo Tackle Hits The opponent where it hurts. EVERYWHERE.
Echo Do you want to?
set /p accept=Yes/No?
If %acccept%==Yes goto Combat
If %acccept%==No goto Begin
Echo I didn't get that.
goto Tackle
Run Code Online (Sandbox Code Playgroud)
代码在这里很好,但是一旦我在这里,它就不会期望goto命令.有人可以修这种牛肉吗?(注意:解决只是一个例子.没有任何攻击有效.)编辑:如果用户输入"是","否",乱码或什么都没有,它仍然会传递相同的错误消息(此时goto意外)
小智 6
你必须把它放在引号中:
if "%accept%"=="yes" goto combat
if "%accept%"=="no" goto begin
Run Code Online (Sandbox Code Playgroud)
或者更确切地说,如果你不想让它区分大小写:
if /i "%accept%"=="yes" goto combat
if /i "%accept%"=="no" goto begin
Run Code Online (Sandbox Code Playgroud)
如果用户没有输入任何内容,您的If行的计算结果可能如下:
\xe2\x80\xa6\nIf ==Yes goto Combat\nIf ==No goto Begin\n\xe2\x80\xa6\nRun Code Online (Sandbox Code Playgroud)\n\n这在语法上是不正确的。我建议在命令accept之前set /p使用一些默认值进行初始化:
\xe2\x80\xa6\nset accept=default\nset /p accept=Yes/No?\nif \xe2\x80\xa6\nRun Code Online (Sandbox Code Playgroud)\n\n这样,如果用户只是按 Enter 键,accept变量将保留该default值,并且后续if不会出现错误。
| 归档时间: |
|
| 查看次数: |
5363 次 |
| 最近记录: |