RockPaperScissors game Won't Work

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BatMaster
Posts: 28
Joined: 22 Dec 2010 12:53

RockPaperScissors game Won't Work

#1 Post by BatMaster » 30 Dec 2010 12:12

i tried to write a game for my freinds to play but it wont work. here is the code

Code: Select all

@echo off &setlocal
title RockPaperScissors
GOTO rps1

:rps1
set"rps=123"
set/a x1=random%%%3
call set "spr=%%rps:~%x1%,1%%"
if %spr%=1 GOTO rock
if %spr%=2 GOTO paper
if %spr%=3 GOTO scissors

:rock
SET INPUT=
ECHO Make a choice
pause
SET /P input=rock/paper/scissors:
if "%input%" =="" GOTO rps1
if "%input%" =="rock" GOTO draw
if "%input%" =="paper" GOTO win
if "%input%" =="scissors" GOTO loss

:paper
SET INPUT=
ECHO Make a choice
pause
SET /P input=rock/paper/scissors:
if "%input%" =="" GOTO rps1
if "%input%" =="rock" GOTO loss
if "%input%" =="paper" GOTO draw
if "%input%" =="scissors" GOTO win

:scissors
SET INPUT=
ECHO Make a choice
pause
SET /P input=rock/paper/scissors:
if "%input%" =="" GOTO rps1
if "%input%" =="rock" GOTO win
if "%input%" =="paper" GOTO loss
if "%input%" =="scissors" GOTO draw

:win
ECHO You have won. play again
pause
set /p input=y/n:
if "%input%" =="" GOTO win
if "%input%" =="y" GOTO rps1
if "%input%" =="n" GOTO exit

:loss
ECHO You have been defeated. play again
pause
set /p input=y/n:
if "%input%" =="" GOTO loss
if "%input%" =="y" GOTO rps1
if "%input%" =="n" GOTO exit

:draw
ECHO The game ended in a draw. play again
pause
set /p input=y/n:
if "%input%" =="" GOTO draw
if "%input%" =="y" GOTO rps1
if "%input%" =="n" GOTO exit

:exit
pause
exit
could you look over it and check to see what the problem is.thanks in advance..BatMaster.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: RockPaperScissors game Won't Work

#2 Post by aGerman » 30 Dec 2010 12:43

Try:

Code: Select all

@echo off &setlocal
title RockPaperScissors

:rps1
set/a spr=%random% %% 3
if %spr%==1 GOTO paper
if %spr%==2 GOTO scissors

:rock
SET INPUT=
ECHO Make a choice
SET /P input=rock/paper/scissors:
if /i "%input%"=="rock" GOTO draw
if /i "%input%"=="paper" GOTO win
if /i "%input%"=="scissors" GOTO loss
GOTO rps1

:paper
SET INPUT=
ECHO Make a choice
SET /P input=rock/paper/scissors:
if /i "%input%"=="rock" GOTO loss
if /i "%input%"=="paper" GOTO draw
if /i "%input%"=="scissors" GOTO win
GOTO rps1

:scissors
SET INPUT=
ECHO Make a choice
SET /P input=rock/paper/scissors:
if /i "%input%"=="rock" GOTO win
if /i "%input%"=="paper" GOTO loss
if /i "%input%"=="scissors" GOTO draw
GOTO rps1

:win
SET INPUT=
ECHO You have won. play again
set /p input=y/n:
if /i "%input%"=="y" GOTO rps1
if /i "%input%"=="n" GOTO :eof
GOTO win

:loss
SET INPUT=
ECHO You have been defeated. play again
set /p input=y/n:
if /i "%input%"=="y" GOTO rps1
if /i "%input%"=="n" GOTO :eof
GOTO loss

:draw
SET INPUT=
ECHO The game ended in a draw. play again
set /p input=y/n:
if /i "%input%"=="y" GOTO rps1
if /i "%input%"=="n" GOTO :eof
GOTO draw


BTW There are a lot of possibilities to optimize.

Regards
aGerman

Post Reply