Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated the end of the game (rules for stopping).

  • Loading branch information...
commit ba01a562c9040142bf75eecbb4b1d0f03e6ab6cc 1 parent f884838
Arthur Kay authored
8 .metadata/controller/Audio
View
@@ -26,7 +26,7 @@
"codeClass": null,
"userConfig": {
"fn": "playPong",
- "implHandler": "var audio = Ext.ComponentQuery.query('#Sound')[0].down('#pong');\n\naudio.play();",
+ "implHandler": " var audio = Ext.ComponentQuery.query('#Sound')[0].down('#pong');\n\n audio.play();",
"designer|userClassName": "playPong"
},
"customConfigs": [],
@@ -42,7 +42,7 @@
"codeClass": null,
"userConfig": {
"fn": "playCollision",
- "implHandler": "var audio = Ext.ComponentQuery.query('#Sound')[0].down('#collision');\n\naudio.play();",
+ "implHandler": " var audio = Ext.ComponentQuery.query('#Sound')[0].down('#collision');\n\n audio.play();",
"designer|userClassName": "playCollision"
},
"customConfigs": [],
@@ -58,7 +58,7 @@
"codeClass": null,
"userConfig": {
"fn": "playWin",
- "implHandler": "var audio = Ext.ComponentQuery.query('#Sound')[0].down('#win');\n\naudio.play();",
+ "implHandler": " var audio = Ext.ComponentQuery.query('#Sound')[0].down('#win');\n\n audio.play();",
"designer|userClassName": "playWin"
},
"customConfigs": [],
@@ -74,7 +74,7 @@
"codeClass": null,
"userConfig": {
"fn": "playLose",
- "implHandler": "var audio = Ext.ComponentQuery.query('#Sound')[0].down('#lose');\n\naudio.play();",
+ "implHandler": " var audio = Ext.ComponentQuery.query('#Sound')[0].down('#lose');\n\n audio.play();",
"designer|userClassName": "playLose"
},
"customConfigs": [],
2  .metadata/controller/Ball
View
@@ -28,7 +28,7 @@
"designer|params": [
"ball"
],
- "implHandler": "var leftPaddle = MyApp.app.paddleLeft.element.getBox(),\n rightPaddle = MyApp.app.paddleRight.element.getBox(),\n ballBox = ball.getBox(),\n ballHeight = ball.getHeight(),\n collisionX = false,\n collisionY = false,\n surfaceBox;\n\nif (!MyApp.app.surface) { \n MyApp.app.surface = Ext.ComponentQuery.query('viewport > panel')[0].element.down('.x-panel-inner'); \n}\nsurfaceBox = MyApp.app.surface.getBox();\n\n//check collision with borders\nif (ballBox.left < surfaceBox.left) {\n MyApp.app.dispatch({\n controller : 'Referee',\n action : 'incrementScore',\n args : [ true ]\n });\n\n return false;\n}\nelse if (ballBox.right > surfaceBox.right) {\n MyApp.app.dispatch({\n controller : 'Referee',\n action : 'incrementScore',\n args : [ false ]\n });\n\n return false;\n}\nif (ballBox.top < surfaceBox.top || ballBox.bottom > surfaceBox.bottom) {\n collisionY = true;\n\n MyApp.app.dispatch({\n controller : 'Audio',\n action : 'playCollision'\n });\n}\n//check collision with paddles\nif (Ball.direction[0] < 0) {\n if (ballBox.bottom >= leftPaddle.top && ballBox.top <= leftPaddle.bottom) {\n if (ballBox.left <= leftPaddle.right && ballBox.left >= leftPaddle.right - Ball.speed - Ball.xConstant) { \n collisionX = true;\n Ball.checkSpeed();\n this.getDeflection(ballBox, leftPaddle);\n\n MyApp.app.dispatch({\n controller : 'Audio',\n action : 'playPong'\n });\n }\n }\n}\nelse {\n if (ballBox.bottom >= rightPaddle.top && ballBox.top <= rightPaddle.bottom) {\n if (ballBox.right >= rightPaddle.left && ballBox.right <= rightPaddle.left + Ball.speed + Ball.xConstant) { \n collisionX = true; \n Ball.checkSpeed();\n this.getDeflection(ballBox, rightPaddle);\n\n MyApp.app.dispatch({\n controller : 'Audio',\n action : 'playPong'\n });\n }\n }\n}\n\n//change ball direction, if necessary\nthis.getDirection(collisionX, collisionY);\n\nreturn true;",
+ "implHandler": " var leftPaddle = MyApp.app.paddleLeft.element.getBox(),\n rightPaddle = MyApp.app.paddleRight.element.getBox(),\n ballBox = ball.getBox(),\n ballHeight = ball.getHeight(),\n collisionX = false,\n collisionY = false,\n surfaceBox;\n\n if (!MyApp.app.surface) { \n MyApp.app.surface = Ext.ComponentQuery.query('viewport > panel')[0].element.down('.x-panel-inner'); \n }\n surfaceBox = MyApp.app.surface.getBox();\n\n //check collision with borders\n if (ballBox.left < surfaceBox.left) {\n MyApp.app.dispatch({\n controller : 'Referee',\n action : 'incrementScore',\n args : [ true ]\n });\n\n return false;\n }\n else if (ballBox.right > surfaceBox.right) {\n MyApp.app.dispatch({\n controller : 'Referee',\n action : 'incrementScore',\n args : [ false ]\n });\n\n return false;\n }\n if (ballBox.top < surfaceBox.top || ballBox.bottom > surfaceBox.bottom) {\n collisionY = true;\n\n MyApp.app.dispatch({\n controller : 'Audio',\n action : 'playCollision'\n });\n }\n //check collision with paddles\n if (Ball.direction[0] < 0) {\n if (ballBox.bottom >= leftPaddle.top && ballBox.top <= leftPaddle.bottom) {\n if (ballBox.left <= leftPaddle.right && ballBox.left >= leftPaddle.right - Ball.speed - Ball.xConstant) { \n collisionX = true;\n Ball.checkSpeed();\n this.getDeflection(ballBox, leftPaddle);\n\n MyApp.app.dispatch({\n controller : 'Audio',\n action : 'playPong'\n });\n }\n }\n }\n else {\n if (ballBox.bottom >= rightPaddle.top && ballBox.top <= rightPaddle.bottom) {\n if (ballBox.right >= rightPaddle.left && ballBox.right <= rightPaddle.left + Ball.speed + Ball.xConstant) { \n collisionX = true; \n Ball.checkSpeed();\n this.getDeflection(ballBox, rightPaddle);\n\n MyApp.app.dispatch({\n controller : 'Audio',\n action : 'playPong'\n });\n }\n }\n }\n\n //change ball direction, if necessary\n this.getDirection(collisionX, collisionY);\n\n return true;",
"designer|userClassName": "checkCollisions"
},
"customConfigs": [],
2  .metadata/controller/Referee
View
@@ -28,7 +28,7 @@
"designer|params": [
"isPlayer"
],
- "implHandler": "MyApp.app.stopGame();\n\nif (!this.scoreCPU) { this.scoreCPU = 0; }\nif (!this.scorePlayer) { this.scorePlayer = 0; }\n\nif (isPlayer) {\n Ext.ComponentQuery.query('#scorePlayer')[0].setHtml('Player: ' + ++this.scorePlayer);\n\n MyApp.app.dispatch({\n controller : 'Audio',\n action : 'playWin'\n });\n}\nelse {\n Ext.ComponentQuery.query('#scoreCPU')[0].setHtml('CPU: ' + ++this.scoreCPU);\n\n MyApp.app.dispatch({\n controller : 'Audio',\n action : 'playLose'\n });\n}\n\nvar box = MyApp.app.surface.getBox();\n\n//center the ball\nMyApp.app.ball.element.setXY(\n[ Math.floor(box.width / 2), Math.floor( box.height / 2) ]\n);\n\nMyApp.app.startGame();",
+ "implHandler": "MyApp.app.stopGame();\n\nif (!this.scoreCPU) { this.scoreCPU = 0; }\nif (!this.scorePlayer) { this.scorePlayer = 0; }\n\nif (isPlayer) {\n Ext.ComponentQuery.query('#scorePlayer')[0].setHtml('Player: ' + ++this.scorePlayer);\n\n MyApp.app.dispatch({\n controller : 'Audio',\n action : 'playWin'\n });\n}\nelse {\n Ext.ComponentQuery.query('#scoreCPU')[0].setHtml('CPU: ' + ++this.scoreCPU);\n\n MyApp.app.dispatch({\n controller : 'Audio',\n action : 'playLose'\n });\n}\n\nvar box = MyApp.app.surface.getBox();\n\n//center the ball\nMyApp.app.ball.element.setXY(\n[ Math.floor(box.width / 2), Math.floor( box.height / 2) ]\n);\n\nif (this.scoreCPU >= 10 && this.scoreCPU > this.scorePlayer) {\n Ext.Msg.alert('Your Lose!', 'You Lose!');\n Ext.ComponentQuery.query('#playpause')[0].disable();\n}\nelse {\n MyApp.app.startGame();\n}",
"designer|userClassName": "incrementScore"
},
"customConfigs": [],
4 .metadata/view/Surface
View
@@ -32,7 +32,7 @@
"designer|userClassName": "MyToolbar"
},
"customConfigs": [],
- "expanded": false,
+ "expanded": true,
"cn": [
{
"id": "ExtBox1-ext-gen50085",
@@ -81,7 +81,7 @@
"value": [
1
],
- "maxValue": 10,
+ "maxValue": 5,
"minValue": 1,
"designer|userClassName": "MySliderField"
},
8 app/controller/Referee.js
View
@@ -56,7 +56,13 @@ Ext.define('MyApp.controller.Referee', {
[ Math.floor(box.width / 2), Math.floor( box.height / 2) ]
);
- MyApp.app.startGame();
+ if (this.scoreCPU >= 10 && this.scoreCPU > this.scorePlayer) {
+ Ext.Msg.alert('Your Lose!', 'You Lose!');
+ Ext.ComponentQuery.query('#playpause')[0].disable();
+ }
+ else {
+ MyApp.app.startGame();
+ }
},
playPause: function(button, e, options) {
2  app/view/ui/Surface.js
View
@@ -49,7 +49,7 @@ Ext.define('MyApp.view.ui.Surface', {
value: [
1
],
- maxValue: 10,
+ maxValue: 5,
minValue: 1
}
]
Please sign in to comment.
Something went wrong with that request. Please try again.