Game play: Click to start the game. Wait for a random time. Then the background color will change (at T1 moment), when you need to click on the screen (at T2 moment), the game is over. Your reaction time is the day t2-t1.
Game logic:
The game logic is very easy, as you can see.
A common five interface, its five images can be replaced
Main code:
var mainlayer = cc. Layercolor.extend ({init:function () {///Initialize interface///0: Click Start Interface 1: Indicates the wait interface, 2: Indicates a click on interface 3: Result interface 4:too soon interface This.flag = 0;this._super (); this.size = cc. Director.getinstance (). Getwinsize (); This.setcolor (cc.c4 (180,170,160,255)); This.showtostart ();// Touch this.settouchenabled (TRUE);},///////////////////////////////////////////////////handles touch events///////////////////// Ontouchesended:function (touches,event) {},ontouchesbegan:function (touches,event) { Cc.log ("Ontouchsbegan", This.flag), switch (this.flag) {case 0:this.showwaite (); break;case 1:this.showtosoon (); ; case 2:this.showresult (); break;case 3:this.showwaite (); break;case 4:this.showwaite (); break;}},// Display Click Start Interface showtostart:function () {this.sprite = cc. Sprite.create (S_clicktostart); this.sprite.setPosition (THIS.SIZE.WIDTH/2,THIS.SIZE.HEIGHT/2); This.addchild ( this.sprite,1); This.flag = 0;},//Display Wait interface showwaite:function () {Cc.log ("Showwaite"); This.removeallchildren ();// Clear all controls This.unscheduleallcallbacks ();//Clear Timer this.sprite = cc. SprIte.create (S_waiteforgreen); this.sprite.setPosition (THIS.SIZE.WIDTH/2,THIS.SIZE.HEIGHT/2); This.addchild ( this.sprite,1); This.anim = cc. Sprite.create (S_waiteforgreenanim) this.anim.setPosition (this.size.width/2,this.size.height/2+200); This.addchild (this.anim,1); var action = cc. Sequence.create (CC. Fadeout.create (1.0), CC. Fadein.create (1.0)); var rep = cc. Repeatforever.create (Action), This.anim.runAction (rep), This.flag = 1;//output 1-10 random number randomtime = Math.floor ( Math.random () *10+1); This.schedule (this.showgreen,randomtime,1,0); Add Timer cc.log ("Randomtime", Randomtime)},//display the clicked Page Showgreen:function () {Cc.log ("Showgreen"); this.sprite = cc. Sprite.create (S_click); this.sprite.setPosition (THIS.SIZE.WIDTH/2,THIS.SIZE.HEIGHT/2); This.addchild (this.sprite , 1); This.flag = 2;this.date1 = new Date ();//After color change. Record a Time},showtosoon:function () {Cc.log ("Showtosoon"); This.unscheduleallcallbacks (); this.sprite = cc. Sprite.create (S_toosoon); this.sprite.setPosition (THIS.SIZE.WIDTH/2,THIS.SIZE.HEIGHT/2); This.addchild ( this.sprite,1); This.flag = 3;},//Display Result interface Showresult:function () {this.unscheduleallcallbacks (); this.date2 = new Date ();//Record Click Time This.date2.getTime ()-this.date1.getTime (); this.sprite = cc. Sprite.create (S_result); this.sprite.setPosition (THIS.SIZE.WIDTH/2,THIS.SIZE.HEIGHT/2); This.addchild ( this.sprite,1); Cc.log ("Showresult", time); This.timelabel = cc. Labelttf.create (time+ "MS", "Arial", This.timeLabel.setPosition), This.timeLabel.setColor (255,255,255); THIS.SIZE.WIDTH/2,THIS.SIZE.HEIGHT/2) This.addchild (this.timelabel,1); this.flag = 4;}}); var mainscene = cc. Scene.extend ({onenter:function () {this._super (); var layer = new Mainlayer (); Layer.init () this.addchild (layer);}});
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvawxvc3rlcg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvawxvc3rlcg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
(cocos2d-js game) test your reaction speed----------basic logic (UP)