如何在Batch中减少值? (CLOSED)

时间:2017-09-27 19:59:04

标签: batch-file decrement

所以,我一直试图制作经典的“三门”#34;批量游戏,但我遇到了一个问题。显然,批量减少价值非常困难?有谁知道我能做什么?我把游戏的主循环放在这个文本下面。 有什么方法可以有效和紧凑地进行减量吗?谢谢!我把块引用放在了错误的位置。

    :loopdeloop
    color 07
    set /a num=%random% %%3 +1
    SET /p door=Pick a number between one and three: 
    if %door% EQU %num% (
    color 0a
    @echo Correct!
    timeout /t 2 /nobreak>nul
    SET /a score+=1
    )
    if %door% NEQ %num% (
    color 0c
    @echo Incorrect!
  

SET / a score- = 1

    timeout /t 1 /nobreak>nul
    cls
    @echo Three Doors.
    @echo Behind two of these doors there are ghosts.
    @echo Behind one, there is freedom.
    @echo Which one will you take?
    title Three Doors - Score: %score%
    goto :loopdeloop

1 个答案:

答案 0 :(得分:1)

两个独立的如果跟随IMO是没有意义的 请改用else子句。 (并使用适当的缩进)

:loopdeloop
color 07
set /a num=%random% %%3 +1
SET /p door=Pick a number between one and three: 
if %door% EQU %num% (
    color 0a
    @echo Correct!
    SET /a score+=1
) else (
    color 0c
    @echo Incorrect!
    SET /a score-=1
)
timeout /t 2 /nobreak>nul
cls
@echo Three Doors.
@echo Behind two of these doors there are ghosts.
@echo Behind one, there is freedom.
@echo Which one will you take?
title Three Doors - Score: %score%
goto :loopdeloop