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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. Decompose game into the different parts
  3. * Clicking button will choose R,P,or S - check frameIndexes
  4. * Image will show on screen based on button clicked
  5. * Computer will choose R P or S - random(2,0) - 0,1,2
  6. * Image for Computer's choice shown frameIndex (0,1,2)
  7. * Win conditionals will be analyzed - if() conditions
  8. * Result is shown (win or lose or tie)
  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. results.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. }
  39. //***************rockButton - Mouse Click Event [1]********************//
  40. //generate the computer's choice
  41. var compChoice = random(0,2);
  42. //Show your choice on RPS1
  43. RPS1.frameIndex(1);
  44. RPS1.visible(true);
  45. //Show computer's choice on RPS2
  46. RPS2.frameIndex(compChoice);
  47. RPS2.visible(true);
  48. //Win Conditionals:
  49. if (compChoice == 2) { //Comnputer chose scissors [2]
  50. results.text("You Win!");
  51. } else if (compChoice === 0) { //Computer chose paper [0]
  52. results.text("You lost!");
  53. } else { //Do we need to type the condition? If it didn't choose paper
  54. //or scissors, it must have chosen rock
  55. results.text("It's a tie!")
  56. }
  57. //************scissorsButton - Mouse Click Event [2]******************//
  58. //generate the computer's choice
  59. var compChoice = random(0,2);
  60. //Show your choice on RPS1
  61. RPS1.frameIndex(2);
  62. RPS1.visible(true);
  63. //Show computer's choice on RPS2
  64. RPS2.frameIndex(compChoice);
  65. RPS2.visible(true);
  66. //Win Conditionals:
  67. if (compChoice === 0) { //Comnputer chose paper [0]
  68. results.text("You Win!");
  69. } else if (compChoice == 1) { //Computer chose rock [1]
  70. results.text("You lost!");
  71. } else { //Do we need to type the condition? If it didn't choose paper
  72. //or rock, it must have chosen scissors
  73. results.text("It's a tie!")
  74. }