batch-fileroguelike

Batch Roguelike Game


I've been learning some batch programming, and decided to make a roguelike, as it's one of my favorite types of games. I have researched any information on making a roguelike in batch, but haven't found much. From the little bit I've gathered, this is the code I have so far:

@echo off

rem init starting position
set pos=6

:level
set c1=#
set c2=#
set c3=#
set c4=#

set c5=#
set c6=.
set c7=.
set c8=#

set c9=#
set c10=.
set c11=.
set c12=#

set c13=#
set c14=#
set c15=#
set c16=#

echo %c1%%c2%%c3%%c4%
echo %c5%%c6%%c7%%c8%
echo %c9%%c10%%c11%%c12%
echo %c13%%c14%%c15%%c16%

This works so far, and draws the simple 4x4 room.I made the room only 4x4 for testing purposes, so it would be simple.

Now I'm at a point where I'm not sure how to write the rest. I know I'll need to call subroutines, and get the input (WASD), but I don't know how to structure those subroutines in the file. I'd appreciate anyone's help on how to structure a batch roguelike, get input to move the player, or even just ideas about what could work.

Thanks.


Solution

  • I give you here a technic without CHOICE and without an External command. It use Xcopy to get the INPUT (W,A,S,D). IN this Exemple i don't make any test of position (where is your object on the screen), So to test it go first right (D). It's just an exemple to help you.

    @echo off
    
    :level
    set c1=#
    set c2=#
    set c3=#
    set c4=#
    
    set c5=#
    set c6=.
    set c7=.
    set c8=#
    
    set c9=#
    set c10=.
    set c11=.
    set c12=#
    
    set c13=#
    set c14=#
    set c15=#
    set c16=#
    
    
    @echo off
    setlocal enableextensions enabledelayedexpansion
    
    set haut=        
    set larg=
    
    :boucle
    cls
    echo WASD TO MOVE THE CURSOR Q TO QUIT&echo.
    for %%a in ( !haut! ) do echo.
    call:aff
    Set "Key="
    For /F "delims=" %%# In ('Xcopy /W "%~f0" "%~f0" 2^>Nul') Do If Not Defined Key Set "Key=%%#"
    Set "Key=%Key:~-1%"
    if /i %key%==q (exit /b)
    if /i %key%==w goto:UP
    if /i %key%==s goto:DOWN
    if /i %key%==a goto:LEFT
    if /i %key%==d goto:RIGHT
    
    :LEFT
    set larg=!larg:~0,-1!
    goto boucle
    
    :RIGHT
    set larg= !larg!
    goto boucle
    
    :UP
    set haut=!haut:~0,-2!
    goto boucle
    
    :DOWN
    set haut=!haut! a
    goto boucle
    
    
    :aff
    echo !larg!%c1%%c2%%c3%%c4%
    echo !larg!%c5%%c6%%c7%%c8%
    echo !larg!%c9%%c10%%c11%%c12%
    echo !larg!%c13%%c14%%c15%%c16%