Solved Batch adventure game

October 18, 2011 at 18:31:22
Specs: Windows 7 Home Premium, 3 gig ram Pentium dual core processor 2.7 ghz
Hi I am fairly new to batch and was working on an room escape based game.

Here is my scripting but it was giving me a lot of trouble. What im trying to do is display whats in the room using the txt files and than erasing it from the "room1" list and adding it to the inventory as if picking it up. I want to do something like-

If "text" is in the file "example.txt" erase

any suggestions would be greatly appreciated


@echo off

:start
echo You wake up in a dimly lit room. You see an open door ahead.

set /p input=COMMAND?
if %input%==walk door


:room1

echo . > inventory.txt
echo You walk into the room and see the following item(s) Woodpost, Glass Shards > room1.txt

type room1.txt

set /p input=COMMAND?
if %input%==take post
echo Woodpost >> inventory.txt
echo You take the post
goto room1

if %input%==take shards
echo Shards >> inventory.txt
echo You take the shards

pause


See More: Batch adventure game

Report •


#1
October 19, 2011 at 09:12:23
I have been playing around with this a little bit and I think it might be easier just to put the items in your code and have them exported to an "inventory.txt" file. This way you dont have to worry about creating text files from the batch file if you wanted to distribute it. I came up with a small segment hopefully it will give you some ideas:


@echo off

:first
if not exist "%userprofile%\Desktop\Adventure Game" (goto next) else (goto start)

:next
mkdir "%userprofile%\desktop\Adventure Game"
goto start

:start
echo You wake up in dimly lit room. You see a door ahead.
ping -n 2 1.1.1.1 > nul
echo.
echo 1) Go through the door?
echo 2) Stay put?
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto room1
if "%Choice%"=="2" goto start

:room1
cls
echo You walk into the room and see the following item(s):
echo.
echo 1) Woodpost
echo 2) Glass Shards
echo.
set /p item=Pick an item:
if "%item%"=="1" echo Woodpost >> "%userprofile%\desktop\Adventure Game\Inventory.txt"
if "%item%"=="2" echo Glass Shards >> "%userprofile%\desktop\Adventure Game\Inventory.txt"
goto (then just keep the code going)


hope this helps


Report •

#2
October 19, 2011 at 14:41:49
✔ Best Answer
What the heck... I added some stuff...

@echo off
setlocal enabledelayedexpansion
:first
if not exist "%userprofile%\Desktop\Adventure Game" (goto next) else (goto start)
:next
mkdir "%userprofile%\desktop\Adventure Game"
goto start
:start
echo You wake up in dimly lit room. You see a door ahead.
ping -n 2 1.1.1.1 > nul
echo.
echo 1) Go through the door?
echo 2) Stay put?
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto room1
if "%Choice%"=="2" goto start
:room1
cls
echo You walk into the room and notice you are beneath a hole in the ceiling. You see the following item(s):
echo.
echo 1) Woodpost
echo 2) Glass Shards
echo 3) Rope tied to hook
echo.
set /p item=Pick an item:
if "%item%"=="1" echo Woodpost >> "%userprofile%\desktop\Adventure Game\Inventory.txt"
if "%item%"=="2" echo Glass Shards >> "%userprofile%\desktop\Adventure Game\Inventory.txt"
if "%item%"=="3" echo Rope Tied To Hook >> "%userprofile%\desktop\Adventure Game\Inventory.txt"
echo 1) Check inventory
echo 2) Go back out the door
set /p choice=Select an action:
if "%choice%"=="1" goto inventorycheck
:inventorycheck
set num=1
for /f (tokens=*) %%a in ""%userprofile%\desktop\Adventure Game\Inventory.txt"
echo !num! %%a
set num=!num!+1
set /p choice=Select an item to learn more about it:
if "%choice%"=="1" goto inv1
if "%choice%"=="2" goto inv2
if "%choice%"=="3" goto inv3
:inv1

some stuff...

:inv2

some stuff...

:inv3

Echo The item Rope Tied To Hook looks like it could help someone cimb out of something...


Report •

#3
October 21, 2011 at 18:11:21
Thanks guys this really helped! And thanks for adding to crashnburns scripts jowan :) If i need more help ill post it up on this website.

Report •

Related Solutions


Ask Question