docsa
5/11/2017 - 9:14 PM

hash

hash

{
  "version": "0.12.1",
  "EmberENV": {
    "FEATURES": {}
  },
  "options": {
    "use_pods": false,
    "enable-testing": false
  },
  "dependencies": {
    "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
    "ember": "2.12.0",
    "ember-template-compiler": "2.12.0",
    "ember-testing": "2.12.0"
  },
  "addons": {
    "ember-data": "2.12.1"
  }
}
<h1> Play Game </h1>
<h2>Score:{{model.score}}</h2>
<br>
<button {{action "setScore"}}>Set Score</button>&nbsp;
<button {{action "gameOver"}}>Game over</button>
<h1> new Game </h1>

setting up..
<h1> Games </h1>

<button  type="submit" {{action "newGame"}}>Play</button>
{{#link-to 'game'}}Game{{/link-to}}
<hr>
{{outlet}}
import Ember from 'ember';
import DS from 'ember-data';

export default Ember.Route.extend({
  score:0,
	model: function() {
  return {score: this.get("score")};
	},
   
  actions:{
    setScore() {
      console.log("model:",this.get('score'));
      var newScore=Math.floor((Math.random() * 100) + 1);
      console.log("NewScore:",newScore);
      this.score=newScore;
      this.refresh();
    },
   gameOver() {
  	this.transitionTo("game.new");
  }
  },
  resetController: function(controller,isExiting ) { 
  	console.log("resetController play", isExiting)
    if(isExiting) {
      this.score=0;
  	}
  }
});
//new
import Ember from 'ember';

export default Ember.Route.extend({
  afterModel() {
  	Ember.run.later(this, function() {this.transitionTo("game.play");},1000);
  }
});
//index
import Ember from 'ember';

export default Ember.Route.extend({
  actions: {
    newGame() {
      this.transitionTo("game.new");
    }
  }
});
import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
  location: 'none',
  rootURL: config.rootURL
});

Router.map(function() {
  this.route('game', function() {
    this.route('new');
    this.route('play');
  });
});

export default Router;
import Ember from 'ember';

export default Ember.Controller.extend({
  appName: 'Ember Twiddle'
});