Created
October 31, 2014 00:33
-
-
Save omas/73b0154024d61f383ed3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enchant(); // enchantライブラリ呼び出し | |
| var game,stage; // GameCore,SceneGroupオブジェクト | |
| var gs = {fps:30}; // Gameのfps | |
| gs.canvas = {height:320,width:320}; // Windowの高さ,幅 | |
| // ================================================== | |
| var Panel = enchant.Class.create(enchant.Label,{ | |
| initialize:function(id){ | |
| enchant.Label.call(this,id); | |
| this.id = id; | |
| this.text = id + 1; | |
| this.size = 95; | |
| this.height = this.size; | |
| this.width = this.size; | |
| this.font = this.size + "px serif"; | |
| this.textAlign = "center"; | |
| this.color = "white"; | |
| this.backgroundColor = "black" | |
| }, | |
| ontouchstart:function(){ | |
| if (this.id === game.correct) { | |
| game.correct++; | |
| this.backgroundColor = "green"; | |
| } | |
| } | |
| }); | |
| var Panels = enchant.Class.create({ | |
| initialize:function() { | |
| this.panels = []; | |
| this.create(); | |
| this.shuffle(); | |
| this.display(); | |
| }, | |
| create:function() { | |
| for (var i = 0; i < 9; i++) { | |
| this.panels.push(new Panel(i)); | |
| }; | |
| }, | |
| shuffle:function(){ | |
| var len = this.panels.length | |
| this.panels.forEach(function(panel,index,panels){ | |
| var random = ~~(Math.random() * len); | |
| var tmp = panels[index]; | |
| panels[index] = panels[random]; | |
| panels[random] = tmp; | |
| }); | |
| }, | |
| display:function(){ | |
| var offset = {x:10,y:10}; | |
| this.panels.forEach(function(panel,index){ | |
| panel.x = 100 * (index % 3) + offset.x; | |
| panel.y = 100 * ~~(index / 3) + offset.y; | |
| stage.addChild(panel); | |
| }); | |
| } | |
| }); | |
| window.onload = function(){ | |
| game = new Core(); | |
| game.correct = 0; | |
| stage = game.rootScene; | |
| game.onload = function(){ | |
| }; | |
| game.start(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment