#1 21 Oct 2016 05:16

Realskull
Member
Registered: 06 Apr 2016
Posts: 22

BUG fixing (Please help to debug/correct this code)

i am trying to make a game that is called World War 0.2 HERE's the code

@echo off
title ~ World War I ~
color 17

:menu
cls
echo =====================================================
echo =                  World War I                      =
echo =                                                   =
echo =           (1) Start a war                         =
echo =           (2) Read Help page                      =
echo =           (3) Exit                                =
echo =====================================================
choice /c:123 /n >nul
if %errorlevel% == 1 goto startwar
if %errorlevel% == 2 goto inthelp        
if %errorlevel% == 3 exit

:inthelp
set pg=1
goto help

:help
if not exist == help%pg%.txt goto menu
cls
echo                Help Page %pg%.
for /f "delims=*" %%a in (help%pg%.txt) do (
echo %%a
)
pause
set /a pg+=1
goto help

:startwar
cls
echo =====================================================
echo =              Start A war                          =
echo =====================================================
set /p co1= Country 1:
set /p co2= Country 2:
goto co1t

:co1t
cls
echo =====================================================
echo =       Choose country 1 type                       =
echo = (1) U.S.A - 150troops.99% success rate of         =
echo = attacking, high HP troops. 1000 score.            =
echo =                                                   =
echo = (2) Germany - 200 Maxtroops. 100% success rate of =
echo = attacking, meduim hp troops. War win 1800 score   =
echo =                                                   =
echo = (3) Nepal - 500Maxtroops.100% wise sucess rate    =
echo = of attacking, low hp troops. War win 2400 score   =
echo =====================================================
choice /c:123 /n >nul
if %errorlevel% == 1 goto chooseusa1
if %errorlevel% == 2 goto chooseger1
if %errorlevel% == 3 goto choosenep1

:choosenep1
cls
echo =====================================================
echo =    Number of troops?500 max                       =
echo =====================================================
set /p c1t=
if %c1t% GTR 500 set c1t=500
set c1hp=130
set cc1hp=%c1hp%
set c1dmg=10
goto co2t

:chooseusa1
cls
echo =====================================================
echo =    Number of troops? 60-150                       =
echo =====================================================
set /p c1t=
if %c1t% GTR 150 set c15=150
set c1hp=140
set cc1hp=%c1hp%
set c1dmg=13
goto co2t

:chooseger1
cls
echo =====================================================
echo =    Number of troops? 50-180                       =
echo =====================================================
set /p c1t=
if %c1t% GTR 180 set c1t=180
set c1hp=135
set cc1hp=%c1hp%
set c1dmg=12
goto co2t

:co2t
cls
echo =====================================================
echo =       Choose country 2 type                       =
echo = (1) U.S.A - 60-150 troops.99% success rate of     =
echo = attacking, high HP troops. 1000 score.            =
echo =                                                   =
echo = (2) Germany - 50-180 troops. 100% success rate of =
echo = attacking, meduim hp troops. War win 1800 score   =
echo =                                                   =
echo = (3) Nepal - 400-500 troops.100% wise sucess rate  =
echo = of attacking, low hp troops. War win 2400 score   =
echo =====================================================
choice /c:123 /n >nul
if %errorlevel% == 1 goto chooseusa2
if %errorlevel% == 2 goto chooseger2
if %errorlevel% == 3 goto choosenep2

:choosenep2
cls
echo =====================================================
echo =    Number of troops?400-500                       =
echo =====================================================
set /p c2t=
if %c2t% GTR 500 set c2t=500
set c2hp=130
set cc2hp=%c2hp%
set c2dmg=10
goto war

:chooseusa2
cls
echo =====================================================
echo =    Number of troops? 60-150                       =
echo =====================================================
set /p c2t=
if %c2t% GTR 150 set c2t=150
set c2hp=140
set cc2hp=%c2hp%
set c2dmg=13
goto war

:chooseger2
cls
echo =====================================================
echo =    Number of troops? 50-180                       =
echo =====================================================
set /p c2t=
if %c2t% GTR 180 set c2t=180
set c2hp=135
set cc2hp=%c2hp%
set c2dmg=12
goto war


:war
set c1left=%c1t%
set c2left=%c2t%
set c1d=0
set c2d=0
goto warsim

:warsim
cls
if %c1d% GTR %c1t% goto win2
if %c2d% GTR %c2t% goto win1
echo =====================================================
echo = Country - %co1%         VS    Country - %co2%     
echo = Total Troops - %c1t%    ==  Total Troops - %c2t%  
echo = Troops Dead - %c1d%     ==  Troops Dead - %c2d%    
echo = Troops Left - %c1left%  == Troops left - %c2left% 
echo = Enemies killed - %c2d%  == Enemies killed - %c1d% 
echo =====================================================
ping localhost -n 1 >nul
:: Troop 1 turn 
if %cc2hp% LEQ 0 (
set cc2hp=!c2hp!
set /a c2d+=1
set /a c2left-=1 )
set /a cc2hp-=%c1dmg%
:: Troop 2 turn
if %cc1hp% LEQ 0 (
set cc1hp=%c1hp%
set /a c1d+=1
set /a c1left-=1 )
set /a cc1hp-=%c2dmg%
goto warsim

:win2
cls
echo =====================================================
echo                  War Results:                       =
echo = Country - %co1%         VS    Country - %co2%     =
echo = Total Troops - %c1t%    ==  Total Troops - %c2t%  =
echo = Troops Dead - %c1d%     ==  Troops Dead - %c2d%   =
echo = Troops Left - %c1left%  == Troops left - %c2left% =
echo = Enemies killed - %c2d%  == Enemies killed - %c1d% =
echo =           Victory for   %co2%!                    =
echo =====================================================
pause
goto menu

:win1
cls
echo =====================================================
echo                  War Results:                       =
echo = Country - %co1%         VS    Country - %co2%     =
echo = Total Troops - %c1t%    ==  Total Troops - %c2t%  =
echo = Troops Dead - %c1d%     ==  Troops Dead - %c2d%   =
echo = Troops Left - %c1left%  == Troops left - %c2left% =
echo = Enemies killed - %c2d%  == Enemies killed - %c1d% =
echo =           Victory for   %co1%!                    =
echo =====================================================


PROBLEM: It works upto the warsim label. It simulates but when every troop dies in player 2 (EXAMPLE) player 1 should win and show label win1 BUT IT CLOSES?

(Ignore the :help label)

Offline

#2 21 Oct 2016 09:37

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 139

Re: BUG fixing (Please help to debug/correct this code)

Because you don't have a

pause
goto menu

at the end of the script.

Online

#3 21 Oct 2016 11:08

Realskull
Member
Registered: 06 Apr 2016
Posts: 22

Re: BUG fixing (Please help to debug/correct this code)

big_smile  HA im stupid

anyway thanks

Offline

Board footer

Powered by FluxBB