Browse Source

Michael's refactor and complete rebuild

Michael Tang 1 năm trước cách đây
mục cha
commit
f5795aff1c
1 tập tin đã thay đổi với 44 bổ sung52 xóa
  1. 44 52
      orange/L5-build-cookie-stacker.js

+ 44 - 52
orange/L5-build-cookie-stacker.js

@@ -1,52 +1,15 @@
-// on B button pressed
-controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
-    if (canStack == true) {
-        sugarCookie = sprites.create(assets.image`myImage0`, SpriteKind.Player)
-        sugarCookie.setPosition(110, sugarCookieY)
-        sugarCookieY += 0 - 2
-        sugarCookieStack += 1
-    }
-})
-// on A button pressed
-controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
-    if (canStack == true) {
-        chocCookie = sprites.create(assets.image`myImage`, SpriteKind.Player)
-        chocCookie.setPosition(50, chocCookieY)
-        chocCookieY += 0 - 2
-        chocCookieStack += 1
-    }
-})
-// on countdown end
-info.onCountdownEnd(function () {
-    canStack = false
-    askForNumber()
-    pause(1000)
-    music.play(music.melodyPlayable(music.powerUp), music.PlaybackMode.UntilDone)
-    cookieStackTotal = chocCookieStack + sugarCookieStack
-    if (playerGuess == cookieStackTotal) {
-        game.showLongText("You geussed it!" + cookieStackTotal + " cookies were stacked!", DialogLayout.Bottom)
-    } else if (playerGuess != cookieStackTotal) {
-        game.showLongText("Wow! You geussed " + playerGuess + " but you acctulay stacked " + cookieStackTotal + " cookies instead!", DialogLayout.Bottom)
-        game.showLongText("Wow! You geussed  corectly " + cookieStackTotal + " cookies were stacked", DialogLayout.Bottom)
-    }
-    game.showLongText("Wow! You geussed " + playerGuess + " but you acctulay stacked" + cookieStackTotal + " cookies instead!", DialogLayout.Bottom)
-})
-function askForNumber () {
-    playerGuess = game.askForNumber("how many cookies did you think you stacked?", 2)
-}
-let playerGuess = 0
-let cookieStackTotal = 0
-let chocCookieStack = 0
-let chocCookie: Sprite = null
-let sugarCookieStack = 0
-let sugarCookie: Sprite = null
-let sugarCookieY = 0
-let chocCookieY = 0
-let canStack = false
-// set up
+// set up 
 scene.setBackgroundColor(5)
 game.showLongText("Stack cookies then geuss how many you stacked!", DialogLayout.Bottom)
-// plate sprite code
+
+//variable set up
+let chocCookieY = 100
+let sugarCookieY = 100
+let chocCookieStack = 0
+let sugarCookieStack = 0
+let canStack = true //init to true
+info.startCountdown(10)
+//plate sprite code
 let plate1 = sprites.create(img`
     ...............bbbbbbbbbbbbbbbbbbb...............
     ...........bbbbdd111111111111111ddbbbb...........
@@ -101,8 +64,37 @@ let plate2 = sprites.create(img`
     ................bbbbbbbbbbbbbbbbb................
     `, SpriteKind.Player)
 plate2.setPosition(110, 100)
-// varibel set up
-canStack = true
-info.startCountdown(10)
-chocCookieY = 100
-sugarCookieY = 100
+//on A button pressed
+controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
+    if (canStack == true) {
+        let chocCookie = sprites.create(assets.image`myImage`, SpriteKind.Player)
+        chocCookie.setPosition(50, chocCookieY)
+        chocCookieY -=2 
+        chocCookieStack += 1
+    }
+})
+//on B button pressed
+controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
+    if (canStack == true) {
+        let sugarCookie = sprites.create(assets.image`myImage0`, SpriteKind.Player)
+        sugarCookie.setPosition(110, sugarCookieY)
+        sugarCookieY -=2 // changed from 0-2
+        sugarCookieStack += 1
+    }
+})
+//on countdown end
+info.onCountdownEnd(function () {
+    canStack = false
+    pause(1000)
+    music.play(music.melodyPlayable(music.powerUp), music.PlaybackMode.UntilDone)
+    //cleaned up playerGuess    
+    let playerGuess = game.askForNumber("How manyt cookies do you think you stacked?", 2)
+    let cookieStackTotal = chocCookieStack + sugarCookieStack
+    game.showLongText("Wow! You stacked " + chocCookieStack + " chocolate chip cookies and " + sugarCookieStack + " sugar cookies!", DialogLayout.Full)
+    //cleaned up if 
+    if (playerGuess == cookieStackTotal) {
+        game.showLongText("You guessed correctly - you're one smart cookie! " + cookieStackTotal + " cookies were stacked!", DialogLayout.Full)
+    } else if (playerGuess != cookieStackTotal) {
+        game.showLongText("You guessed "+ playerGuess + " cookies, but you stacked " + cookieStackTotal + " cookies instead!", DialogLayout.Full)
+    }
+})