本文主要是介绍合体积木,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
欢迎来到程序小院
合体积木
玩法:点击积木移动,将积木合并一起,移动步数越少获得⭐️⭐️越多,
共52关卡,每关卡都有不同的积木摆放,快去闯关吧^^。
开始游戏
html
<canvas id="gameCanvas" width="640" height="864"></canvas>
css
body,html {-webkit-touch-callout: none; -webkit-text-size-adjust: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;margin: 0;padding: 0;font-family: Arial, Verdana, sans-serif;font-size: 12px;font-weight: normal;color: #ccc;background-color: #fff;
}
.portraitLock {position: absolute;display: none;width: 100%;height: 100%;background-color: #fff;
}
.rotatePhoneIcon {width: 60%;margin: 30px auto;display: block;
}
js
function att(e) {new Jok.JokEngine("gameCanvas");(new Jok.JokG).jokEngine.initState(new PreloadState)
}function init() {att(0);
}
var Jok = Jok || {};
Jok.JokState = function() {createjs.Container.call(this);this.name = ""
};
Jok.JokState.prototype = Object.create(createjs.Container.prototype);
Jok.JokState.prototype.constructor = Jok.JokState;
Jok.JokState.prototype.dispose = function() {};
Jok.JokState.prototype.create = function() {};
Jok.JokState.prototype.update = function() {};
SplashScreenZibbo = function() {Jok.JokState.call(this)
};
SplashScreenZibbo.prototype = Object.create(Jok.JokState.prototype);
SplashScreenZibbo.prototype.constructor = SplashScreenZibbo;
SplashScreenZibbo.prototype.create = function() {console.log("SplashScreenZibbo.create");var e = new createjs.Container;this.addChild(e);this.shape = new createjs.Shape;this.shape.x = -(new Jok.JokG).width / 2;this.shape.y = -(new Jok.JokG).height / 2;this.shape.graphics.beginFill("rgba(255,255,255,1)").rect(0, 0, (new Jok.JokG).width,(new Jok.JokG).height);e.addChild(this.shape);var t = new createjs.Bitmap((new Jok.JokG).queue.getResult("zibboLogoBig"));t.x = -t.getBounds().width / 2;t.y = -t.getBounds().height / 2;e.addChild(t);console.log("bmp.x = " + t.x);this.timeBegin = createjs.Ticker.getTime();this.transScreen = true;e.on("click", createjs.proxy(ZibboUtils.logoAction, this));e.cursor = "pointer";if ((new Jok.JokG).showZibbo) {console.log("new Jok.JokG().showZibbo = " + (new Jok.JokG).showZibbo)}
};
SplashScreenZibbo.prototype.openUrl = function() {ZibboUtils.logoAction()
};
SplashScreenZibbo.prototype.update = function() {if (createjs.Ticker.getTime() - this.timeBegin > 500 && this.transScreen) {this.transScreen = false;(new Jok.JokG).jokEngine.transitionScreen(new MainMenu, null, null)}
};
ZibboUtils = function() {};
ZibboUtils.prototype.constructor = ZibboUtils;
ZibboUtils.walkAction = function() {ZibboUtils.buttonAction("walkthrough")
};
ZibboUtils.moreAction = function() {ZibboUtils.buttonAction("more_games")
};
ZibboUtils.logoAction = function() {ZibboUtils.buttonAction("logo")
};
ZibboUtils.buttonAction = function(e) {};
ZibboUtils.openUrl = function(e) {e = e || "http://play68.com";var t = window.open(e, "_blank");t.focus()
};
MyButtonBase = function(e, t, n, r) {createjs.Container.call(this);this.actionFunc = e;this._actionDefault = null;this.x = t.x;this.y = t.y;this._scaleBegin = n;this.scaleX = this._scaleBegin.x;this.scaleY = this._scaleBegin.y;if (r)if (r.length > 0) {this.sprDown = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, r);this.sprDown.stop();this.addChild(this.sprDown)}this.onWork();this.TIME_ANIM = 300;this.SCALE_ANIM = 1.11;this.tweenSize = null;this.eventScaleBegin = createjs.proxy(this.scaleBegin, this);this.eventScaleEnd = createjs.proxy(this.scaleEnd, this)
};
MyButtonBase.prototype = Object.create(createjs.Container.prototype);
MyButtonBase.prototype.constructor = MyButtonBase;
MyButtonBase.prototype.addBmpTTT = function(e, t, n, r) {console.log("bmp = " + e);console.log("MyButtonBase.prototype.addBmpTTT width = " + n);if (n);else if (e.getBounds()) {n = e.getBounds().width;r = e.getBounds().height} else {n = 202;r = 50} if (t) {e.x = -n / 2;e.y = -r / 2}var i = new createjs.Shape((new createjs.Graphics).beginFill("#000000").drawRect(e.x, e.y, n, r));this.hitArea = i;this.addChild(e);console.log("this.addChild(bmp);")
};
MyButtonBase.prototype.initUp = function(e) {this.sprUp = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, e);this.sprUp.stop();this.addChild(this.sprUp)
};
MyButtonBase.prototype.action = function(e) {if (this.tweenSize == null) {(new MusicManager).playMouse();if (this.actionFunc != null) this.actionFunc();this.tweenSize = createjs.Tween.get(this).to({scaleX: this._scaleBegin.x * this.SCALE_ANIM,scaleY: this._scaleBegin.y * this.SCALE_ANIM}, this.TIME_ANIM, createjs.Ease.quartInOut).call(this.eventScaleBegin)}
};
MyButtonBase.prototype.scaleBegin = function(e) {this.tweenSize = createjs.Tween.get(this).to({scaleX: this._scaleBegin.x,scaleY: this._scaleBegin.y}, this.TIME_ANIM, createjs.Ease.quartInOut).call(this.eventScaleEnd)
};
MyButtonBase.prototype.scaleEnd = function(e) {this.tweenSize = null
};
MyButtonBase.prototype.onSetAction = function(e) {this.offWork();this._actionDefault = e;this.onWork()
};
MyButtonBase.prototype.onWork = function() {if (!this.hasEventListener("click"))if (this._actionDefault != null) this.on("click", this._actionDefault);else this.eventAction = this.on("click", createjs.proxy(this.action, this));this.cursor = "pointer"
};
MyButtonBase.prototype.offWork = function() {console.log("MyButtonBase.prototype.offWork");if (this.hasEventListener("click")) this.off("click", this.eventAction);this.cursor = "arrow"
};
FieldContainer = function(e, t) {createjs.Container.call(this);this.gameManager = t;this.field = e;this.fieldsSteps = [];this.addSaveStep();this.x = -this.gameManager.FIELD_WIDTH / 2 * this.gameManager.CELL_SIZE + this.gameManager.CELL_SIZE;this.y = -207;this.BLUE_ID = 1;this.ORANGE_ID = 2;this.BLACK_ID = 3;this.PURPLE_ID = 4;this._moveClipsNames = {};this._moveClipsNames["" + this.BLUE_ID] = "tile_a_";this._moveClipsNames["" + this.ORANGE_ID] = "tile_c_";this._moveClipsNames["" + this.BLACK_ID] = "tile_black_";this._moveClipsNames["" + this.PURPLE_ID] = "tile_b_";this.figures = [];this._moveComplete = true;this._numMove = 0;this.findFigures();this.drawBlackCells();this.initMouse()
};
FieldContainer.prototype = Object.create(createjs.Container.prototype);
FieldContainer.prototype.constructor = FieldContainer;
FieldContainer.prototype.initMouse = function() {this.stage = (new Jok.JokG).stage;this._mouseDown = false;this._step = false;this._oldPos = new createjs.Point(this.stage.mouseX, this.stage.mouseY);this.onMouse();this.MOUSE_X_Y_DIFF_MIN = 5;this.MOUSE_PATH_MIN = 3
};
FieldContainer.prototype.offMouse = function() {this.stage.off("stagemousemove", this.eventMove);this.stage.off("stagemousedown", this.eventMouseDown);this.stage.off("stagemouseup", this.eventMouseUp)
};
FieldContainer.prototype.onMouse = function() {this.eventMove = this.stage.on("stagemousemove", createjs.proxy(this.cccMouseMove,this));this.eventMouseDown = this.stage.on("stagemousedown", createjs.proxy(this.cccMouseDown, this));this.eventMouseUp = this.stage.on("stagemouseup", createjs.proxy(this.cccMouseUp, this))
};
FieldContainer.prototype.cccMouseMove = function(e) {if (this._mouseDown && this._step && this._moveComplete) {var t = this.stage.mouseX;var n = this.stage.mouseY;var r = Math.abs(t - this._oldPos.x);var i = Math.abs(n - this._oldPos.y);if (Math.abs(r - i) < this.MOUSE_X_Y_DIFF_MIN || r < this.MOUSE_PATH_MIN && i < this.MOUSE_PATH_MIN) {this._oldPos.x = t;this._oldPos.y = n;return}this._step = false;this._numMove = 0;this._moveComplete = false;if (r > i)if (t > this._oldPos.x) this.step(1, 0);else this.step(-1, 0);else if (n > this._oldPos.y) this.step(0, 1);else this.step(0, -1);this._oldPos.x = t;this._oldPos.y = n}
};
FieldContainer.prototype.cccMouseDown = function(e) {this._mouseDown = true;this._step = true;this._oldPos.x = this.stage.mouseX;this._oldPos.y = this.stage.mouseY
};
FieldContainer.prototype.cccMouseUp = function(e) {this._mouseDown = false
};
FieldContainer.prototype.findFigures = function() {var e = new FigureBlocks(this.field, this.gameManager, this);var t = 0;var n = 0;for (t = 0; t < this.gameManager.FIELD_WIDTH; t++)for (n = 0; n < this.gameManager.FIELD_HEIGHT; n++)if (!this.cellOnFigere(t, n))if (e.findAllCells(t, n)) {this.figures.push(e);this.addChild(e);var e = new FigureBlocks(this.field, this.gameManager, this)}
};
FieldContainer.prototype.cellOnFigere = function(e, t) {for (var n = 0; n < this.figures.length; n++)if (this.figures[n].isCellFigure(e, t)) return true;return false
};
FieldContainer.prototype.drawBlackCells = function() {this.drawOne(this.BLACK_ID)
};
FieldContainer.prototype.testDrawFiled = function() {this.removeAllChildren();this.drawOne(this.BLACK_ID);this.drawOne(this.BLUE_ID);this.drawOne(this.ORANGE_ID);this.drawOne(this.PURPLE_ID)
};
FieldContainer.prototype.drawOne = function(e) {var t = -1;var n = -1;var r = new createjs.Container;this.addChild(r);for (t = -1; t < this.gameManager.FIELD_WIDTH; t++)for (n = -1; n < this.gameManager.FIELD_HEIGHT; n++) {var i = this.getSprTile(t, n, e);if (i != null) {i.x = this.gameManager.CELL_SIZE * t;i.y = this.gameManager.CELL_SIZE * n;r.addChild(i)}}
};
FieldContainer.prototype.getSprTile = function(e, t, n) {var r = this.getTileId(e, t);var i = this.getTileId(e + 1, t);var s = this.getTileId(e + 1, t + 1);var o = this.getTileId(e, t + 1);if (r != n) r = 0;else r = 1; if (i != n) i = 0;else i = 1; if (s != n) s = 0;else s = 1; if (o != n) o = 0;else o = 1; if (r == 0 && i == 0 && s == 0 && o == 0) return null;var u = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet,this._moveClipsNames["" + n] + r + "_" + i + "_" + s + "_" + o);u.stop();return u
};
FieldContainer.prototype.getTileId = function(e, t) {if (e <= -1 || t <= -1 || e >= this.gameManager.FIELD_WIDTH ||t >= this.gameManager.FIELD_HEIGHT) return 0;return this.field[e][t]
};
FieldContainer.prototype.getFigureByCell = function(e, t) {for (var n = 0; n < this.figures.length; n++)if (this.figures[n].isCellFigure(e, t)) return this.figures[n];console.log("OMFG figures = NULL )) cellX = " + e + " cellY = " + t);return null
};
FieldContainer.prototype.step = function(e, t) {for (var n = 0; n < this.figures.length; n++) this.figures[n].step(e, t);var r = false;while (true) {r = false;for (var n = 0; n < this.figures.length; n++)if (this.figures[n].postStep()) r = true;if (!r) break}for (var n = 0; n < this.figures.length; n++) this.figures[n].preGo();var i = false;for (n = 0; n < this.figures.length; n++)if (this.figures[n].go(e, t)) i = true;if (i) {(new MusicManager).playStep();this.gameManager.gui.starBar.addStep();this.addSaveStep()}
};
FieldContainer.prototype.checkFigureConnection = function() {var e = false;for (var t = 0; t < this.figures.length; t++)for (var n = t + 1; n < this.figures.length; n++)if (this.figures[t].connectToFigure(this.figures[n])) e = true;if (e) {for (var t = 0; t < this.figures.length; t++)if (this.figures[t].connecting) {this.removeChild(this.figures[t]);this.figures.splice(t, 1);t--}this.findFigures();if (!this.checkWin())(new MusicManager).playConnect()}
};
FieldContainer.prototype.checkWin = function() {var e = {};e["" + this.BLUE_ID] = 0;e["" + this.ORANGE_ID] = 0;e["" + this.BLACK_ID] = 0;e["" + this.PURPLE_ID] = 0;for (var t = 0; t < this.figures.length; t++) e["" + this.figures[t].cellId]++;for (var t in e)if (e[t] > 1) return false;this.gameManager.setGameOver();console.log("WIN!!!");// updateShare(this.gameManager.levelId + 1);// Play68.setRankingScoreDesc(this.gameManager.levelId + 1, Play68.rankingShowType.RANKING_SHOW_NO);return true
};
FieldContainer.prototype.moveComplete = function() {this._numMove++;if (this._numMove == this.figures.length) {this._moveComplete = true;this.checkFigureConnection()}
};
FieldContainer.prototype.addSaveStep = function() {var e = [];for (var t = 0; t < this.field.length; t++) e.push(this.field[t].slice(0));this.fieldsSteps.push(e);this.traceSteps()
};
FieldContainer.prototype.deleteStep = function() {if (this.gameManager.gui.starBar.stepNow > 0) {var e = this.fieldsSteps[this.gameManager.gui.starBar.stepNow - 1];for (var t = 0; t < e.length; t++)for (var n = 0; n < e[t].length; n++) this.field[t][n] = e[t][n];this.fieldsSteps.pop();console.log(this.fieldsSteps.length);this.gameManager.gui.starBar.stepNow = this.gameManager.gui.starBar.stepNow - 2;this.gameManager.gui.starBar.addStep();for (var t = 0; t < this.figures.length; t++) this.removeChild(this.figures[t]);this.figures.length = 0;this.findFigures()}this.traceSteps()
};
FieldContainer.prototype.traceSteps = function() {};
FigureBlocks = function(e, t, n) {createjs.Container.call(this);this.gameManager = t;this.field = e;this.fieldContainer = n;this._moveClipsNames = this.fieldContainer._moveClipsNames;this.cells = [];this.id = (new Jok.JokG).getNewid();this.figuresStep = [];this.connecting = false;this.tweenMove = null;this.eventMoveComplete = createjs.proxy(this.moveComplete, this);this.MOVE_TIME = 320;this.MOVE_CLOSE_PATH = this.gameManager.CELL_SIZE / 10
};
FigureBlocks.prototype = Object.create(createjs.Container.prototype);
FigureBlocks.prototype.constructor = FigureBlocks;
FigureBlocks.prototype.setCells = function(e) {this.cells = e
};
FigureBlocks.prototype.findAllCells = function(e, t) {this.cells.length = 0;if (this.field[e][t] == 0 || this.field[e][t] == this.fieldContainer.BLACK_ID) return false;this.cellId = this.field[e][t];this.addCell(e, t);this.drawOne(this.cellId);return true
};
FigureBlocks.prototype.testFigure = function() {var e = "" + this.cellId + " ";for (var t = 0; t < this.cells.length; t++) e += "" + this.cells[t].x + " " + this.cells[t].y + " ";console.log(e)
};
FigureBlocks.prototype.addCell = function(e, t) {if (e <= -1 || t <= -1 || e >= this.gameManager.FIELD_WIDTH || t >= this.gameManager.FIELD_HEIGHT) return;if (this.field[e][t] != this.cellId) return;if (!this.isCellFigure(e, t)) {this.cells.push(new createjs.Point(e, t));this.addCell(e - 1, t);this.addCell(e + 1, t);this.addCell(e, t - 1);this.addCell(e, t + 1)}
};
FigureBlocks.prototype.isCellFigure = function(e, t) {var n = 0;for (n = 0; n < this.cells.length; n++)if (this.cells[n].x == e && t == this.cells[n].y) return true;return false
};
FigureBlocks.prototype.drawOne = function(e) {var t = -1;var n = -1;for (t = -1; t < this.gameManager.FIELD_WIDTH; t++)for (n = -1; n < this.gameManager.FIELD_HEIGHT; n++) {var r = this.getSprTile(t, n, e);if (r != null) {r.x = this.gameManager.CELL_SIZE * t;r.y = this.gameManager.CELL_SIZE * n;this.addChild(r)}}this.casheAllTTTT()
};
FigureBlocks.prototype.casheAllTTTT = function() {};
FigureBlocks.prototype.getSprTile = function(e, t, n) {var r = this.getTileId(e, t);var i = this.getTileId(e + 1, t);var s = this.getTileId(e + 1, t + 1);var o = this.getTileId(e, t + 1);if (r != n) r = 0;else r = 1; if (i != n) i = 0;else i = 1; if (s != n) s = 0;else s = 1; if (o != n) o = 0;else o = 1; if (r == 0 && i == 0 && s == 0 && o == 0) return null;var u = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, this._moveClipsNames["" + n] + r + "_" + i + "_" + s + "_" + o);u.stop();return u
};
源码
需要源码请关注添加好友哦^ ^
转载:欢迎来到本站,转载请注明文章出处
https://ormcc.com/
这篇关于合体积木的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!