Board Logo
« Rock, Paper, Scissors game »

Welcome Guest. Please Login or Register.
Jan 21st, 2018, 12:49am


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: Rock, Paper, Scissors game  (Read 1954 times)
Welopez
Moderator
ImageImageImageImageImage


member is offline

Avatar

Never let your beliefs get in the way of learning.


PM

Gender: Male
Posts: 4407
xx Re: Rock, Paper, Scissors game
« Reply #30 on: Apr 23rd, 2008, 07:40am »

The game was Smarticus! Actually, I mis-spoke, there were 114 SELECT CASE choices, the remaining 6 default to a win for the player or Smarticus.

I needed to make three comparisons for each line and had not yet learned to use the ";" between variables, so I used the STR$() value of 3 variables to check the status of the game board. It was great fun... just to see if I could do it.

The paper, rock, scissors could also be stored in a string, then parsed using WORD$(), instead of an array. Some beginners seem to grasp the use of WORD$() before they grasp arrays.
Code:
choice$="Paper Rock Scissors"
FOR k=1 TO 3
     PRINT WORD$(choice$,k)
NEXT k

END
 

Uncle Ben's DEMO is very clear and concise also. I just wanted to point out another method. I think it's useful to put more "tools" in the beginners tool box which can be used the next time he is beginning a project.

I also wanted to emphasize the "Do again? (Y/N)" comparison. If the user does not choose "Y", there is no need for other checks... simple end the program.

User IP Logged

JB 1.01
Win7 64bit, 4 GB RAM, Pentium 6200@2.13 GHz (laptop)
WinXP, 1 GB RAM, Intel N270@1.6 GHz (netbook)
Melior007
New Member
Image


member is offline

Avatar




PM


Posts: 1
xx Re: Rock, Paper, Scissors game
« Reply #31 on: Feb 11th, 2015, 09:45am »

Hi All,

I am new to JB and programming in general. Now working on Rock, Paper, Scissors game and I keep seeing error and have no idea how to debug it.

Some of the code below.

Any clues?
Code:
graphicbox #play.gboxPlayer, 45, 70, 144, 144
graphicbox #play.gboxComputer, 300, 70, 144, 144

Instructions1$ = "Player:"
Instructions2$ = "Computer:"
Instructions3$ = "Select a Move:"
Instructions4$ = "Computer Move:"

statictext #play.statictext1, Instructions1$, 90, 40, 80, 20
statictext #play.statictext2, Instructions2$, 335, 40, 80, 20
statictext #play.statictext3, Instructions3$, 20, 260, 80, 20
statictext #play.statictext4, Instructions4$, 270, 260, 80, 20

combobox #play.combobox, moves$(), doubleClick, 20, 280, 200, 80

button #play.button1 "Go", PlayHand, UL, 70, 345, 100, 50

textbox #play.textbox, 270, 280, 200, 22

groupbox #play.groupbox, "Game Statistics:", 270, 310, 200, 105


statictext #play.statictext5, "Player Wins:", 285, 330, 70, 14
statictext #play.statictext6, "Player Losses:", 285, 360, 70, 14
statictext #play.statictext7, "Ties:", 285, 390, 70, 14

textbox #play.textbox2, 365, 325, 90, 22
textbox #play.textbox3, 365, 355, 90, 22
textbox #play.textbox4, 365, 385, 90, 22

open "Rock, Paper, Scissors" for window_nf as #play

print #play, "trapclose ClosePlay"

print #play.button1, "!disable"

print #play.statictext1, "!font Arial 12"  
print #play.statictext2, "!font Arial 12"  

wait

sub doubleClick handle$

print #play.button1, "!enable"
end sub

sub PlayHand handle$ 

#play.combobox "selection? playerMove$"

print #play.gboxPlayer, "flush"
print #play.gboxComputer, "flush"

if playerMove$ = "Rock" then
print #play.gboxPlayer, "drawbmp rockImage 1 1"
end if

if playerMove$ = "Paper" then
print #play.gboxPlayer, "drawbmp paperImage 1 1"
end if

if playerMove$ = "Scissors" then
print #play.gboxPlayer, "drawbmp scissorsImage 1 1"
end if

RandomNumber = int(rnd(1)*3) + 1

if RandomNumber = 1 then
 computerMove$ = "Rock"
 print #play.gboxComputer, "drawbmp rockImage 1 1"
 end if

 if RandomNumber = 2 then
 computerMove$ = "Paper"
 print #play.gboxComputer, "drawbmp paperImage 1 1"
 end if

 if RandomNumber = 3 then
 computerMove$ = "Scissors"
 print #play.gboxComputer, "drawbmp scissorsImage 1 1"
 end if

print #play.gboxPlayer, "flush"
 print #play.gboxComputer, "flush"

print #play.textbox, computerMove$ 

 if playerMove$ = "Rock" then
 select case
 case computerMove$ = "Rock"
 result$ = "Tie!"
 ties = ties + 1
 print #play.textbox4, ties

 case computerMove$ = "Paper"
 result$ = "The computer wins!"
 losses = losses + 1
 print #play.textbox3, losses

 case computerMove$ = "Scissors"
 result$ = "The player wins!"
 wins = wins + 1
 print #play.textbox2, wins

 end select
 end if

if playerMove$ = "Paper" then
select case
case computerMove$ = "Rock"
result$ = "The player wins!"
wins = wins + 1
print #play.textbox2, wins

case computerMove$ = "Paper"
result$ = "Tie!"
ties = ties + 1
print #play.textbox4, ties

case computerMove$ = "Scissors"
result$ = "The computer wins!"
losses = losses + 1
print #play.textbox3, losses

end select
end if

if playerMove$ = "Scissors" then
select case
case computerMove$ = "Rock"
result$ = "The computer wins!"
losses = losses + 1
print #play.textbox3, losses

case computerMove$ = "Paper"
result$ = "The player wins!"
wins = wins + 1
print #play.textbox2, wins

case computerMove$ = "Scissors"
result$ = "Tie!"
ties = ties + 1
print #play.textbox4, ties

end select
end if

print #play.button1, "!disable"  
print #play.combobox, "selectindex 0"  
end sub

#play.combobox "selection? playerMove$"

sub ClosePlay handle$ 

confirm "Are you sure you want to quit?"; answer$ 
if answer$ = "yes" then  
close #play  

end  
end if
end sub

sub ClosePlay handle$

confirm "Are you sure you want to quit?"; answer$ 
  if answer$ = "yes" then  
    close #play  
  end if
end sub
 
« Last Edit: Feb 12th, 2015, 2:24pm by Stefan Pendl » User IP Logged

tenochtitlanuk ( John F)
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 430
xx Re: Rock, Paper, Scissors game
« Reply #32 on: Feb 11th, 2015, 10:12am »

Are you attempting a new solution, or playing with the existing code?
You have left off at the beginning, the Code:
nomainwin
widowWidth =800
WindowHeight =800
 

and at the end you define the quit routine twice...

AND if you enter example code, it is best to use the '#' symbol to give you the [ code]....[ /code] to make it more readable.
User IP Logged

Visit my LB/JB pages at http://www.diga.me.uk/index.html
I use XP and Ubuntu Linux on old machines!
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 268
xx Re: Rock, Paper, Scissors game
« Reply #33 on: May 12th, 2015, 10:57am »

hi,
here is my version Code:
[start]
print "choose your option..."
print"R for rock ; S for scissors; P for paper";op1$
input"";op1$
i=int(rnd(1)*3)+1
op2$=word$("R,S,P",i,",")
cls
print"your option is ";upper$(op1$)
print"my option is ";op2$
res$=upper$(op1$)+op2$
if (res$="RR" or res$="PP"or res$="SS") then winner$="neither you nor me"
if (res$="RS" or res$="SP"or res$="PR") then winner$="you"
if (res$="SR" or res$="PS"or res$="RP") then winner$="I "
print winner$; " won"
[prompt]
input"do you like to continue? y/n";op3$
if op3$="y" or op3$="y" then goto [start]
if op3$="n" or op3$="N" then goto [end]
[end]
end


 
User IP Logged

zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 268
xx Re: Rock, Paper, Scissors game
« Reply #34 on: May 12th, 2015, 11:24am »

here is one more version Code:
[start]
print "choose your option..."
print"R for rock ; S for scissors; P for paper";op1$
input"";op1$
i=int(rnd(1)*3)+1
op2$=word$("R,S,P",i,",")
cls
txt$="R,S,P,R"
op1$=upper$(op1$)
print"your option is ";op1$
print"my option is ";op2$
res$=op1$+op2$
winner$="neither you nor me"
for i=1 to 3
if res$=word$(txt$,i,",")+word$(txt$,i+1,",")then winner$="you"
if res$=word$(txt$,i+1,",")+word$(txt$,i,",")then winner$="I "
next
print winner$; " won"
[prompt]
input"do you like to continue? y/n   ";op3$
if op3$="y" or op3$="y" then goto [start]
if op3$="n" or op3$="N" then goto [end]
[end]
end


 
User IP Logged

TyCamden
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1431
xx Re: Rock, Paper, Scissors game
« Reply #35 on: May 12th, 2015, 12:40pm »

on May 12th, 2015, 11:24am, zzz000abc wrote:
here is one more version ...(CODE)..


I think the following line of code has a typo...

Code:
if op3$="y" or op3$="y" then goto [start] 


and should read...

Code:
if op3$="y" or op3$="Y" then goto [start] 


For fun, I made a small modification to that section of the program, so here is the full program revised code:

Code:
[start]
print "choose your option..."
print"R for rock ; S for scissors; P for paper";op1$
input"";op1$
i=int(rnd(1)*3)+1
op2$=word$("R,S,P",i,",")
cls
txt$="R,S,P,R"
op1$=upper$(op1$)
print"your option is ";op1$
print"my option is ";op2$
res$=op1$+op2$
winner$="neither you nor me"
for i=1 to 3
if res$=word$(txt$,i,",")+word$(txt$,i+1,",")then winner$="you"
if res$=word$(txt$,i+1,",")+word$(txt$,i,",")then winner$="I "
next
print winner$; " won"
[prompt]
input"do you like to continue? y/n   ";op3$
if lower$(left$(op3$,1)) = "y" then
    goto [start]
else
    end
end if 

User IP Logged

TyCamden

Please give credit if you use code I post, no need to ask for permission.


Just BASIC 1.01, Windows 7 Home Premium version (2009), AMD Athelon II 320 Dual-Core Processor 2.10 GHz - 4.00 GB RAM (3.75 usable) - 64-bit OS
bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Rock, Paper, Scissors, Lizard Spock! game
« Reply #36 on: Aug 4th, 2015, 12:22am »

Hello this is my first post, I had JB several months ago but got distracted by other Basics. This challenge looks cool!

Here is my variation:
Code:
'RPSLK.txt for Just Basic == Rock, Paper, Scissors, Lizard, Spock!
'translated from SmallBASIC 2015-08-03 MGA/B+

Global rule$ 
rule$="SPRLKSLPKR" 'letter on left beats letter on right
for i=1 to 10
   read beats$
   beat$(i)=beats$
next i

do 'main game
   call readRules
   print : call cp "Type your choice letter:"
   call cp "(R)ock, (P)aper, (S)cissors, (L)izard, Spoc(K), (Q)uit"
   call cp "and <enter>"
   print tab(40);
   input pl$ 
   if len(pl$) then
      pl$=upper$(pl$)
      if pl$<>"Q" and (pl$="R" or pl$="P" or pl$="S" or pl$="L" or pl$="K") then
         cl$=mid$(rule$,int(rnd(1)*10)+1,1)
         win$=winner$(pl$,cl$)
         print
         call cp "Player chose "+nameLetter$(pl$)+"   Computer chose "+nameLetter$(cl$)
         print
         if win$="Player" then
            pscore=pscore+1:s$="Winner was "
         else
            if win$="Computer" then
                cscore=cscore+1:s$="Winner was "
            else
                s$="The contest was a "
            end if
         end if
         call cp s$+win$ : print
         call cp "Player = "+str$(pscore)+"   Computer = "+str$(cscore)
         print
         call cp "when ready... press <enter>"
         print tab(40);
         input temp$
      end if
   end if
loop until pl$="Q"
print
call cp "Thanks for playing, Goodbye!"
end

data "cuts","covers","crushes","poisons","smashes","decapitates","eats","disproves","vaporizes","crushes"

sub readRules
   cls
   call cp "'Rock, Paper, Scissors, Lizard, Spock!'  Rules are:"
   print
   for i=1 to 10
      letter$=mid$(rule$,i,1)
      if i=10 then nextletter$="S" else nextletter$=mid$(rule$,i+1,1)
      call cp nameLetter$(letter$)+" "+beat$(i)+" "+nameLetter$(nextletter$)
   next i
end sub

function nameLetter$(letter$)
    select case letter$
        case "S":rtn$="Scissors"
        case "P":rtn$="Paper"
        case "R":rtn$="Rock"
        case "L":rtn$="Lizard"
        case "K":rtn$="Spock"
    end select
    nameLetter$=rtn$
end function

function winner$(playerletter$, computerletter$)
    winner$="Tie"
    for i=1 to 10
        select case
            case mid$(rule$,i,1)=playerletter$
                if i=10 then
                    if computerletter$="S" then winner$="Player":exit function
                else
                    if mid$(rule$,i+1,1)=computerletter$ then winner$="Player":exit function
                end if
            case mid$(rule$,i,1)=computerletter$
                if i=10 then
                    if playerletter$="S" then winner$="Computer":exit function
                else
                    if mid$(rule$,i+1,1)=playerletter$ then winner$="Computer":exit function
                end if
        end select
    next i
end function

sub cp sometext$
    n=int((80-len(sometext$))/2)
    print tab(n);sometext$
end sub

 


Well I had fun, bye.

B+

EDIT: Oh! for the cp sub (Center Print) reset the 80 to the width of your output screen if different. (for best results as they say)

EDIT #2: I have been informed that my spelling of "scissors" needs repair. Thank you.
« Last Edit: Aug 4th, 2015, 10:50am by bplus » User IP Logged

B+
Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls