My game isn't working could anyone look at the code?

June 15, 2013 at 15:18:18
Specs: Windows XP
@echo off


:opening
title Lotto Game
echo Type the number of what you wish to choose
echo ------------------------------------------
echo.
echo 1) Play
echo.
echo 2) Instructions
echo.
echo 3) Exit
echo.
echo ------------------------------------------
pathping localhost -q 2 -p 250 > nul
pathping localhost -q 2 -p 250 > nul
pathping localhost -q 2 -p 250 > nul
set /p choice=""
if %choice% == 1 goto inputnumber

if %choice% == 2 goto instructions

if %choice% == 3 goto leave

:inputnumber
cls
echo.
echo Numbers are 1 to 50
echo.
set /p firstnumber="1st Number:"
echo.
set /p secondnumber="2nd Number:"
echo.
set /p thirdnumber="3rd Number:"
echo.
set /p fourthnumber="4th Number:"
echo.
set /p fifthnumber="5th Number:"
echo Click [ ENTER ]
pause > nul


:play1
cls
echo Generating the first Lottery Number...
pathping localhost -q 2 -p 100 > nul
:loop1
set num=%random%
if /i %num% GTR 50 goto loop1
if /i %num% LSS 1 goto loop1
goto finish1
:finish1
cls
echo Lottery number is %num%
pause > nul
echo Click [ ENTER ]
if %num% == %firstnumber% goto play2
else if %num% NEQ %firstnumber% goto loser

:play2
cls
echo Generating the second Lottery Number...
pathping localhost -q 2 -p 100 > nul
:loop2
set num2=%random%
if /i %num2% GTR 50 goto loop2
if /i %num2% LSS 1 goto loop2
goto finish2
:finish2
cls
echo Lottery number is %num2%
echo Click [ ENTER ]
pause > nul
if %num2% == %secondnumber% goto play3
else if %num2% NEQ %secondnumber% goto loser

:play3
cls
echo Generating the third Lottery Number...
pathping localhost -q 2 -p 100 > nul
:loop3
set num3=%random%
if /i %num3% GTR 20 goto loop3
if /i %num3% LSS 1 goto loop3
goto finish
:finish3
cls
echo Lottery number %num3%
echo Click [ ENTER ]
pause > nul
if %num3% == %thirdnumber% goto play4
else if %num% NEQ %firstnumber% goto loser

:play4
cls
echo Generating the fourth Lottery Number...
pathping localhost -q 2 -p 100 > nul
:loop4
set num4=%random%
if /i %num4% GTR 50 goto loop4
if /i %num4% LSS 1 goto loop4
goto finish4
:finish4
cls
echo Lottery number %num4%
echo Click [ ENTER ]
pause > nul
if %num4% == %firstnumber% goto play5
else if %num% NEQ %firstnumber% goto loser

:play5
cls
echo Generating the last Lottery Number...
pathping localhost -q 2 -p 100 > nul
:loop5
set num5=%random%
if /i %num% GTR 50 goto loop
if /i %num% LSS 1 goto loop
goto finish5
:finish5
cls
echo Lottery number %num5%
echo Click [ ENTER ]
pause > nul
if %num5% == %fifthnumber% goto winner
else if %num5% NEQ %fifthnumber% goto loser


:winner
cls
echo.
echo.
echo You win!
echo.
echo.
pathping localhost -q 2 -p 250 > nul
pathping localhost -q 2 -p 250 > nul
echo.
echo.
echo Congratulations!
echo.
echo.
pathping localhost -q 2 -p 250 > nul
pathping localhost -q 2 -p 250 > nul
cls
echo.
echo.
echo You win a BILLION DOLLARS!
echo.
echo.
pathping localhost -q 2 -p 250 > nul
pathping localhost -q 2 -p 250 > nul
echo.
echo.
echo Not really...
echo.
echo.
pathping localhost -q 2 -p 250 > nul
pathping localhost -q 2 -p 250 > nul
echo Thanks for playing
pathping localhost -q 2 -p 250 > nul
goto opening


:loser
cls
echo.
echo.
echo You lose
echo.
echo.
pathping localhost -q 2 -p 250 > nul
pathping localhost -q 2 -p 250 > nul
echo.
echo.
echo Sorry...
echo.
echo.
pathping localhost -q 2 -p 250 > nul
pathping localhost -q 2 -p 250 > nul
echo Thanks for playing
pathping localhost -q 2 -p 250 > nul

:instructions
cls
echo.
echo Type in your five choices at the begining
echo.
echo Let the computer do the rest of the work
echo.
echo The numbers are from 1 to 50
echo.
echo Created by Brock's Batch Files
echo Click [ ENTER ]
pause > nul
cls
goto opening


:leave
cls
echo
pathping localhost -q 2 -p 50 > nul
exit


See More: My game isnt working could anyone look at the code?

Report •

#1
June 15, 2013 at 18:33:55
batch does not support this syntax:
if %num% == %firstnumber% goto play2
else if %num% NEQ %firstnumber% goto loser

(specifically, the second line listed above). It could be modified to do so, but if you examine the logic, you will see a much better way:
if %num% neq %firstnumber% goto loser

Then if num is equal, it just falls through to the next step (:play2) without needing a "goto".

ps: in "play3" you have a "20" instead of a "50". If you used a subroutine, you would only have to maintain one, instead of five, for correctness. Aside from that, and about a hundred other things, no-one will ever play this game because there's no reward, no skill or intelligence involved, and they will almost always always never win. :-(


Report •

#2
June 16, 2013 at 19:04:08
Yeah, it is basically impossible to win, I just made it because I was bored. However, if I knew how to make it so that order doesn't matter, I totally would.

Report •

#3
June 16, 2013 at 22:20:04
Ha ha!! Still, the same caveats mostly hold true, but here's what I would do:
@echo off & setlocal
:0
set a
set c=0
:xx
set /a z=%random% %% 50+1
if defined a%z% goto :xx
set a%z%=1
set /a c+=1
if %c% lss 5 goto :xx
set c=0
:yy
set /a c+=1
set zz=
set /p zz=number:
if not defined a%zz% goto :loser
if %c% equ 5 goto :win
set a%zz%=
goto :yy
:loser
echo ..... sorry .....
goto :zz
:win
set a%zz%=
echo ***** Winner *****
:zz
for /L %%a in (1,1,50) do set a%%a=
set c=0
goto :0
::==== end batch
Now I'm gonna go buy a lotto ticket (easy-pick, of course!)

Report •
Related Solutions


Ask Question