Rock Paper Scissors Game With CMD

by NotePro in Craft > Digital Graphics

660 Views, 2 Favorites, 0 Comments

Rock Paper Scissors Game With CMD

rps.PNG

This is the classic Rock Paper Scissors game recreated into batch. I used inspiration from a previous instructable of mine to create a functional AI opponent. This game can be played with 1 or 2 players.

Supplies

As always, you will need notepad and the ability to copy and paste.

The Program

rps2.PNG

rem Copy and paste everything.

@echo off


title R P S


:menu

cls

echo This game was created by NotePro

echo Would you like to play 2 player or single player?

choice /c 123456789 /n /m "press the number of players you wish to play with"

set /a players = %errorlevel%

if %players% GTR 2 echo how do you play with %players% players? && pause> nul && goto menu

:error

cls

:top

cls

if %players% == 1 set /a p1 = %random% && call :AI

echo player1

echo R, P, S?

choice /c rps1234567890qwetyuioadfghjklzxcvbnm /n

set /a p1 = %errorlevel%

if %errorlevel% GTR 3 goto error


:p2

cls

echo player2

echo R, P, S?

choice /c rps1234567890qwetyuioadfghjklzxcvbnm /n

set /a p2 = %errorlevel%

if %errorlevel% GTR 3 goto p2

goto %p2%

:1

if %p1% == %p2% echo p1: Rock  p2: Rock -- Tie!

if %p1% == 2 echo p1: Paper  p2: Rock -- Player1 wins!

if %p1% == 3 echo p1: Scissors  p2: Rock -- Player2 wins!

pause

goto top

:2

if %p1% == %p2% echo p1: Paper  p2: Paper -- Tie!

if %p1% == 1 echo p1: Rock  p2: Paper -- Player2 wins!

if %p1% == 3 echo p1: Scissors  p2: Paper -- Player1 wins!

pause

goto top

:3

if %p1% == %p2% echo p1: Scissors  p2: Scissors -- Tie!

if %p1% == 1 echo p1: Rock  p2: Scissors -- Player1 wins!

if %p1% == 2 echo p1: Paper  p2: Scissors -- Player2 wins!

pause

goto top

:AI

if %p1% LSS 4 goto p2

if %p1% GTR 1000 set /a p1=%p1% -997

set /a p1= %p1% -3

if %p1% LSS 4 goto p2turn

goto AI

:p2turn

echo AI - Choice made

timeout /t 1 /nobreak> nul

goto p2

Final Thoughts

This is a project based off of CMD %random% Variable Controller. I hope you enjoy this project!

(Remember to save the file with the extension .bat)