Program crashing after input

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sambeevors
Posts: 6
Joined: 08 May 2014 11:43

Program crashing after input

#1 Post by sambeevors » 08 May 2014 11:54

My program keeps crashing once I enter which country I want to be, but it only happens sometimes, does anyone know what's wrong with it?

Code: Select all

@echo off
color 0f
title TOTAL WAR!!!
setlocal
call :Echo.Color.Init
goto main
:Echo.Color %1=Color %2=Str [%3=/n]
setlocal enableDelayedExpansion
set "str=%~2"
:Echo.Color.2
:# Replace path separators in the string, so that the final path still refers to the current path.
set "str=a%ECHO.DEL%!str:\=a%ECHO.DEL%\..\%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%!"
set "str=!str:/=a%ECHO.DEL%/..\%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%!"
set "str=!str:"=\"!"
:# Go to the script directory and search for the trailing -
pushd "%ECHO.DIR%"
findstr /p /r /a:%~1 "^^-" "!str!\..\!ECHO.FILE!" nul
popd
:# Remove the name of this script from the output. (Dependant on its length.)
for /l %%n in (1,1,12) do if not "!ECHO.FILE:~%%n!"=="" <nul set /p "=%ECHO.DEL%"
:# Remove the other unwanted characters "\..\: -"
<nul set /p "=%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%"
:# Append the optional CRLF
if not "%~3"=="" echo.
endlocal & goto :eof
:Echo.Color.Var %1=Color %2=StrVar [%3=/n]
if not defined %~2 goto :eof
setlocal enableDelayedExpansion
set "str=!%~2!"
goto :Echo.Color.2
:Echo.Color.Init
set "ECHO.COLOR=call :Echo.Color"
set "ECHO.DIR=%~dp0"
set "ECHO.FILE=%~nx0"
set "ECHO.FULL=%ECHO.DIR%%ECHO.FILE%"
:# Use prompt to store a backspace into a variable. (Actually backspace+space+backspace)
for /F "tokens=1 delims=#" %%a in ('"prompt #$H# & echo on & for %%b in (1) do rem"') do set "ECHO.DEL=%%a"
goto :eof
:main
echo.
echo Welcome to Total War, created by Vincent Allain and Sam Beevors.
echo.
pause
:players
cls
set player=
set replay=
echo.
set /p player=Select 1 or 2 player mode:
if '%player%'=='1' goto name
if '%player%'=='2' goto apology
:apology
echo I am sorry, multiplayer is still a Work In Progress...
ping localhost -n 4 >nul
cls
goto players
:name
cls
set name=
echo.
set /p name=Please type in your name (One word):    
if '%name%'=='' goto name
:country
cls
set country=
set enemy=
echo.
echo Welcome %name%, to Total War!
echo.
set /p country=Choose your country; USA, Russia, or Japan:
if '%country%'=='usa' goto enemy1
if '%country%'=='USA' goto enemy1
if '%country%'=='Usa' goto enemy1
if '%country%'=='Russia' goto enemy2
if '%country%'=='russia' goto enemy2
if '%country%'=='japan' goto enemy3
if '%country%'=='Japan' goto enemy3
goto country
:enemy1
set country=USA   
goto enemy
:enemy2
set country=Russia
goto enemy
:enemy3
set country=Japan
:enemy
set /a cpucountryrand=%random% %%5 +1
if '%cpucountryrand%'=='0' goto enemy
if '%cpucountryrand%'=='1' set enemy=Russia
if '%cpucountryrand%'=='2' set enemy=USA   
if '%cpucountryrand%'=='3' set enemy=Japan
if '%cpucountryrand%'=='4' goto enemy
if '%cpucountryrand%'=='5' goto enemy
if '%enemy%'=='%country%' goto enemy
:begin
set user=1200
set cpu=1200
set nuke=1
set airstrike=3
set missiles=6
set fortify=2
set package=1
set cpunuke=1
set cpuairstrike=3
set cpumissiles=6
set cpufortify=2
set cpupackage=1
:gameplay
cls
color 0f
set move=
set choice=
set cpucount=0
echo.
call :Echo.Color 0b "%name%, your turn."
echo.
echo.
call :Echo.Color 0a "%country%: "
call :Echo.Color 8e "   %user% DEF    "
echo.
call :Echo.Color 0c "%enemy%: "
call :Echo.Color 8e "   %cpu% DEF    "
echo.
echo.
echo Arsenal:
echo.
echo.
call :Echo.Color 0f "   Nukes:      "
call :Echo.Color 70 " %nuke% "
echo.
echo.
call :Echo.Color 0f "   Airstrikes: "
call :Echo.Color 70 " %airstrike% "
echo.
echo.
call :Echo.Color 0f "   Missiles:   "
call :Echo.Color 70 " %missiles% "
echo.
echo.
call :Echo.Color 0f "   Workers:    "
call :Echo.Color 70 " %fortify% "
echo.
echo.
if '%package%'=='0' call :Echo.Color 0c "   Note: Care Package Unavaliable."
if '%package%'=='1' call :Echo.Color 0a "   Note: Care Package Avaliable!"
echo.
echo.
echo Options:
echo.
echo    1. Fire NUKE
echo.
echo    2. Fire Airstrike
echo.
echo    3. Fire Missiles
echo.
echo    4. Surrender
echo.
echo    5. Fortify Your Structures
echo.
echo    OR enter C to call in your care package!
echo.
set /p move=   Select your option:
if '%move%'=='1' goto nuke
if '%move%'=='2' goto airstrike
if '%move%'=='3' goto missiles
if '%move%'=='4' goto surrender
if '%move%'=='5' goto fortify
if '%move%'=='c' goto carepackage
if '%move%'=='C' goto carepackage
if '%move%'=='warneverchanges' set /a nuke=%nuke% + 9999
goto gameplay
:nuke
cls
if '%nuke%'=='0' goto nonuke
echo.
echo %name% has fired a NUKE headed towards %enemy%!
echo.
start /MAX img nuke.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %enemy% has lost 400 DEF!
echo.
pause
set /a cpu=%cpu% - 400
set nuke=0
if '%cpu%'=='0' goto win
if '%cpu%'=='-100' goto win
if '%cpu%'=='-200' goto win
if '%cpu%'=='-300' goto win
goto cpu1
:nonuke
echo.
echo You can't use a nuke since you don't have any more left!
echo.
pause
goto gameplay
:airstrike
cls
if '%airstrike%'=='0' goto noairstrike
echo.
echo %name% has fired an airstrike on %enemy%!
echo.
start /MAX img airstrike.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %enemy% has lost 300 DEF!
echo.
pause
set /a cpu=%cpu% - 300
set /a airstrike=%airstrike% - 1
if '%cpu%'=='0' goto win
if '%cpu%'=='-100' goto win
if '%cpu%'=='-200' goto win
if '%cpu%'=='-300' goto win
goto cpu1
:noairstrike
echo.
echo You can't use an airstrike since you don't have any more left!
echo.
pause
goto gameplay
:missiles
cls
if '%missiles%'=='0' goto nomissiles
echo.
echo %name% has fired multiple missiles headed towards %enemy%!
echo.
start /MAX img missile.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %enemy% has lost 200 DEF!
echo.
pause
set /a cpu=%cpu% - 200
set /a missiles=%missiles% - 1
if '%cpu%'=='0' goto win
if '%cpu%'=='-100' goto win
if '%cpu%'=='-200' goto win
if '%cpu%'=='-300' goto win
goto cpu1
:nomissiles
echo.
echo You can't use missiles since you don't have any more left!
echo.
pause
goto gameplay
:fortify
cls
if '%fortify%'=='0' goto nofortify
echo.
echo %name% has foritfied their base, they lost 1 worker in the process.
echo.
start /MAX img fortify.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Fortification complete!
echo.
echo %name% has gained 500 DEF!
echo.
pause
set /a user=%user% + 500
set /a fortify=%fortify% - 1
goto cpu1
:nofortify
echo.
echo You can't fortify your structures again since you have run out of workers.
echo.
pause
goto gameplay
:carepackage
cls
if '%package%'=='0' goto nocarepackage
echo.
echo %name% has called in their care package!
echo.
:carepackagegive
set /a reward=%random% %%6
if '%reward%'=='0' goto carepackagegive
if '%reward%'=='1' goto carepackagegive
if '%reward%'=='2' goto carepackagegive
if '%reward%'=='3' set /a nuke=%nuke% + 1
if '%reward%'=='4' set /a airstrike=%airstrike% + 1
if '%reward%'=='5' set /a missiles=%missiles% + 1
if '%reward%'=='6' set /a fortify=%fortify% + 1
start /MAX img package.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo.
echo %name%'s care package has arrived, and will be opened on their next turn.
echo.
pause
set /a package=%package% - 1
goto cpu1
:nocarepackage
echo.
echo Your care package is unavaliable.
echo.
pause
goto gameplay
:surrender
cls
start /MAX img surrender.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo.
echo "We may have lost the war, but we still have our dignity..."
echo.
pause
:end
cls
echo.
echo "We may have lost the war, but we still have our dignity..."
echo.
set /p replay=Type anything to replay the game. Type 'x' to exit:
if '%replay%'=='x' goto suggest
if '%replay%'=='' goto end
goto players
:win
cls
echo.
echo You have won Total War!!!
echo.
pause
:win2
cls
echo.
echo You have won Total War!!!
echo.
set /p replay=Type anything to replay the game. Type 'x' to exit:
if '%replay%'=='x' goto suggest
if '%replay%'=='' goto win2
goto players
:cpu1
cls
set /a cpucount=%cpucount% + 1
if '%cpucount%'=='5' goto cpu2
echo.
call :Echo.Color 0d "CPU's turn..."
echo.
echo.
call :Echo.Color 0c "%country%: "
call :Echo.Color 8e "   %user% DEF    "
echo.
call :Echo.Color 0a "%enemy%: "
call :Echo.Color 8e "   %cpu% DEF    "
echo.
echo.
echo Arsenal:
echo.
echo.
call :Echo.Color 0f "   Nukes:      "
call :Echo.Color 70 " %cpunuke% "
echo.
echo.
call :Echo.Color 0f "   Airstrikes: "
call :Echo.Color 70 " %cpuairstrike% "
echo.
echo.
call :Echo.Color 0f "   Missiles:   "
call :Echo.Color 70 " %cpumissiles% "
echo.
echo.
call :Echo.Color 0f "   Workers:    "
call :Echo.Color 70 " %cpufortify% "
echo.
echo.
if '%cpupackage%'=='0' call :Echo.Color 0c "   Note: Care Package Unavaliable."
if '%cpupackage%'=='1' call :Echo.Color 0a "   Note: Care Package Avaliable!"
echo.
echo.
echo Options:
echo.
echo    1. Fire NUKE
echo.
echo    2. Fire Airstrike
echo.
echo    3. Fire Missiles
echo.
echo    4. Surrender
echo.
echo    5. Fortify Your Structures
echo.
echo    OR enter C to call in your care package!
echo.
echo    Select your option:
echo.
call :Echo.Color 0b "      ?"
ping localhost -n 1 >nul
cls
echo.
call :Echo.Color 0d "CPU's turn..."
echo.
echo.
call :Echo.Color 0c "%country%: "
call :Echo.Color 8e "   %user% DEF    "
echo.
call :Echo.Color 0a "%enemy%: "
call :Echo.Color 8e "   %cpu% DEF    "
echo.
echo.
echo Arsenal:
echo.
echo.
call :Echo.Color 0f "   Nukes:      "
call :Echo.Color 70 " %cpunuke% "
echo.
echo.
call :Echo.Color 0f "   Airstrikes: "
call :Echo.Color 70 " %cpuairstrike% "
echo.
echo.
call :Echo.Color 0f "   Missiles:   "
call :Echo.Color 70 " %cpumissiles% "
echo.
echo.
call :Echo.Color 0f "   Workers:    "
call :Echo.Color 70 " %cpufortify% "
echo.
echo.
if '%cpupackage%'=='0' call :Echo.Color 0c "   Note: Care Package Unavaliable."
if '%cpupackage%'=='1' call :Echo.Color 0a "   Note: Care Package Avaliable!"
echo.
echo.
echo Options:
echo.
echo    1. Fire NUKE
echo.
echo    2. Fire Airstrike
echo.
echo    3. Fire Missiles
echo.
echo    4. Surrender
echo.
echo    5. Fortify Your Structures
echo.
echo    OR enter C to call in your care package!
echo.
echo    Select your option:
echo.
echo.
call :Echo.Color 0d "      ?"
ping localhost -n 1 >nul
cls
echo.
call :Echo.Color 0d "CPU's turn..."
echo.
echo.
call :Echo.Color 0c "%country%: "
call :Echo.Color 8e "   %user% DEF    "
echo.
call :Echo.Color 0a "%enemy%: "
call :Echo.Color 8e "   %cpu% DEF    "
echo.
echo.
echo Arsenal:
echo.
echo.
call :Echo.Color 0f "   Nukes:      "
call :Echo.Color 70 " %cpunuke% "
echo.
echo.
call :Echo.Color 0f "   Airstrikes: "
call :Echo.Color 70 " %cpuairstrike% "
echo.
echo.
call :Echo.Color 0f "   Missiles:   "
call :Echo.Color 70 " %cpumissiles% "
echo.
echo.
call :Echo.Color 0f "   Workers:    "
call :Echo.Color 70 " %cpufortify% "
echo.
echo.
if '%cpupackage%'=='0' call :Echo.Color 0c "   Note: Care Package Unavaliable."
if '%cpupackage%'=='1' call :Echo.Color 0a "   Note: Care Package Avaliable!"
echo.
echo.
echo Options:
echo.
echo    1. Fire NUKE
echo.
echo    2. Fire Airstrike
echo.
echo    3. Fire Missiles
echo.
echo    4. Surrender
echo.
echo    5. Fortify Your Structures
echo.
echo    OR enter C to call in your care package!
echo.
echo    Select your option:
echo.
call :Echo.Color 0e "      ?"
ping localhost -n 1 >nul
goto cpu1
:cpu2
cls
set /a choice=%random% %%6
if '%choice%'=='4' goto cpu2
if '%choice%'=='6' goto cpu2
echo.
call :Echo.Color 0d "CPU's turn..."
echo.
echo.
call :Echo.Color 0c "%country%: "
call :Echo.Color 8e "   %user% DEF    "
echo.
call :Echo.Color 0a "%enemy%: "
call :Echo.Color 8e "   %cpu% DEF    "
echo.
echo.
echo Arsenal:
echo.
echo.
call :Echo.Color 0f "   Nukes:      "
call :Echo.Color 70 " %cpunuke% "
echo.
echo.
call :Echo.Color 0f "   Airstrikes: "
call :Echo.Color 70 " %cpuairstrike% "
echo.
echo.
call :Echo.Color 0f "   Missiles:   "
call :Echo.Color 70 " %cpumissiles% "
echo.
echo.
call :Echo.Color 0f "   Workers:    "
call :Echo.Color 70 " %cpufortify% "
echo.
echo.
if '%cpupackage%'=='0' call :Echo.Color 0c "   Note: Care Package Unavaliable."
if '%cpupackage%'=='1' call :Echo.Color 0a "   Note: Care Package Avaliable!"
echo.
echo.
echo Options:
echo.
echo    1. Fire NUKE
echo.
echo    2. Fire Airstrike
echo.
echo    3. Fire Missiles
echo.
echo    4. Surrender
echo.
echo    5. Fortify Your Structures
echo.
echo    OR enter C to call in your care package!
echo.
echo Select your option: %choice%
ping localhost -n 4 >nul
set /a cpucount=%cpucount% - 5
if '%choice%'=='0' goto cpucarepackage
if '%choice%'=='1' goto cpunuke
if '%choice%'=='2' goto cpuairstrike
if '%choice%'=='3' goto cpumissiles
if '%choice%'=='5' goto cpufortify
:cpunuke
cls
if '%cpunuke%'=='0' goto nocpunuke
echo.
echo I have fired a NUKE headed towards %country%!
echo.
start /MAX img nuke.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %country% has lost 400 DEF!
echo.
ping localhost -n 4 >nul
set /a user=%user% - 400
set cpunuke=0
if '%user%'=='0' goto cpuwin
if '%user%'=='-100' goto cpuwin
if '%user%'=='-200' goto cpuwin
if '%user%'=='-300' goto cpuwin
goto gameplay
:nocpunuke
echo.
echo I can't use a nuke since I don't have any more left!
echo.
ping localhost -n 4 >nul
set cpucount=0
goto cpu1
:cpuairstrike
cls
if '%cpuairstrike%'=='0' goto nocpuairstrike
echo.
echo I have fired an airstrike on %country%!
echo.
start /MAX img airstrike.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %country% has lost 300 DEF!
echo.
ping localhost -n 4 >nul
set /a user=%user% - 300
set /a cpuairstrike=%cpuairstrike% - 1
if '%user%'=='0' goto cpuwin
if '%user%'=='-100' goto cpuwin
if '%user%'=='-200' goto cpuwin
if '%user%'=='-300' goto cpuwin
goto gameplay
:nocpuairstrike
echo.
echo I can't use an airstrike since I don't have any more left!
echo.
ping localhost -n 4 >nul
set cpucount=0
goto cpu1
:cpumissiles
cls
if '%cpumissiles%'=='0' goto nocpumissiles
echo.
echo I have fired multiple missiles headed towards %country%!
echo.
start /MAX img missile.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %country% has lost 200 DEF!
echo.
ping localhost -n 4 >nul
set /a user=%user% - 200
set /a cpumissiles=%cpumissiles% - 1
if '%user%'=='0' goto cpuwin
if '%user%'=='-100' goto cpuwin
if '%user%'=='-200' goto cpuwin
if '%user%'=='-300' goto cpuwin
goto gameplay
:nocpumissiles
echo.
echo I can't use missiles since I don't have any more left!
echo.
ping localhost -n 4 >nul
set cpucount=0
goto cpu1
:cpufortify
cls
if '%cpufortify%'=='0' goto cpunofortify
echo.
echo %enemy% has foritfied their base, they lost 1 worker in the process.
echo.
start /MAX img fortify.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Fortification complete!
echo.
echo %enemy% has gained 500 DEF!
echo.
pause
set /a cpu=%cpu% + 500
set /a cpufortify=%cpufortify% - 1
goto gameplay
:cpunofortify
echo.
echo I can't fortify my structures again since I have run out of workers.
echo.
pause
goto cpu1
:cpucarepackage
cls
if '%cpupackage%'=='0' goto cpunocarepackage
echo.
echo %enemy% has called in their care package!
echo.
:cpucarepackagegive
set /a cpureward=%cpurandom% %%6
if '%cpureward%'=='0' goto cpucarepackagegive
if '%cpureward%'=='1' goto cpucarepackagegive
if '%cpureward%'=='2' goto cpucarepackagegive
if '%cpureward%'=='3' set /a cpunuke=%cpunuke% + 1
if '%cpureward%'=='4' set /a cpuairstrike=%cpuairstrike% + 1
if '%cpureward%'=='5' set /a cpumissiles=%cpumissiles% + 1
if '%cpureward%'=='6' set /a cpufortify=%cpufortify% + 1
start /MAX img package.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo.
echo %enemy%'s care package has arrived, and will be opened on their next turn.
echo.
pause
set /a cpupackage=%cpupackage% - 1
goto gameplay
:cpunocarepackage
echo.
echo My care package is unavaliable.
echo.
pause
goto cpu1
:cpuwin
cls
start /MAX img surrender.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo.
echo It was a long battle today. I have emerged victorious, even though you tried
echo very well.
echo.
pause
:cpuwin2
cls
echo.
echo It was a long battle today. I have emerged victorious, even though you tried
echo very well.
echo.
set /p replay=Type anything to replay the game. Type 'x' to exit:
if '%replay%'=='x' goto suggest
if '%replay%'=='' goto cpuwin2
goto players
:p1name
cls
set p1name=
echo.
set /p p1name=Player 1, please type in your name (One word):
if '%p1name%'=='' goto p1name
:p2name
cls
set p2name=
echo.
set /p p2name=Player 2, please type in your name (One word):
if '%p2name%'=='%p1name%' goto p2name
if '%p2name%'=='' goto p2name
rem Easter Egg:
if '%p1name%'=='IAmVincent' goto p1win
if '%p1name%'=='IAmSam' goto p1win
if '%p2name%'=='IAmVincent' goto p2win
if '%p2name%'=='IAmSam' goto p2win
:p1country
cls
set p1country=
echo.
echo Welcome %p1name%!
echo.
set /p p1country=Choose your country; USA, Russia, or Japan:
if '%p1country%'=='usa' goto p1country1
if '%p1country%'=='USA' goto p1country1
if '%p1country%'=='Usa' goto p1country1
if '%p1country%'=='Russia' goto p1country2
if '%p1country%'=='russia' goto p1country2
if '%p1country%'=='Japan' goto p1country3
if '%p1country%'=='japan' goto p1country3
goto p1country
:p1country1
set p1country=USA   
goto p2country
:p1country2
set p1country=Russia
goto p2country
:p1country3
set p1country=Japan
:p2country
cls
set p2country=
echo.
echo Welcome %p2name%!
echo.
set /p p2country=Choose your country; USA, Russia, or Japan:
if '%p2country%'=='%p1country%' goto na
if '%p2country%'=='usa' goto p2country1
if '%p2country%'=='USA' goto p2country1
if '%p2country%'=='Usa' goto p2country1
if '%p2country%'=='Russia' goto p2country2
if '%p2country%'=='russia' goto p2country2
if '%p2country%'=='Japan' goto p2country3
if '%p2country%'=='japan' goto p2country3
goto p2country
:na
cls
echo.
echo You can't choose %p1country% because %p1name% has already chosen it.
pause >nul
goto p2country
:p2country1
set p2country=USA   
goto begin2
:p2country2
set p2country=Russia
goto begin2
:p2country3
set p2country=Japan
:begin2
set p1health=1000
set p2health=1000
set p1nuke=1
set p1airstrike=2
set p1missiles=3
set p2nuke=1
set p2airstrike=2
set p2missiles=3
:p1gameplay
cls
set move=
set choice=
echo.
call :Echo.Color 0e "%p1name%, your turn."
echo.
call :Echo.Color 0a "                                          %country%: "
call :Echo.Color 8e "%user% DEF"
echo.
echo Options:
call :Echo.Color 0c "                                          %enemy%: "
call :Echo.Color 8e "%cpu% DEF"
echo.
echo 1. Fire NUKE x %p1nuke%
echo.
echo 2. Fire Airstrike x %p1airstrike%
echo.
echo 3. Fire Missiles x %p1missiles%
echo.
echo 4. Surrender
echo.
echo 5. Do nothing
echo.
set /p move=Select your option:
if '%move%'=='1' goto p1nuke
if '%move%'=='2' goto p1airstrike
if '%move%'=='3' goto p1missiles
if '%move%'=='4' goto p1surrender
if '%move%'=='5' goto p1fortify
goto p1gameplay
:p1nuke
cls
if '%p1nuke%'=='0' goto nop1nuke
echo.
echo %p1name% has fired a NUKE headed towards %p2country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p2country% has lost 400 DEF!
echo.
pause
set /a p2health=%p2health% - 400
set p1nuke=0
if '%p2health%'LEQ'0 goto p1win
if '%p2health%'=='-100' goto p1win
if '%p2health%'=='-200' goto p1win
if '%p2health%'=='-300' goto p1win
goto p2gameplay
:nop1nuke
echo.
echo You can't use a nuke since you don't have any more left!
echo.
pause
goto p1gameplay
:p1airstrike
cls
if '%p1airstrike%'=='0' goto nop1airstrike
echo.
echo %p1name% has fired an airstrike on %p2country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p2country% has lost 300 DEF!
echo.
pause
set /a p2health=%p2health% - 300
set /a p1airstrike=%p1airstrike% - 1
if '%p2health%'=='0' goto p1win
if '%p2health%'=='-100' goto p1win
if '%p2health%'=='-200' goto p1win
if '%p2health%'=='-300' goto p1win
goto p2gameplay
:nop1airstrike
echo.
echo You can't use an airstrike since you don't have any more left!
echo.
pause
goto p1gameplay
:p1missiles
cls
if '%p1missiles%'=='0' goto nop1missiles
echo.
echo %p1name% has fired multiple missiles headed towards %p2country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p2country% has lost 200 DEF!
echo.
pause
set /a p2health=%p2health% - 200
set /a p1missiles=%p1missiles% - 1
if '%p2health%'=='0' goto p1win
if '%p2health%'=='-100' goto p1win
if '%p2health%'=='-200' goto p1win
if '%p2health%'=='-300' goto p1win
goto p2gameplay
:nop1missiles
echo.
echo You can't use missiles since you don't have any more left!
echo.
pause
goto p1gameplay
:p1fortify
cls
if '%p1fortify%'=='0' goto nop1fortify
echo.
echo %p1name% has foritfied their base, they lost 1 worker in the process.
echo.
ping localhost -n 4 >nul
echo Fortification complete!
echo.
echo %p1country% has gained 100 DEF!
echo.
pause
set /a p1health=%p1health% + 100
set /a cpuforitfy=%cpufortify% - 1
goto p1gameplay
:nop1fortify
echo.
echo You can't fortify your structures again since I have run out of workers.
echo.
pause
goto cpu1
:p1surrender
cls
echo.
echo %p2name% has won Total War!!!
echo.
pause
:p1surrender2
cls
echo.
echo %p2name% has won Total War!!!
echo.
set /p replay=Type anything to replay the game. Type 'x' to exit:
if '%replay%'=='x' goto suggest
if '%replay%'=='' goto p1surrender2
goto players
:p1win
cls
echo.
echo %p1name% has won Total War!!!
echo.
pause
:p1win2
cls
echo.
echo %p1name% has won Total War!!!
echo.
set /p replay=Type anything to replay the game. Type 'x' to exit:
if '%replay%'=='x' goto suggest
if '%replay%'=='' goto p1win2
goto players
:p2gameplay
cls
set move=
set choice=
echo.
call :Echo.Color 04 "%p2name%, your turn."
echo.
call :Echo.Color 0a "                                          %country%: "
call :Echo.Color 8e "%user% DEF"
echo.
echo Options:
call :Echo.Color 0c "                                          %enemy%: "
call :Echo.Color 8e "%cpu% DEF"
echo.
echo 1. Fire NUKE x %p2nuke%
echo.
echo 2. Fire Airstrike x %p2airstrike%
echo.
echo 3. Fire Missiles x %p2missiles%
echo.
echo 4. Surrender
echo.
echo 5. Do nothing
echo.
set /p move=Select your option:
if '%move%'=='1' goto p2nuke
if '%move%'=='2' goto p2airstrike
if '%move%'=='3' goto p2missiles
if '%move%'=='4' goto p2surrender
if '%move%'=='5' goto p1gameplay
goto p2gameplay
:p2nuke
cls
if '%p2nuke%'=='0' goto nop2nuke
echo.
echo %p2name% has fired a NUKE headed towards %p1country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p1country% has lost 400 DEF!
echo.
pause
set /a p1health=%p1health% - 400
set p2nuke=0
if '%p1health%'=='0' goto p2win
if '%p1health%'=='-100' goto p2win
if '%p1health%'=='-200' goto p2win
if '%p1health%'=='-300' goto p2win
goto p1gameplay
:nop2nuke
echo.
echo You can't use a nuke since you don't have any more left!
echo.
pause
goto p2gameplay
:p2airstrike
cls
if '%p2airstrike%'=='0' goto nop2airstrike
echo.
echo %p2name% has fired an airstrike on %p1country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p1country% has lost 300 DEF!
echo.
pause
set /a p1health=%p1health% - 300
set /a p2airstrike=%p2airstrike% - 1
if '%p1health%'=='0' goto p2win
if '%p1health%'=='-100' goto p2win
if '%p1health%'=='-200' goto p2win
if '%p1health%'=='-300' goto p2win
goto p1gameplay
:nop2airstrike
echo.
echo You can't use an airstrike since you don't have any more left!
echo.
pause
goto p2gameplay
:p2missiles
cls
if '%p2missiles%'=='0' goto nop2missiles
echo.
echo %p2name% has fired multiple missiles headed towards %p1country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p1country% has lost 200 DEF!
echo.
pause
set /a p1health=%p1health% - 200
set /a p2missiles=%p2missiles% - 1
if '%p1health%'=='0' goto p2win
if '%p1health%'=='-100' goto p2win
if '%p1health%'=='-200' goto p2win
if '%p1health%'=='-300' goto p2win
goto p1gameplay
:nop2missiles
echo.
echo You can't use missiles since you don't have any more left!
echo.
pause
goto p2gameplay
:p2fortify
cls
if '%p2fortify%'=='0' goto nop2fortify
echo.
echo %p2name% has foritfied their base, they lost 1 worker in the process.
echo.
ping localhost -n 4 >nul
echo Fortification complete!
echo.
echo %p2country% has gained 100 DEF!
echo.
pause
set /a p2health=%p2health% + 100
set /a cpuforitfy=%cpufortify% - 1
goto p2gameplay
:nop2fortify
echo.
echo You can't fortify your structures again since I have run out of workers.
echo.
pause
goto cpu2
:p2surrender
cls
echo.
echo %p1name% has won Total War!!!
echo.
pause
:p2surrender2
cls
echo.
echo %p1name% has won Total War!!!
echo.
set /p replay=Type anything to replay the game. Type 'x' to exit:
if '%replay%'=='x' goto suggest
if '%replay%'=='' goto p2surrender2
goto players
:p2win
cls
echo.
echo %p2name% has won Total War!!!
echo.
pause
:p2win2
cls
echo.
echo %p2name% has won Total War!!!
echo.
set /p replay=Type anything to replay the game. Type 'x' to exit:
if '%replay%'=='x' goto suggest
if '%replay%'=='' goto p2win2
goto players
:suggest
cls
echo.
echo Before you leave, can you suggest a country I can add to the file?
echo.
set /p suggestion=Suggest a country here:
if '%suggestion%'=='' goto suggest
echo %suggestion% >> suggestions.txt
exit /b
:# The following line must be last and not end by a CRLF.
-

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Program crashing after input

#2 Post by foxidrive » 08 May 2014 19:30

When using this style of input it is more robust, in all input sections.

A) the quotes when clearing the variables stop trailing spaces from interfering
B) the quotes in the IF compares protect the code from spaces

The /i in the IF compare also makes the compare case insensitive.

Code: Select all

:country
cls
set "country="
set "enemy="
echo.
echo Welcome %name%, to Total War!
echo.
set /p "country=Choose your country; USA, Russia, or Japan: "
if /i "%country%"=="usa" goto enemy1
if /i "%country%"=="russia" goto enemy2
if /i "%country%"=="japan" goto enemy3
goto country

sambeevors
Posts: 6
Joined: 08 May 2014 11:43

Re: Program crashing after input

#3 Post by sambeevors » 09 May 2014 02:10

It still doesn't work, the game still crashes :(

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Program crashing after input

#4 Post by foxidrive » 09 May 2014 03:09

sambeevors wrote:It still doesn't work, the game still crashes :(


Where? All your input routines have the same issue.

Use a pause command at places where it branches to and find out which part is causing the error.

sambeevors
Posts: 6
Joined: 08 May 2014 11:43

Re: Program crashing after input

#5 Post by sambeevors » 09 May 2014 03:32

After the country has been inputted, it pops up with ='USA' not expected

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Program crashing after input

#6 Post by foxidrive » 09 May 2014 03:47

sambeevors wrote:After the country has been inputted, it pops up with ='USA' not expected


I checked just one line of your code - this line has trailing spaces.

Code: Select all

set country=USA   

sambeevors
Posts: 6
Joined: 08 May 2014 11:43

Re: Program crashing after input

#7 Post by sambeevors » 09 May 2014 03:54

By that do you mean extra spaces at the end of the code? Because that is intentional (unless that's the cause of the crashing in which case I'll just have to find another way around it)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Program crashing after input

#8 Post by foxidrive » 09 May 2014 04:56

After USA there are spaces, and there were more in another line I checked.

Batch code has to be written to handle spaces... which my first reply does. It won't fail if spaces are added when typing the input.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Program crashing after input

#9 Post by foxidrive » 09 May 2014 05:09

See if this works any better - the replacement of most single quotes with double quotes may help,
but it can't be tested without the images.

Code: Select all

@echo off
color 0f
title TOTAL WAR!!!
setlocal
call :Echo.Color.Init
goto main
:Echo.Color %1=Color %2=Str [%3=/n]
setlocal enableDelayedExpansion
set "str=%~2"
:Echo.Color.2
:# Replace path separators in the string, so that the final path still refers to the current path.
set "str=a%ECHO.DEL%!str:\=a%ECHO.DEL%\..\%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%!"
set "str=!str:/=a%ECHO.DEL%/..\%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%!"
set "str=!str:"=\"!"
:# Go to the script directory and search for the trailing -
pushd "%ECHO.DIR%"
findstr /p /r /a:%~1 "^^-" "!str!\..\!ECHO.FILE!" nul
popd
:# Remove the name of this script from the output. (Dependant on its length.)
for /l %%n in (1,1,12) do if not "!ECHO.FILE:~%%n!"=="" <nul set /p "=%ECHO.DEL%"
:# Remove the other unwanted characters "\..\: -"
<nul set /p "=%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%%ECHO.DEL%"
:# Append the optional CRLF
if not "%~3"=="" echo.
endlocal & goto :eof
:Echo.Color.Var %1=Color %2=StrVar [%3=/n]
if not defined %~2 goto :eof
setlocal enableDelayedExpansion
set "str=!%~2!"
goto :Echo.Color.2
:Echo.Color.Init
set "ECHO.COLOR=call :Echo.Color"
set "ECHO.DIR=%~dp0"
set "ECHO.FILE=%~nx0"
set "ECHO.FULL=%ECHO.DIR%%ECHO.FILE%"
:# Use prompt to store a backspace into a variable. (Actually backspace+space+backspace)
for /F "tokens=1 delims=#" %%a in ('"prompt #$H# & echo on & for %%b in (1) do rem"') do set "ECHO.DEL=%%a"
goto :eof
:main
echo.
echo Welcome to Total War, created by Vincent Allain and Sam Beevors.
echo.
pause
:players
cls
set player=
set replay=
echo.
set /p player=Select 1 or 2 player mode:
if "%player%"=="1" goto name
if "%player%"=="2" goto apology
:apology
echo I am sorry, multiplayer is still a Work In Progress...
ping localhost -n 4 >nul
cls
goto players
:name
cls
set name=
echo.
set /p name=Please type in your name (One word):   
if "%name%"=="" goto name
:country
cls
set country=
set enemy=
echo.
echo Welcome %name%, to Total War!
echo.
set /p country=Choose your country; USA, Russia, or Japan:
if "%country%"=="usa" goto enemy1
if "%country%"=="USA" goto enemy1
if "%country%"=="Usa" goto enemy1
if "%country%"=="Russia" goto enemy2
if "%country%"=="russia" goto enemy2
if "%country%"=="japan" goto enemy3
if "%country%"=="Japan" goto enemy3
goto country
:enemy1
set country=USA   
goto enemy
:enemy2
set country=Russia
goto enemy
:enemy3
set country=Japan
:enemy
set /a cpucountryrand=%random% %%5 +1
if "%cpucountryrand%"=="0" goto enemy
if "%cpucountryrand%"=="1" set enemy=Russia
if "%cpucountryrand%"=="2" set enemy=USA   
if "%cpucountryrand%"=="3" set enemy=Japan
if "%cpucountryrand%"=="4" goto enemy
if "%cpucountryrand%"=="5" goto enemy
if "%enemy%"=="%country%" goto enemy
:begin
set user=1200
set cpu=1200
set nuke=1
set airstrike=3
set missiles=6
set fortify=2
set package=1
set cpunuke=1
set cpuairstrike=3
set cpumissiles=6
set cpufortify=2
set cpupackage=1
:gameplay
cls
color 0f
set move=
set choice=
set cpucount=0
echo.
call :Echo.Color 0b "%name%, your turn."
echo.
echo.
call :Echo.Color 0a "%country%: "
call :Echo.Color 8e "   %user% DEF    "
echo.
call :Echo.Color 0c "%enemy%: "
call :Echo.Color 8e "   %cpu% DEF    "
echo.
echo.
echo Arsenal:
echo.
echo.
call :Echo.Color 0f "   Nukes:      "
call :Echo.Color 70 " %nuke% "
echo.
echo.
call :Echo.Color 0f "   Airstrikes: "
call :Echo.Color 70 " %airstrike% "
echo.
echo.
call :Echo.Color 0f "   Missiles:   "
call :Echo.Color 70 " %missiles% "
echo.
echo.
call :Echo.Color 0f "   Workers:    "
call :Echo.Color 70 " %fortify% "
echo.
echo.
if "%package%"=="0" call :Echo.Color 0c "   Note: Care Package Unavaliable."
if "%package%"=="1" call :Echo.Color 0a "   Note: Care Package Avaliable!"
echo.
echo.
echo Options:
echo.
echo    1. Fire NUKE
echo.
echo    2. Fire Airstrike
echo.
echo    3. Fire Missiles
echo.
echo    4. Surrender
echo.
echo    5. Fortify Your Structures
echo.
echo    OR enter C to call in your care package!
echo.
set /p move=   Select your option:
if "%move%"=="1" goto nuke
if "%move%"=="2" goto airstrike
if "%move%"=="3" goto missiles
if "%move%"=="4" goto surrender
if "%move%"=="5" goto fortify
if "%move%"=="c" goto carepackage
if "%move%"=="C" goto carepackage
if "%move%"=="warneverchanges" set /a nuke=%nuke% + 9999
goto gameplay
:nuke
cls
if "%nuke%"=="0" goto nonuke
echo.
echo %name% has fired a NUKE headed towards %enemy%!
echo.
start /MAX img nuke.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %enemy% has lost 400 DEF!
echo.
pause
set /a cpu=%cpu% - 400
set nuke=0
if "%cpu%"=="0" goto win
if "%cpu%"=="-100" goto win
if "%cpu%"=="-200" goto win
if "%cpu%"=="-300" goto win
goto cpu1
:nonuke
echo.
echo You can't use a nuke since you don't have any more left!
echo.
pause
goto gameplay
:airstrike
cls
if "%airstrike%"=="0" goto noairstrike
echo.
echo %name% has fired an airstrike on %enemy%!
echo.
start /MAX img airstrike.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %enemy% has lost 300 DEF!
echo.
pause
set /a cpu=%cpu% - 300
set /a airstrike=%airstrike% - 1
if "%cpu%"=="0" goto win
if "%cpu%"=="-100" goto win
if "%cpu%"=="-200" goto win
if "%cpu%"=="-300" goto win
goto cpu1
:noairstrike
echo.
echo You can't use an airstrike since you don't have any more left!
echo.
pause
goto gameplay
:missiles
cls
if "%missiles%"=="0" goto nomissiles
echo.
echo %name% has fired multiple missiles headed towards %enemy%!
echo.
start /MAX img missile.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %enemy% has lost 200 DEF!
echo.
pause
set /a cpu=%cpu% - 200
set /a missiles=%missiles% - 1
if "%cpu%"=="0" goto win
if "%cpu%"=="-100" goto win
if "%cpu%"=="-200" goto win
if "%cpu%"=="-300" goto win
goto cpu1
:nomissiles
echo.
echo You can't use missiles since you don't have any more left!
echo.
pause
goto gameplay
:fortify
cls
if "%fortify%"=="0" goto nofortify
echo.
echo %name% has foritfied their base, they lost 1 worker in the process.
echo.
start /MAX img fortify.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Fortification complete!
echo.
echo %name% has gained 500 DEF!
echo.
pause
set /a user=%user% + 500
set /a fortify=%fortify% - 1
goto cpu1
:nofortify
echo.
echo You can't fortify your structures again since you have run out of workers.
echo.
pause
goto gameplay
:carepackage
cls
if "%package%"=="0" goto nocarepackage
echo.
echo %name% has called in their care package!
echo.
:carepackagegive
set /a reward=%random% %%6
if "%reward%"=="0" goto carepackagegive
if "%reward%"=="1" goto carepackagegive
if "%reward%"=="2" goto carepackagegive
if "%reward%"=="3" set /a nuke=%nuke% + 1
if "%reward%"=="4" set /a airstrike=%airstrike% + 1
if "%reward%"=="5" set /a missiles=%missiles% + 1
if "%reward%"=="6" set /a fortify=%fortify% + 1
start /MAX img package.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo.
echo %name%"s care package has arrived, and will be opened on their next turn.
echo.
pause
set /a package=%package% - 1
goto cpu1
:nocarepackage
echo.
echo Your care package is unavaliable.
echo.
pause
goto gameplay
:surrender
cls
start /MAX img surrender.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo.
echo "We may have lost the war, but we still have our dignity..."
echo.
pause
:end
cls
echo.
echo "We may have lost the war, but we still have our dignity..."
echo.
set /p replay=Type anything to replay the game. Type "x" to exit:
if "%replay%"=="x" goto suggest
if "%replay%"=="" goto end
goto players
:win
cls
echo.
echo You have won Total War!!!
echo.
pause
:win2
cls
echo.
echo You have won Total War!!!
echo.
set /p replay=Type anything to replay the game. Type "x" to exit:
if "%replay%"=="x" goto suggest
if "%replay%"=="" goto win2
goto players
:cpu1
cls
set /a cpucount=%cpucount% + 1
if "%cpucount%"=="5" goto cpu2
echo.
call :Echo.Color 0d "CPU's turn..."
echo.
echo.
call :Echo.Color 0c "%country%: "
call :Echo.Color 8e "   %user% DEF    "
echo.
call :Echo.Color 0a "%enemy%: "
call :Echo.Color 8e "   %cpu% DEF    "
echo.
echo.
echo Arsenal:
echo.
echo.
call :Echo.Color 0f "   Nukes:      "
call :Echo.Color 70 " %cpunuke% "
echo.
echo.
call :Echo.Color 0f "   Airstrikes: "
call :Echo.Color 70 " %cpuairstrike% "
echo.
echo.
call :Echo.Color 0f "   Missiles:   "
call :Echo.Color 70 " %cpumissiles% "
echo.
echo.
call :Echo.Color 0f "   Workers:    "
call :Echo.Color 70 " %cpufortify% "
echo.
echo.
if "%cpupackage%"=="0" call :Echo.Color 0c "   Note: Care Package Unavaliable."
if "%cpupackage%"=="1" call :Echo.Color 0a "   Note: Care Package Avaliable!"
echo.
echo.
echo Options:
echo.
echo    1. Fire NUKE
echo.
echo    2. Fire Airstrike
echo.
echo    3. Fire Missiles
echo.
echo    4. Surrender
echo.
echo    5. Fortify Your Structures
echo.
echo    OR enter C to call in your care package!
echo.
echo    Select your option:
echo.
call :Echo.Color 0b "      ?"
ping localhost -n 1 >nul
cls
echo.
call :Echo.Color 0d "CPU's turn..."
echo.
echo.
call :Echo.Color 0c "%country%: "
call :Echo.Color 8e "   %user% DEF    "
echo.
call :Echo.Color 0a "%enemy%: "
call :Echo.Color 8e "   %cpu% DEF    "
echo.
echo.
echo Arsenal:
echo.
echo.
call :Echo.Color 0f "   Nukes:      "
call :Echo.Color 70 " %cpunuke% "
echo.
echo.
call :Echo.Color 0f "   Airstrikes: "
call :Echo.Color 70 " %cpuairstrike% "
echo.
echo.
call :Echo.Color 0f "   Missiles:   "
call :Echo.Color 70 " %cpumissiles% "
echo.
echo.
call :Echo.Color 0f "   Workers:    "
call :Echo.Color 70 " %cpufortify% "
echo.
echo.
if "%cpupackage%"=="0" call :Echo.Color 0c "   Note: Care Package Unavaliable."
if "%cpupackage%"=="1" call :Echo.Color 0a "   Note: Care Package Avaliable!"
echo.
echo.
echo Options:
echo.
echo    1. Fire NUKE
echo.
echo    2. Fire Airstrike
echo.
echo    3. Fire Missiles
echo.
echo    4. Surrender
echo.
echo    5. Fortify Your Structures
echo.
echo    OR enter C to call in your care package!
echo.
echo    Select your option:
echo.
echo.
call :Echo.Color 0d "      ?"
ping localhost -n 1 >nul
cls
echo.
call :Echo.Color 0d "CPU's turn..."
echo.
echo.
call :Echo.Color 0c "%country%: "
call :Echo.Color 8e "   %user% DEF    "
echo.
call :Echo.Color 0a "%enemy%: "
call :Echo.Color 8e "   %cpu% DEF    "
echo.
echo.
echo Arsenal:
echo.
echo.
call :Echo.Color 0f "   Nukes:      "
call :Echo.Color 70 " %cpunuke% "
echo.
echo.
call :Echo.Color 0f "   Airstrikes: "
call :Echo.Color 70 " %cpuairstrike% "
echo.
echo.
call :Echo.Color 0f "   Missiles:   "
call :Echo.Color 70 " %cpumissiles% "
echo.
echo.
call :Echo.Color 0f "   Workers:    "
call :Echo.Color 70 " %cpufortify% "
echo.
echo.
if "%cpupackage%"=="0" call :Echo.Color 0c "   Note: Care Package Unavaliable."
if "%cpupackage%"=="1" call :Echo.Color 0a "   Note: Care Package Avaliable!"
echo.
echo.
echo Options:
echo.
echo    1. Fire NUKE
echo.
echo    2. Fire Airstrike
echo.
echo    3. Fire Missiles
echo.
echo    4. Surrender
echo.
echo    5. Fortify Your Structures
echo.
echo    OR enter C to call in your care package!
echo.
echo    Select your option:
echo.
call :Echo.Color 0e "      ?"
ping localhost -n 1 >nul
goto cpu1
:cpu2
cls
set /a choice=%random% %%6
if "%choice%"=="4" goto cpu2
if "%choice%"=="6" goto cpu2
echo.
call :Echo.Color 0d "CPU's turn..."
echo.
echo.
call :Echo.Color 0c "%country%: "
call :Echo.Color 8e "   %user% DEF    "
echo.
call :Echo.Color 0a "%enemy%: "
call :Echo.Color 8e "   %cpu% DEF    "
echo.
echo.
echo Arsenal:
echo.
echo.
call :Echo.Color 0f "   Nukes:      "
call :Echo.Color 70 " %cpunuke% "
echo.
echo.
call :Echo.Color 0f "   Airstrikes: "
call :Echo.Color 70 " %cpuairstrike% "
echo.
echo.
call :Echo.Color 0f "   Missiles:   "
call :Echo.Color 70 " %cpumissiles% "
echo.
echo.
call :Echo.Color 0f "   Workers:    "
call :Echo.Color 70 " %cpufortify% "
echo.
echo.
if "%cpupackage%"=="0" call :Echo.Color 0c "   Note: Care Package Unavaliable."
if "%cpupackage%"=="1" call :Echo.Color 0a "   Note: Care Package Avaliable!"
echo.
echo.
echo Options:
echo.
echo    1. Fire NUKE
echo.
echo    2. Fire Airstrike
echo.
echo    3. Fire Missiles
echo.
echo    4. Surrender
echo.
echo    5. Fortify Your Structures
echo.
echo    OR enter C to call in your care package!
echo.
echo Select your option: %choice%
ping localhost -n 4 >nul
set /a cpucount=%cpucount% - 5
if "%choice%"=="0" goto cpucarepackage
if "%choice%"=="1" goto cpunuke
if "%choice%"=="2" goto cpuairstrike
if "%choice%"=="3" goto cpumissiles
if "%choice%"=="5" goto cpufortify
:cpunuke
cls
if "%cpunuke%"=="0" goto nocpunuke
echo.
echo I have fired a NUKE headed towards %country%!
echo.
start /MAX img nuke.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %country% has lost 400 DEF!
echo.
ping localhost -n 4 >nul
set /a user=%user% - 400
set cpunuke=0
if "%user%"=="0" goto cpuwin
if "%user%"=="-100" goto cpuwin
if "%user%"=="-200" goto cpuwin
if "%user%"=="-300" goto cpuwin
goto gameplay
:nocpunuke
echo.
echo I can't use a nuke since I don't have any more left!
echo.
ping localhost -n 4 >nul
set cpucount=0
goto cpu1
:cpuairstrike
cls
if "%cpuairstrike%"=="0" goto nocpuairstrike
echo.
echo I have fired an airstrike on %country%!
echo.
start /MAX img airstrike.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %country% has lost 300 DEF!
echo.
ping localhost -n 4 >nul
set /a user=%user% - 300
set /a cpuairstrike=%cpuairstrike% - 1
if "%user%"=="0" goto cpuwin
if "%user%"=="-100" goto cpuwin
if "%user%"=="-200" goto cpuwin
if "%user%"=="-300" goto cpuwin
goto gameplay
:nocpuairstrike
echo.
echo I can't use an airstrike since I don't have any more left!
echo.
ping localhost -n 4 >nul
set cpucount=0
goto cpu1
:cpumissiles
cls
if "%cpumissiles%"=="0" goto nocpumissiles
echo.
echo I have fired multiple missiles headed towards %country%!
echo.
start /MAX img missile.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Hit!
echo.
echo %country% has lost 200 DEF!
echo.
ping localhost -n 4 >nul
set /a user=%user% - 200
set /a cpumissiles=%cpumissiles% - 1
if "%user%"=="0" goto cpuwin
if "%user%"=="-100" goto cpuwin
if "%user%"=="-200" goto cpuwin
if "%user%"=="-300" goto cpuwin
goto gameplay
:nocpumissiles
echo.
echo I can't use missiles since I don't have any more left!
echo.
ping localhost -n 4 >nul
set cpucount=0
goto cpu1
:cpufortify
cls
if "%cpufortify%"=="0" goto cpunofortify
echo.
echo %enemy% has foritfied their base, they lost 1 worker in the process.
echo.
start /MAX img fortify.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo Fortification complete!
echo.
echo %enemy% has gained 500 DEF!
echo.
pause
set /a cpu=%cpu% + 500
set /a cpufortify=%cpufortify% - 1
goto gameplay
:cpunofortify
echo.
echo I can't fortify my structures again since I have run out of workers.
echo.
pause
goto cpu1
:cpucarepackage
cls
if "%cpupackage%"=="0" goto cpunocarepackage
echo.
echo %enemy% has called in their care package!
echo.
:cpucarepackagegive
set /a cpureward=%cpurandom% %%6
if "%cpureward%"=="0" goto cpucarepackagegive
if "%cpureward%"=="1" goto cpucarepackagegive
if "%cpureward%"=="2" goto cpucarepackagegive
if "%cpureward%"=="3" set /a cpunuke=%cpunuke% + 1
if "%cpureward%"=="4" set /a cpuairstrike=%cpuairstrike% + 1
if "%cpureward%"=="5" set /a cpumissiles=%cpumissiles% + 1
if "%cpureward%"=="6" set /a cpufortify=%cpufortify% + 1
start /MAX img package.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo.
echo %enemy%"s care package has arrived, and will be opened on their next turn.
echo.
pause
set /a cpupackage=%cpupackage% - 1
goto gameplay
:cpunocarepackage
echo.
echo My care package is unavaliable.
echo.
pause
goto cpu1
:cpuwin
cls
start /MAX img surrender.jpg
ping localhost -n 4 >nul
taskkill /im mspaint.exe >nul
echo.
echo It was a long battle today. I have emerged victorious, even though you tried
echo very well.
echo.
pause
:cpuwin2
cls
echo.
echo It was a long battle today. I have emerged victorious, even though you tried
echo very well.
echo.
set /p replay=Type anything to replay the game. Type "x" to exit:
if "%replay%"=="x" goto suggest
if "%replay%"=="" goto cpuwin2
goto players
:p1name
cls
set p1name=
echo.
set /p p1name=Player 1, please type in your name (One word):
if "%p1name%"=="" goto p1name
:p2name
cls
set p2name=
echo.
set /p p2name=Player 2, please type in your name (One word):
if "%p2name%"=="%p1name%" goto p2name
if "%p2name%"=="" goto p2name
rem Easter Egg:
if "%p1name%"=="IAmVincent" goto p1win
if "%p1name%"=="IAmSam" goto p1win
if "%p2name%"=="IAmVincent" goto p2win
if "%p2name%"=="IAmSam" goto p2win
:p1country
cls
set p1country=
echo.
echo Welcome %p1name%!
echo.
set /p p1country=Choose your country; USA, Russia, or Japan:
if "%p1country%"=="usa" goto p1country1
if "%p1country%"=="USA" goto p1country1
if "%p1country%"=="Usa" goto p1country1
if "%p1country%"=="Russia" goto p1country2
if "%p1country%"=="russia" goto p1country2
if "%p1country%"=="Japan" goto p1country3
if "%p1country%"=="japan" goto p1country3
goto p1country
:p1country1
set p1country=USA   
goto p2country
:p1country2
set p1country=Russia
goto p2country
:p1country3
set p1country=Japan
:p2country
cls
set p2country=
echo.
echo Welcome %p2name%!
echo.
set /p p2country=Choose your country; USA, Russia, or Japan:
if "%p2country%"=="%p1country%" goto na
if "%p2country%"=="usa" goto p2country1
if "%p2country%"=="USA" goto p2country1
if "%p2country%"=="Usa" goto p2country1
if "%p2country%"=="Russia" goto p2country2
if "%p2country%"=="russia" goto p2country2
if "%p2country%"=="Japan" goto p2country3
if "%p2country%"=="japan" goto p2country3
goto p2country
:na
cls
echo.
echo You can't choose %p1country% because %p1name% has already chosen it.
pause >nul
goto p2country
:p2country1
set p2country=USA   
goto begin2
:p2country2
set p2country=Russia
goto begin2
:p2country3
set p2country=Japan
:begin2
set p1health=1000
set p2health=1000
set p1nuke=1
set p1airstrike=2
set p1missiles=3
set p2nuke=1
set p2airstrike=2
set p2missiles=3
:p1gameplay
cls
set move=
set choice=
echo.
call :Echo.Color 0e "%p1name%, your turn."
echo.
call :Echo.Color 0a "                                          %country%: "
call :Echo.Color 8e "%user% DEF"
echo.
echo Options:
call :Echo.Color 0c "                                          %enemy%: "
call :Echo.Color 8e "%cpu% DEF"
echo.
echo 1. Fire NUKE x %p1nuke%
echo.
echo 2. Fire Airstrike x %p1airstrike%
echo.
echo 3. Fire Missiles x %p1missiles%
echo.
echo 4. Surrender
echo.
echo 5. Do nothing
echo.
set /p move=Select your option:
if "%move%"=="1" goto p1nuke
if "%move%"=="2" goto p1airstrike
if "%move%"=="3" goto p1missiles
if "%move%"=="4" goto p1surrender
if "%move%"=="5" goto p1fortify
goto p1gameplay
:p1nuke
cls
if "%p1nuke%"=="0" goto nop1nuke
echo.
echo %p1name% has fired a NUKE headed towards %p2country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p2country% has lost 400 DEF!
echo.
pause
set /a p2health=%p2health% - 400
set p1nuke=0
if "%p2health%"LEQ"0 goto p1win
if "%p2health%"=="-100" goto p1win
if "%p2health%"=="-200" goto p1win
if "%p2health%"=="-300" goto p1win
goto p2gameplay
:nop1nuke
echo.
echo You can't use a nuke since you don't have any more left!
echo.
pause
goto p1gameplay
:p1airstrike
cls
if "%p1airstrike%"=="0" goto nop1airstrike
echo.
echo %p1name% has fired an airstrike on %p2country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p2country% has lost 300 DEF!
echo.
pause
set /a p2health=%p2health% - 300
set /a p1airstrike=%p1airstrike% - 1
if "%p2health%"=="0" goto p1win
if "%p2health%"=="-100" goto p1win
if "%p2health%"=="-200" goto p1win
if "%p2health%"=="-300" goto p1win
goto p2gameplay
:nop1airstrike
echo.
echo You can't use an airstrike since you don't have any more left!
echo.
pause
goto p1gameplay
:p1missiles
cls
if "%p1missiles%"=="0" goto nop1missiles
echo.
echo %p1name% has fired multiple missiles headed towards %p2country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p2country% has lost 200 DEF!
echo.
pause
set /a p2health=%p2health% - 200
set /a p1missiles=%p1missiles% - 1
if "%p2health%"=="0" goto p1win
if "%p2health%"=="-100" goto p1win
if "%p2health%"=="-200" goto p1win
if "%p2health%"=="-300" goto p1win
goto p2gameplay
:nop1missiles
echo.
echo You can't use missiles since you don't have any more left!
echo.
pause
goto p1gameplay
:p1fortify
cls
if "%p1fortify%"=="0" goto nop1fortify
echo.
echo %p1name% has foritfied their base, they lost 1 worker in the process.
echo.
ping localhost -n 4 >nul
echo Fortification complete!
echo.
echo %p1country% has gained 100 DEF!
echo.
pause
set /a p1health=%p1health% + 100
set /a cpuforitfy=%cpufortify% - 1
goto p1gameplay
:nop1fortify
echo.
echo You can't fortify your structures again since I have run out of workers.
echo.
pause
goto cpu1
:p1surrender
cls
echo.
echo %p2name% has won Total War!!!
echo.
pause
:p1surrender2
cls
echo.
echo %p2name% has won Total War!!!
echo.
set /p replay=Type anything to replay the game. Type "x" to exit:
if "%replay%"=="x" goto suggest
if "%replay%"=="" goto p1surrender2
goto players
:p1win
cls
echo.
echo %p1name% has won Total War!!!
echo.
pause
:p1win2
cls
echo.
echo %p1name% has won Total War!!!
echo.
set /p replay=Type anything to replay the game. Type "x" to exit:
if "%replay%"=="x" goto suggest
if "%replay%"=="" goto p1win2
goto players
:p2gameplay
cls
set move=
set choice=
echo.
call :Echo.Color 04 "%p2name%, your turn."
echo.
call :Echo.Color 0a "                                          %country%: "
call :Echo.Color 8e "%user% DEF"
echo.
echo Options:
call :Echo.Color 0c "                                          %enemy%: "
call :Echo.Color 8e "%cpu% DEF"
echo.
echo 1. Fire NUKE x %p2nuke%
echo.
echo 2. Fire Airstrike x %p2airstrike%
echo.
echo 3. Fire Missiles x %p2missiles%
echo.
echo 4. Surrender
echo.
echo 5. Do nothing
echo.
set /p move=Select your option:
if "%move%"=="1" goto p2nuke
if "%move%"=="2" goto p2airstrike
if "%move%"=="3" goto p2missiles
if "%move%"=="4" goto p2surrender
if "%move%"=="5" goto p1gameplay
goto p2gameplay
:p2nuke
cls
if "%p2nuke%"=="0" goto nop2nuke
echo.
echo %p2name% has fired a NUKE headed towards %p1country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p1country% has lost 400 DEF!
echo.
pause
set /a p1health=%p1health% - 400
set p2nuke=0
if "%p1health%"=="0" goto p2win
if "%p1health%"=="-100" goto p2win
if "%p1health%"=="-200" goto p2win
if "%p1health%"=="-300" goto p2win
goto p1gameplay
:nop2nuke
echo.
echo You can't use a nuke since you don't have any more left!
echo.
pause
goto p2gameplay
:p2airstrike
cls
if "%p2airstrike%"=="0" goto nop2airstrike
echo.
echo %p2name% has fired an airstrike on %p1country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p1country% has lost 300 DEF!
echo.
pause
set /a p1health=%p1health% - 300
set /a p2airstrike=%p2airstrike% - 1
if "%p1health%"=="0" goto p2win
if "%p1health%"=="-100" goto p2win
if "%p1health%"=="-200" goto p2win
if "%p1health%"=="-300" goto p2win
goto p1gameplay
:nop2airstrike
echo.
echo You can't use an airstrike since you don't have any more left!
echo.
pause
goto p2gameplay
:p2missiles
cls
if "%p2missiles%"=="0" goto nop2missiles
echo.
echo %p2name% has fired multiple missiles headed towards %p1country%!
echo.
ping localhost -n 4 >nul
echo Hit!
echo.
echo %p1country% has lost 200 DEF!
echo.
pause
set /a p1health=%p1health% - 200
set /a p2missiles=%p2missiles% - 1
if "%p1health%"=="0" goto p2win
if "%p1health%"=="-100" goto p2win
if "%p1health%"=="-200" goto p2win
if "%p1health%"=="-300" goto p2win
goto p1gameplay
:nop2missiles
echo.
echo You can't use missiles since you don't have any more left!
echo.
pause
goto p2gameplay
:p2fortify
cls
if "%p2fortify%"=="0" goto nop2fortify
echo.
echo %p2name% has foritfied their base, they lost 1 worker in the process.
echo.
ping localhost -n 4 >nul
echo Fortification complete!
echo.
echo %p2country% has gained 100 DEF!
echo.
pause
set /a p2health=%p2health% + 100
set /a cpuforitfy=%cpufortify% - 1
goto p2gameplay
:nop2fortify
echo.
echo You can't fortify your structures again since I have run out of workers.
echo.
pause
goto cpu2
:p2surrender
cls
echo.
echo %p1name% has won Total War!!!
echo.
pause
:p2surrender2
cls
echo.
echo %p1name% has won Total War!!!
echo.
set /p replay=Type anything to replay the game. Type "x" to exit:
if "%replay%"=="x" goto suggest
if "%replay%"=="" goto p2surrender2
goto players
:p2win
cls
echo.
echo %p2name% has won Total War!!!
echo.
pause
:p2win2
cls
echo.
echo %p2name% has won Total War!!!
echo.
set /p replay=Type anything to replay the game. Type "x" to exit:
if "%replay%"=="x" goto suggest
if "%replay%"=="" goto p2win2
goto players
:suggest
cls
echo.
echo Before you leave, can you suggest a country I can add to the file?
echo.
set /p suggestion=Suggest a country here:
if "%suggestion%"=="" goto suggest
echo %suggestion% >> suggestions.txt
exit /b
:# The following line must be last and not end by a CRLF.
-

sambeevors
Posts: 6
Joined: 08 May 2014 11:43

Re: Program crashing after input

#10 Post by sambeevors » 09 May 2014 05:20

It now crashes when it is the CPU's turn :?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Program crashing after input

#11 Post by foxidrive » 09 May 2014 05:33

What is the error message?

sambeevors
Posts: 6
Joined: 08 May 2014 11:43

Re: Program crashing after input

#12 Post by sambeevors » 09 May 2014 07:06

The syntax of the command is incorrect

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Program crashing after input

#13 Post by foxidrive » 09 May 2014 07:39

Try the code above again - it has been edited.

Post Reply