User prompt
There will be 3 available shapes: A Circle, A square and A triangle. By every click the player changes the shape to one of those 3.
User prompt
Fix Bug: 'TypeError: shapes[a].containsPoint is not a function' in this line: 'if (shapes[a] && shapes[a].containsPoint(pos)) {' Line Number: 51
User prompt
Fix Bug: 'TypeError: shapes[a] is undefined' in this line: 'if (shapes[a].containsPoint(pos)) {' Line Number: 51
User prompt
Fix Bug: 'TypeError: shapes[a] is undefined' in this line: 'if (shapes[a].matched) {' Line Number: 32
Initial prompt
Shape Match FRVR
===================================================================
--- original.js
+++ change.js
@@ -1,19 +1,45 @@
-var Shape = Container.expand(function () {
+var Circle = Container.expand(function () {
var self = Container.call(this);
- var shapeGraphics = self.createAsset('shape', 'Shape Graphics', .5, .5);
+ var circleGraphics = self.createAsset('circle', 'Circle Graphics', .5, .5);
self.matched = false;
self.match = function () {
self.matched = true;
};
});
+var Square = Container.expand(function () {
+ var self = Container.call(this);
+ var squareGraphics = self.createAsset('square', 'Square Graphics', .5, .5);
+ self.matched = false;
+ self.match = function () {
+ self.matched = true;
+ };
+});
+var Triangle = Container.expand(function () {
+ var self = Container.call(this);
+ var triangleGraphics = self.createAsset('triangle', 'Triangle Graphics', .5, .5);
+ self.matched = false;
+ self.match = function () {
+ self.matched = true;
+ };
+});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player Graphics', .5, .5);
self.score = 0;
+ self.shape = 'circle';
self.incrementScore = function () {
self.score += 1;
};
+ self.changeShape = function () {
+ if (self.shape === 'circle') {
+ self.shape = 'square';
+ } else if (self.shape === 'square') {
+ self.shape = 'triangle';
+ } else {
+ self.shape = 'circle';
+ }
+ };
});
var Game = Container.expand(function () {
var self = Container.call(this);
var shapes = [];
@@ -44,15 +70,16 @@
self.addChild(newShape);
}
});
stage.on('down', function (obj) {
+ player.changeShape();
var event = obj.event;
var pos = event.getLocalPosition(self);
for (var a = shapes.length - 1; a >= 0; a--) {
if (shapes[a] && shapes[a].containsPoint({
x: pos.x,
y: pos.y
- })) {
+ }) && shapes[a] instanceof window[player.shape]) {
shapes[a].match();
}
}
});