如何在没有命令提示关闭的情况下创建一个简单的批量移动模拟器?

时间:2016-09-18 19:17:55

标签: batch-file

我正在尝试在批量游戏中创建一个简单的关卡。我知道批次不是制作游戏的理想选择,并且其功能非常有限但我还是想挑战自己并尝试这个。这个级别的想法是走廊中的运动模拟,只有左右移动可用,我已经遵循了许多指令,似乎无法使其工作。

这是我到目前为止的代码。

echo off
set "location=#@                /"
echo Move with a and d. @ is you. You is @. Get to the door. I repeat, the door.
echo ###################
echo %location%
echo ###################
goto :movement

:movement
choice /c ad /n
if %errorlevel% equ 1 goto :left
if %errorlevel% equ 2 goto :right
goto :movement

:left
if pos==1 set /a pos=1
if pos<1 set /a pos-=1
goto :position

:right
if pos==17 goto :endlevel
if pos>18 set /a pos+=1
goto :position

:position
if pos=1 set "location=#@                |"
if pos=2 set "location=# @               |"
if pos=3 set "location=#  @              |"
if pos=4 set "location=#   @             |"
if pos=5 set "location=#    @            |"
if pos=6 set "location=#     @           |"
if pos=7 set "location=#      @          |"
if pos=8 set "location=#       @         |"
if pos=9 set "location=#        @        |"
if pos=10 set "location=#         @       |"
if pos=11 set "location=#          @      |"
if pos=12 set "location=#           @     |"
if pos=13 set "location=#            @    |"
if pos=14 set "location=#             @   |"
if pos=15 set "location=#              @  |"
if pos=16 set "location=#               @ |"
if pos=17 set "location=#                @|"
if pos=18 set "location=#                 /"
goto :print

:print
cls
echo Move with a and d. @ is you. You is @. Get to the door. I repeat, the     door.
echo ###################
echo %location%
echo ###################
goto :movement

:endlevel
echo Move with a and d. @ is you. You is @. Get to the door. I repeat, the door.
echo ###################
echo #                 /
echo ###################
>nul timeout 2
echo That's quite some skills you have.
pause
cls
goto :end

:end
echo woo.
pause

由于某种原因,在打印地图的第一部分之后,如果我按下a或d,命令提示符就会关闭,并显示一条显示太快而无法阅读的消息。有人能指出我做错了什么吗?我确信我刚刚犯了一些简单的错误,抱歉是痛苦的,我是批处理的新手。

1 个答案:

答案 0 :(得分:1)

首先,我在已打开的命令提示符下使用echo on运行您的代码,然后收到错误消息(否则我会很难解决所有问题)。

您的语法问题:

  1. if pos<1应为if %pos% lss 1(否则pos未评估,<为输入重定向...实际上应该是gtr或者它不起作用(同样适用于if pos>17
  2. if pos=1应为if %pos% EQU 1
  3. 您必须使用|
  4. 转义^个字符

    这是我修复的代码。它现在移动角色。祝你好运。

    @echo off
    set/a pos=1
    set "location=#@                /"
    echo Move with a and d. @ is you. You is @. Get to the door. I repeat, the door.
    echo ###################
    echo %location%
    echo ###################
    goto movement
    
    :movement
    choice /c ad /n
    if %errorlevel% equ 1 goto left
    if %errorlevel% equ 2 goto right
    goto movement
    
    :left
    if %pos% gtr 1 set /a pos-=1
    goto position
    
    :right
    if %pos% EQU 17 goto endlevel
    if %pos% lss 18 set /a pos+=1
    goto position
    
    :position
    if %pos% EQU 1 set "location=#@                ^|"
    if %pos% EQU 2 set "location=# @               ^|"
    if %pos% EQU 3 set "location=#  @              ^|"
    if %pos% EQU 4 set "location=#   @             ^|"
    if %pos% EQU 5 set "location=#    @            ^|"
    if %pos% EQU 6 set "location=#     @           ^|"
    if %pos% EQU 7 set "location=#      @          ^|"
    if %pos% EQU 8 set "location=#       @         ^|"
    if %pos% EQU 9 set "location=#        @        ^|"
    if %pos% EQU 10 set "location=#         @       ^|"
    if %pos% EQU 11 set "location=#          @      ^|"
    if %pos% EQU 12 set "location=#           @     ^|"
    if %pos% EQU 13 set "location=#            @    ^|"
    if %pos% EQU 14 set "location=#             @   ^|"
    if %pos% EQU 15 set "location=#              @  ^|"
    if %pos% EQU 16 set "location=#               @ ^|"
    if %pos% EQU 17 set "location=#                @^|"
    if %pos% EQU 18 set "location=#                 /"
    goto print
    
    :print
    cls
    echo Move with a and d. @ is you. You is @. Get to the door. I repeat, the     door.
    echo ###################
    echo %location%
    echo ###################
    goto movement
    
    :endlevel
    cls
    echo Move with a and d. @ is you. You is @. Get to the door. I repeat, the door.
    echo ###################
    echo #                 /
    echo ###################
    >nul timeout 2
    echo That's quite some skills you have.
    pause
    cls
    goto end
    
    :end
    echo woo.
    pause