Hello all! I am new to these forums, and I thought this would be a great introduction for both parties. I am creating a text-based adventure game as a .bat file, just for fun, and would like to share. I am looking for constructive criticism and advice, as I hope that this little project gives me a more advanced knowledge of .bat scripting.
Here's what I have so far:
@echo off
title Adventure Game
set manRoomVal= 0
:manRoom
echo;
echo Your basic controls are:
echo Enter L for Left
echo Enter R for Right
echo Enter F for Forward
echo Enter B for Backward
echo Enter S for Search
echo Enter H for Hear/Listen
if %manRoomVal% EQU 1 goto mainRoom
if %manRoomVal% EQU 0 goto introduction
:introduction
set manRoomVal= 1
echo;
echo You are standing in a cold hallway, wielding a gun. You're sweating and you don't recall much.
echo There is a door infront of you, a desk to the left, a dark opening to a corridor behind you, and nothing to your right. What do you do?
set mainRoomLeftVal= 0
set mainRoomSearchVal= 0
set mainRoomHearVal= 0
set mainRoomRightVal= 0
goto mainRoom
:mainRoom
echo;
set /p directionChoice= What will you do?
if %directionChoice% EQU L goto mainRoomLeft
if %directionChoice% EQU R goto mainRoomRight
if %directionChoice% EQU F goto mainRoomForward
if %directionChoice% EQU B goto mainRoomBackward
if %directionChoice% EQU S goto mainRoomSearch
if %directionChoice% EQU H goto mainRoomHear
if %directionChoice% EQU man goto manRoom
pause
:rejectionRoom
echo;
echo You've already done this!
goto mainRoom
:mainRoomLeft
if %mainRoomLeftVal% EQU 1 goto rejectionRoom
if %mainRoomLeftVal% EQU 0 echo;
echo You turn left and move towards the desk. You look it over. There some papers on it, and perhaps something in the drawer...
echo;
set /p deskChoice= (S)earch it or (L)eave it and turn back the way you were facing before?
if %deskChoice% EQU S goto deskSearch
if %deskChoice% EQU L goto mainRoom
:deskSearch
echo;
echo You examine the paperwork on the top of the desk more closely. It's all very official looking; long writing files with drab words.
echo You can't seem to focus on everything it says..
echo You open the drawer hoping something jumps out of at you in there.
echo There's another gun in there, as well as a set of keys, and a pack of cigarettes.
echo You pocket it all and then move back to the spot you were standing at before.
echo;
set mainRoomLeftVal= 1
goto mainRoom
:mainRoomRight
if %mainRoomRightVal% EQU 1 goto rejectionRoom
if %mainRoomRIghtVal% EQU 0 echo;
echo You turn to your right to move but there is nothing there besides a dull wall.
set mainRoomRightVal= 1
goto mainRoom
:mainRoomSearch
if %mainRoomSearchVal% EQU 1 goto rejectionRoom
if %mainRoomSearchVal% EQU 0 echo;
echo Frantically you try to look around the room and process everything. Your heart is beating so fast and your pupils are dancing with each beat.
echo You notice the walls are cold gray tile, kind of modern looking. There is a fading flourescent light fixture about your head.
echo There's nothing on the floor except garbage.
echo There's blood on your clothes.. Why is there blood on your clothes?
echo;
set mainRoomSearchVal= 1
goto mainRoom
:mainRoomHear
if %mainRoomHearVal% EQU 1 goto rejectionRoom
if %mainRoomHearVal% EQU 0 echo;
echo You try to listen to the noises of the room. It is difficult. Your heart is beating fast and heavily. You also hear yourself breathing.
echo A break in your body's noises let's you hear something deep and familiar in the distance.. Metal on metal.. tunneling through..
echo That's train noise.
echo;
set mainRoomHearVal= 1
goto mainRoom
:mainRoomBackward
echo backward
pause
:mainRoomForward
echo forward
pause
The end, so far. Please tell me what you all think and offer any advice/tips you can!
-Tim
Creating a text-based adventure game
Moderator: DosItHelp
Re: Creating a text-based adventure game
Code: Select all
goto mainRoom
:mainRoom
The goto isn't needed as the code underneath that label will be executed next regardless.
I would change this
Code: Select all
if %directionChoice% EQU L goto mainRoomLeft
to this style of coding for all your IF statements that are comparing strings.
Code: Select all
if /I "%directionChoice%"=="L" goto mainRoomLeft
You may also want to put in some error checking to make sure they only entered in one character. If they enter in LL or ll it will never be equal.
If you are using Windows 7 and above then just use the CHOICE command instead.
Re: Creating a text-based adventure game
Squashman wrote:Code: Select all
goto mainRoom
:mainRoom
The goto isn't needed as the code underneath that label will be executed next regardless.
I would change thisCode: Select all
if %directionChoice% EQU L goto mainRoomLeft
to this style of coding for all your IF statements that are comparing strings.Code: Select all
if /I "%directionChoice%"=="L" goto mainRoomLeft
You may also want to put in some error checking to make sure they only entered in one character. If they enter in LL or ll it will never be equal.
If you are using Windows 7 and above then just use the CHOICE command instead.
Awesome advice, thank you!
Re: Creating a text-based adventure game
Following up Squashman's CHOICE suggestion, I would change this section:
... by this one:
... and change the labels accordingly:
Antonio
Code: Select all
:mainRoom
echo;
set /p directionChoice= What will you do?
if %directionChoice% EQU L goto mainRoomLeft
if %directionChoice% EQU R goto mainRoomRight
if %directionChoice% EQU F goto mainRoomForward
if %directionChoice% EQU B goto mainRoomBackward
if %directionChoice% EQU S goto mainRoomSearch
if %directionChoice% EQU H goto mainRoomHear
if %directionChoice% EQU man goto manRoom
pause
... by this one:
Code: Select all
:mainRoom
echo/
choice /C LRFBSHM /N /M "What will you do? "
goto mainRoom-%errorlevel%
... and change the labels accordingly:
Code: Select all
:mainRoom-7 <- add this before :manRoom
:manRoom
. . .
:mainRoom-1 Left
:mainRoom-2 Right
. . .
Antonio
Re: Creating a text-based adventure game
Aacini wrote:Following up Squashman's CHOICE suggestion, I would change this section:Code: Select all
:mainRoom
echo;
set /p directionChoice= What will you do?
if %directionChoice% EQU L goto mainRoomLeft
if %directionChoice% EQU R goto mainRoomRight
if %directionChoice% EQU F goto mainRoomForward
if %directionChoice% EQU B goto mainRoomBackward
if %directionChoice% EQU S goto mainRoomSearch
if %directionChoice% EQU H goto mainRoomHear
if %directionChoice% EQU man goto manRoom
pause
... by this one:Code: Select all
:mainRoom
echo/
choice /C LRFBSHM /N /M "What will you do? "
goto mainRoom-%errorlevel%
... and change the labels accordingly:Code: Select all
:mainRoom-7 <- add this before :manRoom
:manRoom
. . .
:mainRoom-1 Left
:mainRoom-2 Right
. . .
Antonio
Thanks for this advice. I was thinking about using "quadrant" for the areas and directions in the rooms.
Ex: quadrant1, instead of mainRoom1, and so on.