Instructables

Simple batch game

Here's a simple .bat game. It's not that good, but at least you'll have something to do when bored. :P
PS.: If you find any way to improve this code or any bugs/mistakes, please let me know by commenting down below.
Code:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

@echo off

:Start1
cls
echo Let's play a game!
echo It's called NUMBER!
echo For settings, type "Sets"
echo Choose any number
echo between 1 and 10:
set /p choice1=
if %choice1%==Sets goto Settings
for /l %%G in (1,1,10) do if %choice1%==%%G goto Add
echo Choose between 1
echo and 10!!
ping localhost -n >nul 3
goto Start1

:Add
if %choice1%==10 goto Tie
set one=1
set /a result=%choice1%+%one%
echo.
echo I choose %result%!
echo I win!
ping localhost -n >nul 3
goto Again1

:Tie
echo.
echo I choose 10!
echo Tie!
ping localhost -n >nul 3
goto Again1

:Again1
cls
echo.
echo Wanna play again? (y/n)
set /p answer=
if %answer%==y goto Start1
if %answer%==n exit
echo Choose y or n!
ping localhost -n >nul 3
goto Again1

:Settings
cls
echo.
echo Settings menu
echo -=-=-=-=-=-=-
echo 1) Always winning
echo 2) Always losing
set /p input=
if %input%==1 goto Win
if %input%==2 goto Loss
echo Choose 1 or 2!
ping localhost -n >nul 3
goto Settings

:Loss
echo Set to always losing.
ping localhost -n >nul 3
goto Start1

:Win
echo Set to always wining.
ping localhost -n >nul 3
goto Start2

:Start2
cls
echo Let's play a game!
echo It's called NUMBER!
echo For settings, type "Sets"
echo Choose any number
echo between 1 and 10:
set /p choice2=
if %choice2%==Sets goto Settings
for /l %%G in (1,1,10) do if %choice2%==%%G goto Sub
echo Choose between 1
echo and 10!!
ping localhost -n >nul 3
goto Start2

:Sub
if %choice2%==1 goto Tie
set one=1
set /a result=%choice2%-%one%
echo.
echo I choose %result%!
echo You win!
ping localhost -n >nul 3
goto Again2

:Tie
echo.
echo I choose 1!
echo Tie!
ping localhost -n >nul 3
goto Again2

:Again2
cls
echo.
echo Wanna play again? (y/n)
set /p answer2=
if %answer2%==y goto Start2
if %answer2%==n exit
echo Choose y or n!
ping localhost -n >nul 3
goto Again2

:Again1
cls
echo.
echo Wanna play again? (y/n)
set /p answer=
if %answer%==y goto Start1
if %answer%==n exit
echo Choose y or n!
ping localhost -n >nul 3
goto Again1

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Tetheu98 (author) 1 year ago
Well, I have just started with Batch and I'm not a pro (yet! :D), and this is my first "mini-batch-based-game", so it's not that good.
But guessing the number would be very easy, because when you have a variable written by the user (for example: set /p "input="), %input% becomes the value typed. For example, in the code above:

echo Choose any number
echo between 1 and 10:
set /p choice1=

If I typed 2, %choice1% would become 2. So guessing would be very easy, just by having "echo %input%". Please explain with more details if I didn't understand it right. :P
P.S: I could also make a Step by Step if you want
Well, some instructions would have been nice....

To be honest, this game isn't good at all. The scripting and readability of the code isn't great either.

May I suggest a new game:

You pick a number between 1 and whatever, and then the computer has to guess it.

I would make it myself but I got the inspiration from your instructable, so it's your call.

If you don't want to make it, let me know.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!