Message from JavaScript discussions

April 2019

— I didn't know

— 

class timeSystem {
constructor(){
time: null,
now: null
}
}
const system = new timeSystem()
class Game {
constructor(pace, money){
this.startTime = 464;
this.pace = pace;
this.money = money;
this.interval = null;
}
hour(a){
a = Math.floor(this.startTime/60)
return (a > 23) ?a = 0 :a
};
minute(a){
a = this.startTime%60
return (a < 10) ?'0'+a :a }
displayTime(){
return this.hour() +':'+this.minute()
}
tick(){
return this.startTime++
}
play(...func){

const queue = (...func)=>{
for(let f of func){
f()
}
}

this.interval = setInterval(()=>{
console.log(this.displayTime());
queue(...func)
this.tick()
console.log(system.time);
system.time++;}, 1000)
}
pause(){
return clearInterval(this.interval)
}
resume(){
this.pause()
this.play()
}
manage(actions, duration) {
this.pause();
this.play(
...actions.length === 0
? [
() =>
console.error('no function was called')
]
: actions.slice(0, 3));
setTimeout(
() => this.resume(),
duration);
}
}
const newGame = new Game(1000, 10000);
system.time = newGame.startTime

const test =()=>newGame.pause()
setTimeout(test, 10000)

class Cat {
constructor(name){
this.name = name;
this.energy = 100;
this.hunger = 100;
this.fun = 0;
this.fat = 0;
this.str = 0
this.humor = 100
}
walk(){
system.now = system.time;
}
}
const newCat = new Cat('Garfield')
newGame.manage([newCat.walk()])

This then

— TRGWII ??

— Now you have global state inside an instance

— I do this.time and this.now then?

— Also known as singleton pattern

— You don't need a second structure

— Never heard of

— Just use Game

— this.time = null;

— Ok I'll try

— Inside the constructor of Game