REMSTART
Brain Entry: Rock Paper Scissors
Made by Sinani201
~The DB Classic Programming Challenge Thread~
REMEND
 
gosub setup
 
`Create an array for the button's mouse events.
dim buttonCoord(3,4)
buttonCoord(1,1) = 100 : `Left
buttonCoord(1,2) = 200 : `Top
buttonCoord(1,3) = 100 : `Right
buttonCoord(1,4) = 200 : `Bottom
 
buttonCoord(2,1) = 210
buttonCoord(2,2) = 100
buttonCoord(2,3) = 310
buttonCoord(2,4) = 200
 
buttonCoord(3,1) = 320
buttonCoord(3,2) = 100
buttonCoord(3,3) = 420
buttonCoord(3,4) = 200
 
print "This is the Rock Paper Scissors brain game."
print "You must choose either rock, paper, or scissors depending on what your opponent chooses."
print "For instance, if you see that your opponent chose Rock, you will have to choose either Paper or Scissors."
print "Be careful, because sometimes the program will ask you to lose as well. Keep your eyes open!"
print "Remember, Paper beats Rock, Rock beats Scissors, and Scissors beats Paper."
print "Choose the correct option as quickly as you can to get a good score"
print "If you get an incorrect answer, it counts as if the correct answer took 10 seconds."
print "Good luck! Press any key to start."
wait key
cls
wait 300
for num = 3 to 1 step -1
  countdown(str$(num))
  wait 1000
  cls
Next num
countdown("Go!")
set text opaque
wait 500
cls
set text size 16
for t = 1 to 10
  randomize timer()
  part1$ = "Opponent's choice: "
  choiceNum = rnd(2) + 1
  select choiceNum
    case 1
      text 0,0,part1$ + "Rock             "
    endcase
    case 2
      text 0,0,part1$ + "Scissors"
    endcase
    case 3
      text 0,0,part1$ + "Paper              "
    endcase
  endselect
  losewin = rnd(1)
  if losewin = 1
    text 0,30,"Please win.    "
  else
    text 0,30,"Please lose."
  endif
 
  for rps = 1 to 3
    makeBox(rps)
  next rps
  repeat
    miliseconds=(Timer()-q)/10
    If miliseconds>=100
      Inc Seconds
      If Seconds>=60
        Inc Minutes
        If Minutes>=60
          Minutes=0
        Endif
        Seconds=0
      Endif
      miliseconds=0
      q=Timer()
    Endif
    Min$=Str$(Minutes)
    If Minutes<10 Then Min$="0"+Min$
    Sec$=Str$(Seconds)
    If Seconds<10 Then Sec$="0"+Sec$
    mili$=Str$(miliseconds)
    If miliseconds<10 Then mili$="0"+mili$
    Text 0,52,"Time: "+Min$+":"+Sec$+":"+mili$+"    "
    for button = 1 to 3
      if zoneclick(buttonCoord(button,1),buttonCoord(button,2),buttonCoord(button,3),buttonCoord(button,4))
        if checkanswer(button,choiceNum,losewin) = 1
          totalTime(1) = totalTime(1) + miliseconds : `Miliseconds
          totalTime(2) = totalTime(2) + Seconds : `Seconds
          totalTime(3) = totalTime(3) + Minutes : `Minutes
        else
          totalTime(2) = totalTime(2) + 10
        endif
        answermade = 1
      ENDIF
    next button
  until answermade = 1
  answermade = 0
next t
wait 1000
cls
print "Your time was ",miliseconds," miliseconds, ",seconds," seconds, and ",minutes," minutes."
end
 
`-------------------------------
`-----Gosubs and Functions------
`-------------------------------
setup:
  Set Display Mode 800,600,16
  cls 0 : sync
  `Make an array to hold the time taken for the game.
  dim totalTime(3)
return
 
function countdown(text$)
  circle 400,300,50
  set text size 40
  center text 400,300-30,text$
endfunction
 
function makeBox(rps)
  select rps
    case 1
      `Rock
      wire_box(100,100,200,200)
      circle 150,150,42
    endcase
    case 2
      `Scissors
      wire_box(210,100,310,200)
      ellipse 340,170,10,22
      ellipse 400,170,10,22
      line 348,160,400,110
      line 392,160,340,110
    endcase
    case 3
      `Paper
      wire_box(320,100,420,200)
      box 230,120,290,180
    endcase
  endselect
endfunction
 
function wire_box(l,t,r,b)
  line l,t,r,t
  line r,t,r,b
  line r,b,l,b
  line l,b,l,t
endfunction
 
function zoneclick(l,t,r,b)
  inc l
  inc t
  inc r
  inc b
  `x
  if mousex() > l and mousex() < r
    `y
    if mousey() > t and mousey() < b
      retVal = mouseclick()
    endif
  endif
endfunction retVal
 
function checkAnswer(rps,op,wl)
  retval = 0
  if wl = 1
    select rps
      case 1
        if op = 2 then retval = 1
      endcase
      case 2
        if op = 3 then retval = 1
      endcase
      case 3
        if op = 1 then retval = 1
      endcase
    endselect
  else
    select rps
      case 1
        if op = 3 then retval = 1
      endcase
      case 2
        if op = 1 then retval = 1
      endcase
      case 3
        if op = 2 then retval = 1
      endcase
    endselect
  endif
endfunction retval