Message from JavaScript discussions

April 2019

β€” You’re welcome πŸŽ‰

β€” 

May I ask your opinion about one more thing... I made this fake time to have actions of the game's characters measured and executed in accordance to that time, there will be even an option to speed up the time that's why I added newGame.pace parameter. The idea is similar to those mobile games that you choose to do an action and it measures and counts the time that is left to execute it. i also want to do it in OOP style.

So I'm wondering if I am going in the right direction?

Ps. the class Game has a constructor so the user can save the games and load them later.

β€” I think you’re in good direction, but I never tried to implement something like that. It takes trial and error.

Message permanent page

β€” elxris I DID IT! now it finally works

β€” Check the timeout in the last line

β€” It checks the time after the function is paused

β€” I feel like something it’s not all right. Could you please send a file or something with all the code?

Message permanent page

β€” Let time = null;
class Game {
constructor(pace, money){
this.hour = (a) =>{
a = Math.floor(this.startTime/60)
return (a > 23) ?a = 0 :a
};
this.minute = (a) => {
a = this.startTime%60
return (a < 10) ?'0'+a :a }
this.startTime = 464;
this.pace = pace;
this.money = money; //12
this.interval = null;
this.process = null;
}
displayTime(){
return this.hour() +':'+this.minute()
}
ticking(){
return this.startTime++
}
play(){
this.interval = setInterval(()=>{
console.log(this.displayTime());
this.ticking()
time++;
console.log(time);
return time}, 1000)
return time
}
pause(){
return clearInterval(this.interval)
}
}

const newGame = new Game(1000, 10000);
const test =()=>newGame.pause()
setTimeout(test, 8000)

newGame.play(time)
time = newGame.startTime

const test2 = () => console.log(time)
setTimeout(test2,15000)

Message permanent page

β€” I'm not an expert but I know I got what I needed

β€” Ticking should probably just be tick

β€” Ok, if this is what you need and works for you it’s fine. But imagine having multiple instances of Game. And I think this is not a OOP pattern like you said you wanted.

Message permanent page

β€” Yeah naming functions and methods is causing me a real headache