【问题标题】:goto Was Unexpected At This Time {BATCH}goto 此时出乎意料 {BATCH}
【发布时间】:2016-02-09 22:23:29
【问题描述】:

我正在尝试批量制作一个简单的硬币游戏。我遇到的问题是一旦延迟完成(ping)“此时goto是意外的”就是我在窗口关闭之前得到的全部。任何帮助将不胜感激!

@echo off
color f0
title Nim In Batch

::: Main Menu
:main
set /a coins=12
set /a time=0
cls
echo Nim In Batch!
echo.
choice /n /c pr /m "Play Or See Rules?"
if %errorlevel%==1 (
    goto play
)
if %errorlevel%==2 (
    goto rules
)

::: Rules
:rules
cls
echo Objective: Be the one to claim the last coin
echo.
echo Rules: 
echo      -You Play First
echo      -You Must Remove 1,2 Or 3 Coins Each Turn
echo      -Turns Switch Once Coins Are Removed
echo      -Coins Must Be Removed In Order
echo.
echo Ready?
pause>nul
goto main


::: Game
:play
cls
echo (%coins%) Coins
echo.
choice /n /c 123 /m "How Many Coins Do You Wish To Remove?"
if %errorlevel%==1 (
    set /a Coins=%coins%-1
)
if %errorlevel%==2 (
    set /a Coins=%coins%-2
)
if %errorlevel%==3 (
    set /a Coins=%coins%-3
)

cls
echo (%coins%) Coins
echo.
echo Computer Is Thinking
ping 1.1.1.1 -n 1 -w 3250 >NUL
if %errorlevel%==1 (
    set /a Coins=%coins%-3
)
if %errorlevel%==2 (
    set /a Coins=%coins%-2
)
if %errorlevel%==3 (
    set /a Coins=%coins%-1
    )

if %coin%==0 (
    goto end
) else (
    goto play
)


:end
cls
echo Computer Wins! 
echo He Collected The Final Coin!
echo.
pause
goto main

【问题讨论】:

    标签: batch-file goto


    【解决方案1】:

    您在这里忘记了 %coins% 中的s

    if %coins%==0 (
        goto end
    ) else (
        goto play
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-11
      • 2012-04-04
      • 1970-01-01
      相关资源
      最近更新 更多