03-06-PY-rock-paper-scissors.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**Decompose game into the different parts
  2. * Clicking button will choose R,P,or S - check frameIndexes
  3. * Image will show on screen based on button clicked
  4. * Computer will choose R P or S - random(2,0) - 0,1,2
  5. * Image for Computer's choice shown frameIndex (0,1,2)
  6. * Win conditionals will be analyzed - if() conditions
  7. * Result is shown (win or lose or tie)
  8. **/
  9. /**Look at RPS1 Animations for frameIndex:
  10. * 0 - paper
  11. * 1 - rock
  12. * 2 - scissors
  13. **/
  14. //Scene - Initialize When Scene Starts
  15. //Nothing picked yet, so big images should be hidden
  16. RPS1.visible(false);
  17. RPS2.visible(false);
  18. //results says "Will You Play?"
  19. //Ninja could change it to a welcome text
  20. results.text("Welcome to RPS v.1.0");
  21. //paperButton - Mouse Click Event [0]
  22. //generate the computer's choice
  23. var compChoice = random(0,2);
  24. //Show your choice on RPS1
  25. RPS1.frameIndex(0);
  26. RPS1.visible(true);
  27. //Show computer's choice on RPS2
  28. RPS2.frameIndex(compChoice);
  29. RPS2.visible(true);
  30. //Win Conditionals:
  31. if (compChoice == 1) { //Comnputer chose rock [1]
  32. result.text("You Win!");
  33. } else if (compChoice == 2) { //Computer chose scissors [2]
  34. results.text("You lost!");
  35. } else { //Do we need to type the condition? If it didn't choose rock
  36. //or scissors, it must have chosen paper
  37. results.text("It's a tie!")
  38. }