Browse Source

Add Rock Paper Scissors

michtang 3 years atrás
parent
commit
0f51e2c643

+ 5 - 4
02-yellow/01-03-rain-catcher-pt-3.js

@@ -1,7 +1,8 @@
-//turtleSprite - Initialize When Scene Starts 
-//Careful with the capitalization of PLAY and the quotations
-//Sometimes, the quotation marks do not paste properly
-
+/**
+ * Careful with the capitalization of PLAY and the quotations
+ * Sometimes, the quotation marks do not paste properly
+ * */
+//turtleSprite - Initialize When Scene Starts
 if($this.scene.state() == "PLAY") {
     createTimer(1000,  function(){
         var ndrop = drop.clone();

+ 4 - 2
02-yellow/01-04-rain-catcher-pt-4.js

@@ -1,6 +1,8 @@
+/**
+Raindrop is from the last activity, we have
+moved it to the scene**/ 
+
 //Scene - Initialize When Scene Starts
-//Raindrop is from the last activity, we have
-//moved it to the scene 
 if($this.scene.state() == "PLAY"){
     createTimer(1000, function(){
         var ndrop = drop.clone();

+ 7 - 5
02-yellow/02-02-meteors-pt2.js

@@ -18,11 +18,13 @@ if(bullet && $this.isTouching(bullet)){
     
     $this.scene.scoreValue++;
     score.text("Score: "+$this.scene.scoreValue);
-    //this is where you add the code in step 3, inside the if ($this.isTouching(bullet)) statement
-    //Good place to have ninja explain what this code is doing
-    //Review conditionals and comparison operators
-    //Remember that this section is all about Math
-    //Draw the connections between math and computer science - math is definitely important in game dev!
+    /**
+    This is where you add the code in step 3, inside the if ($this.isTouching(bullet)) statement
+    Good place to have ninja explain what this code is doing
+    Review conditionals and comparison operators
+    Remember that this section is all about Math
+    Draw the connections between math and computer science - math is definitely important in game dev!
+    **/
     if (this.scaleX() >= 0.25) {
         var ncircle = $this.clone();
         ncircle.x($this.x()+100);

+ 46 - 0
02-yellow/03-06-PY-rock-paper-scissors.js

@@ -0,0 +1,46 @@
+/**Decompose game into the different parts
+ * Clicking button will choose R,P,or S - check frameIndexes
+ * Image will show on screen based on button clicked
+ * Computer will choose R P or S - random(2,0) - 0,1,2
+ * Image for Computer's choice shown frameIndex (0,1,2)
+ * Win conditionals will be analyzed - if() conditions
+ * Result is shown (win or lose or tie)
+ **/
+
+/**Look at RPS1 Animations for frameIndex:
+ * 0 - paper
+ * 1 - rock
+ * 2 - scissors
+ **/
+
+//Scene - Initialize When Scene Starts 
+//Nothing picked yet, so big images should be hidden
+RPS1.visible(false);
+RPS2.visible(false);
+//results says "Will You Play?"
+//Ninja could change it to a welcome text
+results.text("Welcome to RPS v.1.0");
+
+//paperButton - Mouse Click Event [0]
+//generate the computer's choice
+var compChoice = random(0,2);
+
+//Show your choice on RPS1
+RPS1.frameIndex(0);
+RPS1.visible(true);
+
+//Show computer's choice on RPS2
+RPS2.frameIndex(compChoice);
+RPS2.visible(true);
+
+//Win Conditionals:
+
+if (compChoice == 1) { //Comnputer chose rock [1]
+    result.text("You Win!");
+} else if (compChoice == 2) { //Computer chose scissors [2]
+    results.text("You lost!");
+} else { //Do we need to type the condition? If it didn't choose rock
+    //or scissors, it must have chosen paper
+    results.text("It's a tie!")
+}
+