Batch File: War Game

by I♥BatchFiles in Circuits > Microsoft

1932 Views, 8 Favorites, 0 Comments

Batch File: War Game

War Pic.png

Hello!

I'm I♥BatchFiles!

I upload a new batch file project every other day. Next batch file project will be on 5/26/16.

How to use this code:

  1. Open Notepad and Paste the code below into it.
  2. Click File
  3. Click Save as
  4. Save it as War.bat
  5. Change Text Documents to All Files
  6. Hit Save
  7. Now find it in Windows Explorer (that little folder icon) and open it

Batch File War Game

@echo off

:menu
color 0f
cls
echo WAR
echo Version 1.1
echo Created by Me
echo 1. Start game
echo 2. Exit
choice /c:12 /n > nul
if errorlevel 2 goto sure
if errorlevel 1 goto start
:start
:oneplayer
set /a health = 1000
set /a money = 1000
set /a otherhealth = 1000
set /a until = 2
set /a cherrybomb = 50
set /a cherrybombcost = 300
set /a missile = 100
set /a missilecost = 500
set /a nuke = 200
set /a nukecost = 700
set /a lightpotion = 100
set /a lightpotioncost = 200
set /a heavypotion = 500
set /a heavypotioncost = 700
set /a defaultcherries = 3
set /a defaultmissiles = 2
set /a defaultnukes = 4
set /a defaultlights = 5
set /a defaultheavies = 7
set land
set /a times = 0
cls
echo Choose your land:
echo A. Atropolis - land of the jungle
echo B. Aquadatic - land of the sea
echo C. Drylands - land of the desert
echo D. Greenleaves - land of the prairie
choice /c:abcd /n > nul
if errorlevel 1 (
set /a land = 1
)
if errorlevel 2 (
set /a land = 2
)
if errorlevel 3 (
set /a land = 3
)
if errorlevel 4 (
set /a land = 4
)
if %land%==1 set it=Atropolis
if %land%==2 set it=Aquadatic
if %land%==3 set it=Drylands
if %land%==4 set it=Greenleaves
:choose
REM Choosing opponent's land
set /a otherland=%random% %% 4+1
if %otherland%==%land% (
goto choose
)
if %otherland%==1 set theirit=Atropolis
if %otherland%==2 set theirit=Aquadatic
if %otherland%==3 set theirit=Drylands
if %otherland%==4 set theirit=Greenleaves
REM Creating new variable to set as opponent's land
:game
if %health% LSS 1 goto lose
cls
echo %it%
echo.
echo You are fighting %theirit%
echo.
echo %theirit%'s health: %otherhealth%
echo.
echo.
echo Your Health: %health%
echo Your Money: %money%
echo Nukes: %defaultnukes%
echo Missiles: %defaultmissiles%
echo Cherry Bombs: %defaultcherries%
echo.
echo Choose:
echo 1. Drop a nuke (%defaultnukes%)
echo 2. Launch a missile (%defaultmissiles%)
echo 3. Drop a cherry bomb :P (%defaultcherries%)
echo 4. Open shop
echo 5. Drink a light health potion (%defaultlights%)
echo 6. Drink a heavy health potion (%defaultheavies%)
echo 7. Complete a quest
choice /c:1234567 /n > nul
if errorlevel 7 goto quest
if errorlevel 6 goto heavy
if errorlevel 5 goto light
if errorlevel 4 goto shop
if errorlevel 3 goto cherry
if errorlevel 2 goto missile
if errorlevel 1 goto nuke
:nuke
if %defaultnukes% GTR 0 (
set /a otherhealth = %otherhealth%-%nuke%
set /a defaultnukes = %defaultnukes%-1
cls
echo %it% dropped a nuke on %theirit%!
echo %theirit% lost 200 health!
ping localhost -n 5 >nul
goto other
)else (
cls
echo You cannot drop any nukes since you have 0.
ping localhost -n 5 >nul
goto game
)

:missile
if %defaultmissiles% GTR 0 (
set /a otherhealth = %otherhealth%-%missile%
set /a defaultmissiles=%defaultmissiles%-1
cls
echo %it% launched a missile on %theirit%!
echo %theirit% lost 100 health!
ping localhost -n 5 >nul
goto other
)else (
cls
echo You cannot launch any missiles since you have 0.
ping localhost -n 5 >nul
goto game
)

:cherry
if %defaultcherries% GTR 0 (
set /a otherhealth = %otherhealth%-%cherrybomb%
set /a defaultcherries = %defaultcherries%-1
cls
echo %it% dropped a cherry bomb on %theirit%!
echo %theirit% lost 50 health!
ping localhost -n 5 >nul
goto other
)else (
cls
echo You cannot drop any cherry bombs since you have 0.
ping localhost -n 5 >nul
goto game
)
:light
if %defaultlights% GTR 0 (
set /a health = %health%+100
set /a defaultlight = %defaultlight%-1
cls
echo You drink a light health potion
echo Now it is %theirit%'s turn.
ping localhost -n 5 >nul
goto other
)else (
cls
echo You have no light health potions
ping localhost -n 5 >nul
)
:heavy
if %defaultheavies% GTR 0 (
set /a health = %health%+%heavypotion%
set /a defaultheavies = %defaultheavies%-1
cls
echo You drink a heavy health potion
echo Now it is %theirit%'s turn.
ping localhost -n 5 >nul
goto other
)else (
cls
echo You have no heavy health potions
ping localhost -n 5 >nul
)
:shop
cls
echo Welcome to the shop
echo Money: %money%
echo 1. Buy Nuke
echo    Cost: %nukecost%
echo    Damage: %nuke%
echo.
echo 2. Buy Missile
echo    Cost: %missilecost%
echo    Damage: %missile%
echo.
echo 3. Buy Cherry Bomb
echo    Cost: %cherrybombcost%
echo    Damage: %cherrybomb%
echo.
echo 4. Buy Light Health Potion
echo    Cost: %lightpotioncost%
echo    Heals: %lightpotion%
echo.
echo 5. Buy Heavy Health Potion
echo    Cost: %heavypotioncost%
echo    Heals: %heavypotion%
echo.
echo 6. Leave store
choice /C:123456 /n > nul
if errorlevel 6 goto game
if errorlevel 5 goto buyheavy
if errorlevel 4 goto buylight
if errorlevel 3 goto buycherry
if errorlevel 2 goto buymissile
if errorlevel 1 goto buynuke
:buynuke
set /a money = %money%-%nukecost%
if %money% LSS 0 (
set /a money = %money%+%nukecost%
echo You don't have enough money
ping localhost -n 5 >nul
)else (
set /a defaultnukes = %defaultnukes%+1
echo You have bought one nuke
ping localhost -n 5 >nul
goto shop
)

:buymissile
set /a money = %money%-%missilecost%
if %money% LSS 0 (
set /a money = %money%+%missilecost%
echo You don't have enough money
ping localhost -n 5 >nul
)else (
set /a defaultmissiles = %defaultmissiles%+1
echo You have bought one missile
ping localhost -n 5 >nul
goto shop
)

:buycherry
set /a money = %money%-%cherrybombcost%
if %money% LSS 0 (
set /a money = %money%+%cherrybombcost%
echo You don't have enough money
ping localhost -n 5 >nul
)else (
set /a defaultcherries = %defaultcherries%+1
echo You have bought one cherry bomb
ping localhost -n 5 >nul
goto shop
)

:buylight
set /a money = %money%-%lightpotioncost%
if %money% LSS 0 (
set /a money = %money%+%lightpotioncost%
echo You don't have enough money
ping localhost -n 5 >nul
)else (
set /a defaultlights = %defaultlights%+1
echo You have bought one light potion
ping localhost -n 5 >nul
goto shop
)

:buyheavy
set /a money = %money%-%heavypotioncost%
if %money% LSS 0 (
set /a money = %money%+%heavypotioncost%
echo You don't have enough money
ping localhost -n 5 >nul
)else (
set /a defaultheavies = %defaultheavies%+1
echo You have bought one heavy potion
ping localhost -n 5 >nul
goto shop
)

:other
cls
set /a until = until - 1
if %otherhealth% LSS 1 (
goto win
)
echo Your opponent is choosing what to do
ping localhost -n 5 >nul
set /a theirchoose=%random% %% 3+1
if %theirchoose%==1 (
cls
set /a health=%health%-200
echo News: %theirit% decides to nuke you! You lose 200 health.
)
if %theirchoose%==2 (
cls
echo News: %theirit% decides to launch a missile at you! You lose 100 health.
set /a health=%health%-100
)
if %theirchoose%==3 (
cls
echo News: %theirit% decides to put cherry bombs on your windows. Some how you lose 50 health.
set /a health=%health%-50
)
if %until%==0 (
echo Also, %theirit% uses their specially designed potion that no one else has. They gain 200 health.
set /a otherhealth=%otherhealth%+200
set /a until=2
)
set /a times = 0
pause
goto game

:sure
cls
echo Are you sure you want to quit?
echo 1. Yes
echo 2. No
choice /c:12 /n > nul
if errorlevel 2 goto menu
if errorlevel 1 exit
:win
cls
echo You win!
pause
goto menu
:lose
cls
echo Sorry you lose :(
pause
goto menu
:quest
cls
if %times% == 1 (
echo You have already completed a quest in this turn
pause
goto game
)
set /a times = %times% + 1
echo Complete this quest to earn money
echo Yeah this isnt really a quest, its more like a quiz but whatever
echo.
echo Press S to start
choice /c:s /n > nul
if errorlevel 1 goto pick
:pick
cls
set /a question=%random% %% 6+1
if %question%==1 goto qo
if %question%==2 goto qtw
if %question%==3 goto qt
if %question%==4 goto qfo
if %question%==5 goto qf
if %question%==6 goto qs
:qo
cls
echo How much money do you have in this game?
set /p answer=(Please do not put any spaces in your answer or it will shut down and no labels):
if %answer%==%money% (
cls
echo Correct; You earn +300 money
ping localhost -n 5 >nul
set /a money=%money%+300
goto game
)else (
cls
echo Incorrect
ping localhost -n 5 >nul
goto game
)
:qtw
cls
echo What is the other team's name?
set /p answer=(Please do not put any spaces in your answer or it will shut down):
if %answer%==%theirit% (
cls
echo Correct; You earn +700 money
ping localhost -n 5 >nul
set /a money=%money%+700
goto game
)else (
cls
echo Incorrect
ping localhost -n 5 >nul
goto game
)
:qt
cls
echo How much does a cherry bomb cost?
set /p answer=(Please do not put any spaces in your answer or it will shut down and no labels):
if %answer%==%cherrybombcost% (
cls
echo Correct; You earn +500 money
ping localhost -n 5 >nul
set /a money=%money%+500
goto game
)else (
cls
echo Incorrect
ping localhost -n 5 >nul
goto game
)
:qfo
cls
echo What is 40 + 20?
set /p answer=(Please do not put any spaces in your answer or it will shut down):
if %answer%==60 (
cls
echo Correct; You earn +300 money
ping localhost -n 5 >nul
set /a money=%money%+300
goto game
)else (
cls
echo Incorrect
ping localhost -n 5 >nul
goto game
)
:qf
cls
echo What is the fourth option in the store?
echo Choose:
echo 1. Missile
echo 2. Light Potion
echo 3. Nuke
choice /c:123 /n > nul
if errorlevel 3 goto incorrect
if errorlevel 2 goto correct
if errorlevel 1 goto incorrect
:incorrect
cls
echo Incorrect
ping localhost -n 5 >nul
goto game
:correct
cls
echo Correct; You earn +600 money
set /a money=%money%+600
ping localhost -n 5 >nul
goto game
:qs
cls
echo Where does your opponent decide to put cherry bombs on? (This is the hardest question)
set /p answer=(Please do not put any spaces in your answer or it will shut down; just one word answer):
if %answer%==windows (
cls
echo Correct; You earn +900 money
ping localhost -n 5 >nul
set /a money=%money%+900
goto game
)else (
cls
echo Incorrect
ping localhost -n 5 >nul
goto game
)