1
\$\begingroup\$

I just started learning commands for batch files. I figured a project is a good way to learn the language better, so I'm attempting to recreate the text-based RPG, Thy Dungeonman 3.

So far, I've learned a lot from fixing a lot of minor problems such as lack of quotation marks, extra spaces at the end of environmental variables, and placement of certain commands that all gave a bit of frustration.

I've got a good method down so far, but I feel like I'm being very long-winded with the commands. It might be that I'm just going with what I'm comfortable with, but I am trying to implement ELSE, and IF NOT DEFINED when I can. I'm just looking for some more experienced eyes to see if there is a more concise way of going about this (aside from the CHOICE option, which I plan to implement later, and probably won't fit the scenario now). Here is what I got so far after about 3.5 hours:

@echo off
color 0e
title Thy Dungeon Man 3
echo -------------------------------------------------------------
echo Thy Dungeon Man 3
echo -------------------------------------------------------------
pause
echo.
echo Objective: Get ye flask!
echo. 
echo Commands: Go, Get, Use, Look, Talk, Dance, etc...
pause
echo.
echo Type INV to open inventory.
pause
cls

set boneinv=0
set clawsinv=0
:Dungeon1
echo Ye find yeself in yon dungeon. Thou art tied up with ropes. The spiked walls of the dungeon closeth in on thee. A dongrel skeleton with sharp CLAWS hangs next to you. A BONE layeth upon the ground. Obvious exits are nowheres!
:Dungeon1a
echo.
echo What wouldst thou deau?
set /p choice1=
echo.

if "%choice1%"=="get bone" (
    if "%clawsinv%"=="0" (
        echo.
        echo Thou wouldst, if thou weren'st tiedst upst.
        echo.
        pause
        cls
        goto Dungeon1a
    )
)

if "%choice1%"=="look" (
    if "%boneinv%"=="2" (
        cls
        echo Ye find teself in yon dungeon. The spiked walls of the dungeon are jammed open with a big ol' bone. A stone door layeth open to the NORTH. A dongrel skeleton with sharp CLAWS hangs next to you.
        goto Dungeon1a
    ) else (
        cls
        goto Dungeon1
    )
)

if "%choice1%"=="inv" (
    if "%boneinv%"=="0" (
        echo.
        echo Nothing but streets and roads. Note to thyself: The spikey walls draw nearer.
        echo.
        pause
        cls
        goto Dungeon1a
    )
)

if "%choice1%"=="inv" (
    if "%boneinv%"=="1" (
        echo.
        echo Ye has: a big ol' bone, and an unbearable lightness of being.
        echo.
        pause
        cls
        goto Dungeon1a
    )
)

if "%choice1%"=="inv" (
    if "%boneinv%"=="2" (
        echo.
        echo Nothing but streets and roads.
        echo.
        pause
        cls
        goto Dungeon1a
    )
)

if "%choice1%"=="get ye flask" (
    echo.
    echo Ho, ho. Aren't thee witty? Twere it that simple I wouldn't have bothered making this game. Note to thyself: The spikey walls draw nearer.
    echo.
    pause
    cls
    goto Dungeon1a
)

if "%choice1%"=="get flask" (
    echo.
    echo Ho, ho. Aren't thee witty? Twere it that simple I wouldn't have bothered making this game. Note to thyself: The spikey walls draw nearer.
    echo.
    pause
    cls
    goto Dungeon1a
)

if "%choice1%"=="talk dongrel" (
    echo.
    echo Ye decide to waste time talking to the dead dongrel skeleton. Good one.
    echo.
    pause
    cls
    goto Dungeon1a
)

if "%choice1%"=="get claws" (
    if "%clawsinv%"=="0" (
        echo.
        echo Now thou art using thy dungeonsmarts! You shimmy all up on the dead dongrel and its razor sharp claws slice through the ties that bind. Thou art free!
        echo.
        pause
        set clawsinv=2
        cls
        goto Dungeon1a
    )
)

if "%choice1%"=="get bone" (
   if "%clawsinv%"=="2" (
        if "%boneinv%"=="0" (
            echo.
            echo Bone grasped! Note to thyself: The spikey walls draw nearer. 
            echo.
            pause
            set boneinv=1
            cls
            goto Dungeon1a
        )   
    )
)

if "%choice1%"=="use bone" (
    if "%boneinv%"=="1" (
        echo.
        echo Ye waits until the spiked walls draw dangerously close then thou jammeth the sturdy bone in their collective craw! The walls shudder and quay and finally withdraw! A stone door opens to the NORTH! Exclamations! 
        echo.
        pause
        set boneinv=2
        cls
        goto Dungeon1a
    )
)

if "%choice1%"=="go north" (
    if "%boneinv%"=="2" (
        cls
        goto Dungeon2
    )
)

if "%choice1%"=="go south" (
    if "%boneinv%"=="2" (
        echo.
        echo The walls in this room are totally cramping thy style.
        pause
        cls
        goto Dungeon1a
    )
)

if "%choice1%"=="go east" (
    if "%boneinv%"=="2" (
        echo.
        echo The walls in this room are totally cramping thy style.
        pause
        cls
        goto Dungeon1a
    )
)

    if "%choice1%"=="go west" (
    if "%boneinv%"=="2" (
        echo.
        echo The walls in this room are totally cramping thy style.
        pause
        cls
        goto Dungeon1a
    )
)

if not defined "%choice1%" (
    echo.
    echo Thou're not very goodst at thist gamest.
    echo.
    pause
    cls
    goto Dungeon1a
)

:Dungeon2
echo win!
pause
exit

This is basically one room of many that I plan to follow the same style of writing for, unless I can find a more efficient way of putting all of the commands. So far, everything is working fine.

\$\endgroup\$
  • \$\begingroup\$ I don't envy you - batch is not a nice language whatsoever, and if you have any choice in the matter I recommend PowerShell or Bash over Batch 100% of the time. \$\endgroup\$ – Reinderien May 10 '15 at 22:46
  • \$\begingroup\$ What did you not like about the previous title? \$\endgroup\$ – Jamal May 11 '15 at 5:20
  • \$\begingroup\$ There was nothing wrong with it. I just felt that it sounded more of an instructional post rather than looking for tips. But I'm new to the site, so you may know better on how it should be titled. \$\endgroup\$ – user73285 May 11 '15 at 5:38
  • \$\begingroup\$ We do prefer titles that specify the code's purpose (without questions). Any questions just belong in the post body. \$\endgroup\$ – Jamal May 11 '15 at 5:46
  • \$\begingroup\$ Alright, I gotcha \$\endgroup\$ – user73285 May 11 '15 at 6:07
2
\$\begingroup\$

I know this is a few months old, but figured why not, this looks like a decent text based game. I'm not saying that is a much better version, as I'm pretty much a noob, but I've gone through and set some of the most used functions such as ECHO,ECHO. and GOTO as variables to help save space overall. This version is quite a bit longer. I added some more logic, for example to the "get claws" command, if you already have claws, it tells you that you already have them. I thought about modifying the INV command to actually display the current inventory, but figured if you wanted to you could. Some of the other things that you'll notice I changed was:

if "%choice1%"=="inv" (
    if "%boneinv%"=="0" (
        echo.
        echo Nothing but streets and roads. Note to thyself: The spikey walls draw nearer.
        echo.
        pause
        cls
        goto Dungeon1a
    )
)

if "%choice1%"=="inv" (
    if "%boneinv%"=="1" (
        echo.
        echo Ye has: a big ol' bone, and an unbearable lightness of being.
        echo.
        pause
        cls
        goto Dungeon1a
    )
)

if "%choice1%"=="inv" (
    if "%boneinv%"=="2" (
        echo.
        echo Nothing but streets and roads.
        echo.
        pause
        cls
        goto Dungeon1a
    )
)

It's not necessary to have 3 if "%choice1%"=="inv" when you can just have nested IF statements. For other changes feel free to compare my version to yours. Here, my modified version.

@ECHO OFF
SETLOCAL
COLOR 0E
TITLE Thy Dungeon Man III
:: Set variables for commonly used functions
SET G=GOTO 
SET E=ECHO 
SET S=ECHO.
:: Set variables for first run
SET boneinv=0
SET clawsinv=0
%E%-------------------------------------------------------------
%E%--                    Thy Dungeon Man 3                    --
%E%-------------------------------------------------------------
TIMEOUT /T 2 /NOBREAK>NUL
CLS
%S%
%S%
%S%
%S%
%E%Objective: Get ye flask!
%S% 
%E%Commands: Go, Get, Use, Look, Talk, Dance, etc...
%S%
%E%Type INV to open inventory.
%S%
PAUSE

:Dungeon1
CLS
%E%Ye find yeself in yon dungeon. Thou art tied up with ropes.
%E%The spiked walls of the dungeon closeth in on thee.
%E%A dongrel skeleton with sharp CLAWS hangs next to you.
%E%A BONE layeth upon the ground. Obvious exits are nowheres!
PAUSE
%G%Dungeon1a

:Dungeon1a
CLS
%S%
%S%
%S%
%S%
SET /P choice1=What wouldst thou deau?  

:: Choices
IF /I "%choice1%"=="get bone" (
CLS
    IF %boneinv%==1 (
        %S%
        %E%Ye already haveth thy bone!
        %E%Note to thyself: The spikey walls draw nearer.
        %S%
        PAUSE
        %G% Dungeon1a
    )
    IF %clawsinv%==0 (
        %S%
        %E%Thou wouldst, if thou weren'st tiedst upst.
        %S%
        PAUSE
        %G% Dungeon1a
    )
    IF %clawsinv%==2 (
        IF %boneinv%==0 (
            %S%
            %E%Bone grasped! Note to thyself: The spikey walls draw nearer. 
            %S%
            PAUSE
            SET boneinv=1
            %G% Dungeon1a
        )   
    )
)

IF "%choice1%"=="look" (
CLS
    IF %boneinv%==2 (
        %E%Ye find teself in yon dungeon.
        %E%The spiked walls of the dungeon are jammed open with a big ol' bone.
        %E%A stone door layeth open to the NORTH.
        %E%A dongrel skeleton with sharp CLAWS hangs next to you.
        %G% Dungeon1a
    ) ELSE (
        %G% Dungeon1
    )
)

IF "%choice1%"=="inv" (
CLS
    IF %boneinv%==0 (
        %S%
        %E%Nothing but streets and roads.
        %E%Note to thyself: The spikey walls draw nearer.
        %S%
        PAUSE
        %G% Dungeon1a
    )
    IF %boneinv%==1 (
        %S%
        %E%Ye has: a big ol' bone, and an unbearable lightness of being.
        %S%
        PAUSE
        %G% Dungeon1a
    )
    IF %boneinv%==2 (
        %S%
        %E%Nothing but streets and roads.
        %S%
        PAUSE
        %G% Dungeon1a
    )
)

IF "%choice1%"=="get ye flask" (
    CLS
    %S%
    %E%Ho, ho. Aren't thee witty?
    %E%Twere it that simple I wouldn't have bothered making this game.
    %E%Note to thyself: The spikey walls draw nearer.
    %S%
    PAUSE
    %G% Dungeon1a
)
IF "%choice1%"=="get flask" (
    CLS
    %S%
    %E%Ho, ho. Aren't thee witty?
    %E%Twere it that simple I wouldn't have bothered making this game.
    %E%Note to thyself: The spikey walls draw nearer.
    %S%
    PAUSE
    %G% Dungeon1a
)


IF "%choice1%"=="talk dongrel" (
    CLS
    %S%
    %E%Ye decide to waste time talking to the dead dongrel skeleton. Good one.
    %S%
    PAUSE
    %G% Dungeon1a
)

IF "%choice1%"=="get claws" (
    CLS
    IF %clawsinv%==0 (
        %S%
        %E%Now thou art using thy dungeonsmarts!
        %E%You shimmy all up on the dead dongrel and its razor sharp claws
        %E%slice through the ties that bind. Thou art free!
        %S%
        PAUSE
        SET clawsinv=2
        %G% Dungeon1a
    )
    IF %clawsinv%==2 (
        %S%
        %E%Ye already haveth thy claws!
        %S%
        PAUSE
        SET clawsinv=2
        %G% Dungeon1a
    )
)

IF "%choice1%"=="use bone" (
    CLS
    IF %boneinv%==0 (
        %S%
        %E%Ye haveth no bone to use!
        %S%
        PAUSE
        %G% Dungeon1a
    )
    IF %boneinv%==1 (
        %S%
        %E%Ye waits until the spiked walls draw dangerously close then thou
        %E%jammeth the sturdy bone in their collective craw!
        %E%The walls shudder and quay and finally withdraw!
        %E%A stone door opens to the NORTH! Exclamations! 
        %S%
        PAUSE
        SET boneinv=2
        %G% Dungeon1a
    )
)

IF "%choice1%"=="go north" (
    CLS
    IF %clawsinv%==0 (
        %S%
        %E%Thou wouldst, if thou weren'st tiedst upst.
        %S%
        PAUSE
        %G% Dungeon1a
    )
    IF %clawsinv%==2 (
        IF %boneinv% NEQ 2 (
            %E%The spikey walls draw nearer. 
            PAUSE
            %G% Dungeon1a
        ) ELSE (
            %G% Dungeon2
        )
    )
)

IF "%choice1%"=="go south", "go east", "go west" (
    CLS
    IF %clawsinv%==0 (
    %S%
    %E%Thou wouldst, if thou weren'st tiedst upst.
    %S%
    PAUSE
    %G% Dungeon1a
    )
    IF %clawsinv%==2 (
        IF %boneinv% NEQ 2 (
            %E%The spikey walls draw nearer. 
            PAUSE
            %G% Dungeon1a
        ) ELSE (
            %S%
            %E%The walls in this room are totally cramping thy style.
            PAUSE
            %G% Dungeon1a
        )
    )
)

IF NOT DEFINED "%choice1%" (
    CLS
    %S%
    %S%
    %S%
    %S%
    %E%Thou're not very goodst at thist gamest.
    %S%
    PAUSE
    %G% Dungeon1a
)


:Dungeon2
CLS
%E%WWWWWWWW                           WWWWWWWW IIIIIIIIII NNNNNNNN        NNNNNNNN
%E%W::::::W                           W::::::W I::::::::I N:::::::N       N::::::N
%E%W::::::W                           W::::::W I::::::::I N::::::::N      N::::::N
%E%W::::::W                           W::::::W II::::::II N:::::::::N     N::::::N
%E% W:::::W           WWWWW           W:::::W    I::::I   N::::::::::N    N::::::N
%E%  W:::::W         W:::::W         W:::::W     I::::I   N:::::::::::N   N::::::N
%E%   W:::::W       W:::::::W       W:::::W      I::::I   N:::::::N::::N  N::::::N
%E%    W:::::W     W:::::::::W     W:::::W       I::::I   N::::::N N::::N N::::::N
%E%     W:::::W   W:::::W:::::W   W:::::W        I::::I   N::::::N  N::::N:::::::N
%E%      W:::::W W:::::W W:::::W W:::::W         I::::I   N::::::N   N:::::::::::N
%E%       W:::::W:::::W   W:::::W:::::W          I::::I   N::::::N    N::::::::::N
%E%        W:::::::::W     W:::::::::W           I::::I   N::::::N     N:::::::::N
%E%         W:::::::W       W:::::::W          II::::::II N::::::N      N::::::::N
%E%          W:::::W         W:::::W           I::::::::I N::::::N       N:::::::N
%E%           W:::W           W:::W            I::::::::I N::::::N        N::::::N
%E%            WWW             WWW             IIIIIIIIII NNNNNNNN         NNNNNNN
ENDLOCAL
PAUSE
EXIT
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to Code Review! Good answer! Also don't worry about a post being old, if you think you can give a helpful answer go for it, especially if it has no answers on it. Those questions are crying out for helpful reviewers like you. \$\endgroup\$ – SuperBiasedMan Sep 17 '15 at 8:29
  • \$\begingroup\$ I honestly didn't even notice that the post was 4 months old until I had already modified the code. But thanks for the warm and welcoming greeting! \$\endgroup\$ – Potato Head Sep 17 '15 at 8:44
  • \$\begingroup\$ Thanks, I appreciate the feedback. I did end up finishing the game a while back, which did have some of the improvements that you suggested. I have the complete file if you are interested in viewing it. I will say that setting variables for common commands is a brilliant idea, and I will incorporate it in future projects. And I will also admit that I was apprehensive of using the NEQ command, but I do see its usefulness. Thank you again for your feedback. \$\endgroup\$ – user73285 Nov 20 '15 at 6:07
  • \$\begingroup\$ @Awexomecross, not a problem, if you wanted to share your code, you could edit your original post. \$\endgroup\$ – Potato Head Nov 23 '15 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy