Help with batch game coding!

March 27, 2011 at 00:26:05
Specs: Windows XP
I am making a game in notepad++ and am having troubles with it. First off whenever I try to go to the instructions or credits it just closes the screen. It also during the first battle won't display the HP correctly and will close and not acutaly start the battle. I also want to know hwo to save it then load it so people can save their progress. I also don't know how to make multiple moves the players can choose to attack with. Thanks for helping me. BTW I am a noobie in DOS but still know some about the code.


@echo off
title Rokemon © Ethan Rigel 2010
:menu
cls
echo What would you like to do?
echo.
echo [1] Start
echo [2] Instructions
echo [3] Credits
echo [4] Exit
set /p choice=)):
if %choice%==1 goto start
if %chocie%==2 goto instructions
if %choice%==3 goto credits
if %choice%==4 exit
:instructions
cls 
echo.
echo To play the game all you have to do is input text 
echo depending on what your options on the screen are!
echo.
echo For example....
echo Choose your Rokemon
echo [1] Rokemon
echo [2] Rokemon
echo [3] Rokemon
pause
set /p instructionschoice=Choose your Rokemon:
if %instructionschoice%==1 goto instructionsend
if %instructionschoice%==2 goto instructionsend
if %instructionschoice%==3 goto instructionsend
:instructionsend
cls
echo That's all there is to it 
goto menu
:credits
cls
echo Programmer: Ethan Rigel
echo Inspirtation: Pokemon
echo © Ethan Rigel 2010
pause
goto menu
:start
cls
echo Hello and welcome to the wonderful world of Rokemon!
echo I'm Professor Poke.
echo.
echo What is your name?
set /p inputname=Name:
echo Nice to meet you %inputname%!
pause 
echo So are you a male of female?
echo.
set /p sex=Sex:
if %sex%==male echo I see you're a male!
if %sex%==female echo I see you're a female!
if %sex%==Male echo I see you're a male!
if %sex%==Female echo I see you're a female!
if %sex%==m echo I see you're a male!
if %sex%==f echo I see you're a female!
pause
echo I would like to give you a Rokemon!
echo So which one do you want?
echo.
echo [1] I have Chardander the fire type, 
echo [2] or you could have a Bulbador a grass type, 
echo [3] lastly you can choose my Squirkle a water type.
set /p starter=Choose your Rokemon:
if %starter%==Chardander goto chardander
if %starter%==Bulbador goto bulbador
if %starter%==Squirkle goto squirkle
if %starter%==1 goto chardander
if %starter%==2 goto bulbador
if %starter%==3 goto squirkle
::::::::::::::::::::Human Stats::::::::::::::::::::
SET money=50
::::::::::::::::::::Pokemon Stats::::::::::::::::::::
:chardander
cls
echo.
SET /a STR=%STR%+5 
SET chardanderlvl=1
SET chardanderexp=0
SET chardanderlvlexp=10
SET chardandermaxexp=100
SET chardanderHP=10
SET chardandermaxhp=50
SET chardanderSTR=1
SET chardanderDEF=1
SET CLASS1=Chardander
echo   [Chardander]
echo.
echo   Chardanders have high strength.
echo   Chardanders can learn fire attacks.
echo.
echo   LVL : %chardanderlvl%
echo   HP  : %chardanderHP%/%chardandermaxhp%
echo   EXP : %chardanderexp%/%chardandermaxexp%
echo   STR : %chardanderSTR%
echo   DEF : %chardanderDEF%
echo.
echo  You have +1 bonus stat point what do you wish to spend it on?:
echo.
echo   [1] STR (+1)
echo   [2] DEF (+1)
echo   [3] HP  (+1)
echo.
SET /p Choice1="))
IF "%Choice1%"=="1" (set /a chardanderSTR=%chardanderSTR%+1
goto town
)
IF "%Choice1%"=="2" (set /a chardanderDEF=%chardanderDEF%+1
goto town
)
IF "%Choice1%"=="3" (set /a chardanderHP=%chardanderHP%+1
goto town
)
:bulbador
cls
echo.
SET /a HP=%HP%+5 
SET bulbadorlvl=1
SET bulbadorexp=0
SET bulbadorlvlexp=10
SET bulbadormaxexp=100
SET bulbadorHP=10
SET bulbadormaxhp=50
SET bulbadorSTR=1
SET bulbadorDEF=1
SET CLASS2=Bulbador
echo   [Bulbador]
echo.
echo   Bulbadors have high health.
echo   Bulbadors can learn grass attacks.
echo.
echo   LVL : %bulbadorlvl%
echo   HP  : %bulbadorHP%/%bulbadormaxhp%
echo   EXP : %bulbadorexp%/%bulbadormaxexp%
echo   STR : %bulbadorSTR%
echo   DEF : %bulbadorDEF%
echo.
echo  You have +1 bonus stat point what do you wish to spend it on?:
echo.
echo   [1] STR (+1)
echo   [2] DEF (+1)
echo   [3] HP  (+1)
echo.
SET /p Choice2="))
IF "%Choice2%"=="1" (set /a bulbadorSTR=%bulbadorSTR%+1
goto town
)
IF "%Choice2%"=="2" (set /a bulbadorDEF=%bulbadorDEF%+1
goto town
)
IF "%Choice2%"=="3" (set /a bulbadorHP=%bulbadorHP%+1
goto town
)
:squirkle
cls
echo.
SET /a DEF=%DEF%+5 
SET squirklelvl=1
SET squirkleexp=0
SET squirklelvlexp=10
SET squirklemaxexp=100
SET squirkleHP=10
SET squirklemaxhp=50
SET squirkleSTR=1
SET squirkleDEF=1
SET CLASS3=Squirkle
echo   [Squirkle]
echo.
echo   Squirkles have high defense.
echo   Squirkles can learn water attacks.
echo.
echo   LVL : %squirkleLVL%
echo   HP  : %squirkleHP%/%squirklemaxhp%
echo   EXP : %squirkleexp%/%maxexp%
echo   STR : %squirkleSTR%
echo   DEF : %squirkleDEF%
echo.
echo  You have +1 bonus stat point what do you wish to spend it on?:
echo.
echo   [1] STR (+1)
echo   [3] DEF  (+1)
echo   [2] HP (+1)
echo.
SET /p Choice3="))
IF "%Choice3%"=="1" (set /a squirkleSTR=%squirkleSTR%+1
goto town
)
IF "%Choice3%"=="2" (set /a squirkleDEF=%squirkleDEF%+1
goto town
)
IF "%Choice3%"=="3" (set /a squirkleHP=%squirkleHP%+1
goto town
)
:levelup
if %starter%==Chardander goto levelup1
if %starter%==Squirkle goto levelup2
if %starter%==Bulbador goto levelup3
:levelup1
cls
set /a HP=%HP%+10
echo.
echo   Congratulations you have advanced to lvl:%lvl%!
echo.
echo   [%CLASS1%]
echo.
echo   LVL : %chardanderlvl%
echo   HP  : %chardanderHP%/%chardandermaxhp%
echo   EXP : %chardanderexp%/%chardandermaxexp%
echo   STR : %chardanderSTR%
echo   DEF : %chardanderDEF%
echo.
echo   You have gained an extra 10 hp
echo   You have +1 bonus stat point what do you wish to spend it on?:
echo. 
echo   [1] STR (+1)
echo   [2] DEF (+1)
echo   [3] HP  (+1)
echo.
SET /p Choice4="))
IF "%Choice4%"=="1" (
SET /a chardanderSTR=%chardanderSTR%+1
)
IF "%Choice4%"=="2" (
SET /a chardanderDEF=%chardanderDEF%+1
)
IF "%Choice1%"=="3" 
set /a chardanderHP=%chardanderHP%+1
)
:levelup2
cls
set /a HP=%HP%+10
echo.
echo   Congratulations you have advanced to lvl:%lvl%!
echo.
echo   [%CLASS3%]
echo.
echo   LVL : %squirkleLVL%
echo   HP  : %squirkleHP%/%squirklemaxhp%
echo   EXP : %squirkleexp%/%maxexp%
echo   STR : %squirkleSTR%
echo   DEF : %squirkleDEF%
echo.
echo   You have gained an extra 10 hp
echo   You have +1 bonus stat point what do you wish to spend it on?:
echo. 
echo   [1] STR (+1)
echo   [2] DEF (+1)
echo   [3] HP  (+1)
echo.
SET /p Choice5="))
IF "%Choice5%"=="1" (
SET /a squirkleSTR=%squirkleSTR%+1
)
IF "%Choice5%"=="2" (
SET /a squirkleDEF=%squirkleDEF%+1
)
IF "%Choice5%"=="3" 
set /a squirkleHP=%squirkleHP%+1
)
:levelup3
cls
set /a HP=%HP%+10
echo.
echo   Congratulations you have advanced to lvl:%lvl%!
echo.
echo   [%CLASS2%]
echo.
echo   LVL : %bulbadorlvl%
echo   HP  : %bulbadorHP%/%bulbadormaxhp%
echo   EXP : %bulbadorexp%/%bulbadormaxexp%
echo   STR : %bulbadorSTR%
echo   DEF : %bulbadorDEF%
echo.
echo   You have gained an extra 10 hp
echo   You have +1 bonus stat point what do you wish to spend it on?:
echo. 
echo   [1] STR (+1)
echo   [2] DEF (+1)
echo   [3] HP  (+1)
echo.
SET /p Choice6="))
IF "%Choice6%"=="1" (
SET /a bulbadorSTR=%bulbadorSTR%+1
)
IF "%Choice6%"=="2" (
SET /a bulbadorDEF=%bulbadorDEF%+1
)
IF "%Choice6%"=="3" 
set /a bulbadorHP=%bulbadorHP%+1
)
:town
cls
if %starter%==Chardander echo I see you chose Chardander! 
if %starter%==Bulbador  echo I see you chose Bulbador! 
if %starter%==Squirkle echo I see you chose Squirkle!
echo I want you to meet my grandson Gary!
echo Go outside to meet him.
pause
echo.
echo As soon as you go outside you meet a kid...
echo.
echo Hey my name is Gary,
echo I see you have a pokemon lets battle!
pause
goto fightgary
:fightgary
cls
echo Gary sends out his pokemon!
echo %inputname% sends out his pokemon!
pause
if %starter%==Chardander goto gary1
if %starter%==Bulbador goto gary2  
if %starter%==Squirkle goto gary3 
:gary1
cls
echo %inputname% sends out Chardander!
echo Gary sends out Squirkle!
echo.
goto begingary1
:gary2
cls
echo %inputname% sends out Bulbador!
echo Gary sends out Chardander!
echo.
goto begingary2
:gary3
cls
echo %inputname% sends out Squirkle!
echo Gary sends out Bulbador!
echo.
goto begingary3
:begingary1
cls
echo Your Chardander has %chardanderHP%HP!
echo Gary's Squirkle has %squirkleHP%HP!
echo [1] Attack
echo [2] Run
set /p garyinput1=))
if %garyinput1%==1 goto garybattle1
if %garyinput1%==2 echo Can't run from trainer battle 
goto begingary1
:begingary2
cls 
echo Your Bulbador has %bulbadorHP%HP!
echo Gary's Chardander has %chardanderHP%HP!
echo [1] Attack
echo [2] Run
set /p garyinput2=))
if %garyinput2%==1 goto garrybattle2
if %garyinput2%==2 echo Can't run from trainer battle 
goto begingary2
:begingary3
cls
echo Your Squirkle has %squirkleHP%HP!
echo Gary's Bulbador has %bulbadorHP%HP!
echo [1] Attack
echo [2] Run
set /p garyinput3=))
if %garyinput3%==1 goto garybattle3
if %garyinput3%==2 echo Can't run from trainer battle 
goto begingary3
:garybattle1
set /a squirkleHP=%squirkleHP% - (%STR%)
if %squirkleHP% leq 0 goto killedgary
set /a chardanderHP=%chardanderhp% - 4
if %chardanderhp% leq 0 goto death
goto begingary
:garybattle2
set /a chardanderHP=%chardanderHP% - (%STR%)
if %chardanderHP% leq 0 goto killedgary
set /a bulbadorHP=%bulbadorHP% - 4
if %bulbadorHP% leq 0 goto death
:garybattle3
set /a bulbadorHP=%bulbadorHP% - (%STR%)
if %bulbadorHP% leq 0 goto killedgary
set /a squirkleHP=%squirkleHP% - 4
if %squirklehp% leq 0 goto death
:killedgary
cls
echo You beat Gary!
echo you gained 7 exp and 6 dollars
set /a exp=%exp% + 7
set /a money=%money% + 6




See More: Help with batch game coding!

Report •

#1
April 5, 2011 at 15:13:42
The main problem is that your not validating input properly, there are also some typo's.

if %chocie%==2

and

IF "%Choice1%"=="3" 
set /a chardanderHP=%chardanderHP%+1
)

are both typo's.

Here is a basic way you can validate set /p:

:label
set /p variable=input string?
if not defined variable goto label
if "%variable:"=%"=="1" goto num1
if /i "%variable:"=%"=="string" goto string
goto label

:num1
echo Number 1 was selected
goto :eof

:string
echo string was selected

A lot of your input sequences fail if the user enters an invalid option, the basic structure above may not seem that different but it does make a big difference.


Report •
Related Solutions


Ask Question