Main Menu

ROCK, PAPER, SCISSORS

Started by geecee, April 27, 2009, 08:28:45 PM

Previous topic - Next topic

geecee

Hi there!

ROCK crushes SCISSORS, SCISSORS cut PAPER and PAPER covers ROCK.

What was once a game to settle playground disputes has grown to be on the cusp of recognition as a global sport.

Here's a short programme that I converted from one that appeared in an old computer magazine.  The conversion wasn't difficult but I've spruced it up a little.

I've posted the code here but it and necessary media are in the attached .zip file.

PlayBASIC Code: [Select]
; PROJECT : Rock, Paper, Scissors
; AUTHOR : geecee
; CREATED : 26/04/2009
; EDITED : 28/04/2009
rem ---------------------------------------------------------------------

rem Tell PB to include the input support library
#include "Input"

rem Load required media
RPSimage=loadnewimage("RPS.png")

rem Display image
drawimage RPSimage,0,0,false

rem This command will hide mouse pointer
mouse off

rem Load required fonts
rem Set text font "Arial" size 30 to bold
LoadFont "Arial",2,30,1
rem Set text font "Arial" size 24 to bold
LoadFont "Arial",3,24,1
rem Set text font "Arial" size 40 to bold
LoadFont "Arial",4,40,1
rem Set text font "Arial" size 18 to bold
LoadFont "Arial",5,18,1

rem Set Font
SetFont 2

rem Set ink colour
ink rgb(255,217,128)

rem Write text to screen
text 360,30, "ROCK, PAPER, SCISSORS"

rem Set font
setfont 5

rem Write text to screen
text 360,75,"ROCK crushes SCISSORS, SCISSORS cut"
text 360,93,"PAPER and PAPER covers ROCK."
text 360,129,"What was once a game to settle playground"
text 360,147,"disputes has grown to be on the cusp of"
text 360,165,"recognition as a global sport."

rem Set font
setfont 3

rem Write text to screen
centertext 400,550, "Press any key to begin"

rem Make screen visible and wait for a key press
sync
waitkey
waitnokey

rem Draw a box to hide previous text at location
boxc 2,550,798,599,1,rgb(255,0,0)

rem Set variable values to zero
wins=0
losses=0
ties=0

rem ============================================================
rem Programme main loop
rem ============================================================
do

rem Determine width of longest text string
tw=400-gettextwidth("SCISSORS")/2

rem Determine text height
height=gettextheight("SCISSORS")

rem Set across and down coordinates
across=400-gettextwidth("SCISSORS beats PAPER")/2
down=160

rem Draw box to hide previous text at location
boxc 2,down+height*3,798,down+height*7,1,rgb(255,0,0)

rem Write text to screen
text tw,down+height*3,"1 ... ROCK"
text tw,down+height*4,"2 ... PAPER"
text tw,down+height*5,"3 ... SCISSORS"
text tw,down+height*6,"4 ... QUIT"

repeat

rem Computer random choice
for a=1 to 10
aichoice=rnd(2)+1
next

rem Alternative to if/then statements
select aichoice
case 1
aichoicetxt$ = "ROCK"
case 2
aichoicetxt$ = "PAPER"
case 3
aichoicetxt$ = "SCISSORS"
endselect

rem Write text to screen
centertext 400,down+height*11,"Wins: "+str$(wins)+" Losses: "+str$(losses)+" Ties: "+str$(ties)

rem Set cursor position
setcursor 400-gettextwidth("Choose from any one of the above categories and key in its number > ")/2,500

rem Enter player choice
playerchoice=val(staticinput("Choose from any one of the above categories and key in its number > "))

rem Alternative to if/then statements
select playerchoice
case 1
playerchoicetxt$ = "ROCK"
case 2
playerchoicetxt$ = "PAPER"
case 3
playerchoicetxt$ = "SCISSORS"
case 4
rem Draw a box to hide previous text at location
boxc 2,200,798,580,1,rgb(255,0,0)

rem Set Font
SetFont 4

rem Write text to screen
centertext 400,300,"THANKS FOR PLAYING ... BYE!"

rem Display screen
sync

rem A short wait before proceeding
for times=1 to 2
wait 1000
next times

rem End programme
end
endselect

rem Draw a box to hide previous text at location
boxc 2,500,798,530,1,rgb(255,0,0)

Login required to view complete source code


:)
Enjoy
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

OldNESJunkie

Um,the media isn't in the zip file I d/l ?

geecee

Sorry OldNESJunkie

My error ...... Now fixed.

:-[
geeceeError Missing Closing Square Bracket
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

OldNESJunkie

No problemo, I just removed the references to the media to try it out, pretty good, some animations would be cool though. You are becoming a coding machine apparently, seems everyday you post something.  :o

geecee

Hi OldNESJunkie

Quotesome animations would be cool though.

Not my forte I'm afraid ...... but I'm sure someone could do the necessary.

:)
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)