Loading...

Batch File Game – Guess The Number

Hey Folks!! Welcome to another tutorial of Batch File Programming, In case you don’t know what batch file programming is, its the backbone ...


Hey Folks!! Welcome to another tutorial of Batch File Programming, In case you don’t know what batch file programming is, its the backbone to the windows operating system to tweak and manipulate anything that you wish. Its the most important tool for creating simple viruses just with a help of notepad. But today we are gonna create batch file games just to improve your batch file creating skills and it is also fun to play games once in a while.
Just save the following code through notepad and save it as a batch file and run it.
————————————————————————————————————————-
@echo off
color 0e
title Guessing Game!
:try again
set /a guessnum=0
set /a answer=%random%
set variable1=lulz
echo Loading.
ping localhost -n 2 >nul
cls
echo Loading..
ping localhost -n 2 >nul
cls
echo Loading...
ping localhost -n 2 >nul
cls
echo #################################################
echo #Welcome to the kingofdkingz's Guessing game! #
echo.# #
echo #Try and Guess a Random Number #
echo #################################################
echo.
:top
echo.
set /p guess=
echo.
if %guess% GTR %answer% ECHO Lower!
if %guess% LSS %answer% ECHO Higher!
if %guess%==%answer% GOTO EQUAL
set /a guessnum=%guessnum% +1
if %guess%==%variable1% ECHO OMFG U found teh secret!!!!!11one: %answer%
goto top
:equal
echo ************************************************
echo #You guessed the number! Congratulations! #
echo.# #
echo #You used %guessnum% times to guess the number!
echo ************************************************
echo Made by kingofdkingz
echo Try Again?
set /a guessnum=0
pause
echo #################################################
echo.# New Round! #
echo # Try and Guess a Random Number #
echo #################################################
goto :top
————————————————————————————————————————-
Reactions: 

Post a Comment

  1. @echo off
    :j
    set ran=%random:~-2%
    if "%ran:~1%"=="" set ran=0%ran%
    set /a ran=1%ran%-99
    echo ===================
    echo Random Number Game
    echo ===================
    echo Guess the integer between 1 and 100.
    echo You have 7 guesses.
    echo Type r to restart.
    :a
    set /p guess="Guess One:"
    set x=1
    if %guess%==%ran% goto end
    if %guess%==r cls && goto j
    if 101 LEQ %guess% echo Invalid number! && goto a
    if 0 GEQ %guess% echo Invalid number! && goto a
    if %ran% GTR %guess% echo The number is greater than %guess% && goto b
    if %ran% LSS %guess% echo The number is less than %guess% && goto b
    echo Invalid number!
    goto a
    :b
    set /p guess="Guess Two:"
    set x=2
    if %guess%==%ran% goto end
    if %guess%==r cls && goto j
    if 101 LEQ %guess% echo Invalid number! && goto b
    if 0 GEQ %guess% echo Invalid number! && goto b
    if %ran% GTR %guess% echo The number is greater than %guess% && goto c
    if %ran% LSS %guess% echo The number is less than %guess% && goto c
    echo Invalid number!
    goto b
    :c
    set /p guess="Guess Three:"
    set x=3
    if %guess%==%ran% goto end
    if %guess%==r cls && goto j
    if 101 LEQ %guess% echo Invalid number! && goto c
    if 0 GEQ %guess% echo Invalid number! && goto c
    if %ran% GTR %guess% echo The number is greater than %guess% && goto d
    if %ran% LSS %guess% echo The number is less than %guess% && goto d
    echo Invalid number!
    goto c
    :d
    set /p guess="Guess Four:"
    set x=4
    if %guess%==%ran% goto end
    if %guess%==r cls && goto j
    if 101 LEQ %guess% echo Invalid number! && goto d
    if 0 GEQ %guess% echo Invalid number! && goto d
    if %ran% GTR %guess% echo The number is greater than %guess% && goto e
    if %ran% LSS %guess% echo The number is less than %guess% && goto e
    echo Invalid number!
    goto d
    :e
    set /p guess="Guess Five:"
    set x=5
    if %guess%==%ran% goto end
    if %guess%==r cls && goto j
    if 101 LEQ %guess% echo Invalid number! && goto e
    if 0 GEQ %guess% echo Invalid number! && goto e
    if %ran% GTR %guess% echo The number is greater than %guess% && goto f
    if %ran% LSS %guess% echo The number is less than %guess% && goto f
    echo Invalid number!
    goto e
    :f
    set /p guess="Guess Six:"
    set x=6
    if %guess%==%ran% goto end
    if %guess%==r cls && goto j
    if 101 LEQ %guess% echo Invalid number! && goto f
    if 0 GEQ %guess% echo Invalid number! && goto f
    if %ran% GTR %guess% echo The number is greater than %guess% && goto g
    if %ran% LSS %guess% echo The number is less than %guess% && goto g
    echo Invalid number!
    goto f
    :g
    set /p guess="Guess Seven:"
    set x=7
    if %guess%==%ran% goto end
    if %guess%==r cls && goto j
    if 101 LEQ %guess% echo Invalid number! && goto g
    if 0 GEQ %guess% echo Invalid number! && goto g
    if %ran% GTR %guess% echo The number is greater than %guess% && goto h
    if %ran% LSS %guess% echo The number is less than %guess% && goto h
    echo Invalid number!
    goto g
    :h
    echo Game Over! The number was %ran%.
    set /p again="Try again? (y/n):"
    if %again%==y cls && goto j
    if %again%==n echo :(
    exit
    :end
    echo Well Done! The number was %ran%. You got it in %x% guesses.
    set /p again="Play again? (y/n):"
    if %again%==y cls && goto j
    if %again%==n echo :(
    exit

    ReplyDelete

emo-but-icon

Home item

Follow by Email

Recommend on Google

Advertisements

Advertisements

Popular Posts

Random Posts

Recent Posts

ADS

eXTReMe Tracker