forked from vergnet/application-amicale
Fixed game tick interval continuing after game exit
This commit is contained in:
parent
8864e686bd
commit
9f4a8c837d
2 changed files with 9 additions and 28 deletions
|
@ -109,7 +109,6 @@ export default class GameLogic {
|
||||||
|
|
||||||
onClock(callback: Function) {
|
onClock(callback: Function) {
|
||||||
this.#gameTime++;
|
this.#gameTime++;
|
||||||
console.log(this.#gameTime);
|
|
||||||
callback(this.#gameTime);
|
callback(this.#gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,11 +205,15 @@ export default class GameLogic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
endGame(isRestart: boolean) {
|
stopGame() {
|
||||||
this.#gameRunning = false;
|
this.#gameRunning = false;
|
||||||
this.#gamePaused = false;
|
this.#gamePaused = false;
|
||||||
clearInterval(this.#gameTickInterval);
|
clearInterval(this.#gameTickInterval);
|
||||||
clearInterval(this.#gameTimeInterval);
|
clearInterval(this.#gameTimeInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
endGame(isRestart: boolean) {
|
||||||
|
this.stopGame();
|
||||||
this.endCallback(this.#gameTime, this.#scoreManager.getScore(), isRestart);
|
this.endCallback(this.#gameTime, this.#scoreManager.getScore(), isRestart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,10 @@ class GameMainScreen extends React.Component<Props, State> {
|
||||||
this.startGame();
|
this.startGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.logic.stopGame();
|
||||||
|
}
|
||||||
|
|
||||||
getRightButton = () => {
|
getRightButton = () => {
|
||||||
return <MaterialHeaderButtons>
|
return <MaterialHeaderButtons>
|
||||||
<Item title="pause" iconName="pause" onPress={this.togglePause}/>
|
<Item title="pause" iconName="pause" onPress={this.togglePause}/>
|
||||||
|
@ -168,32 +172,6 @@ class GameMainScreen extends React.Component<Props, State> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
showGameOverConfirm() {
|
|
||||||
let message = i18n.t("screens.game.gameOver.score") + this.state.gameScore + '\n';
|
|
||||||
message += i18n.t("screens.game.gameOver.level") + this.state.gameLevel + '\n';
|
|
||||||
message += i18n.t("screens.game.gameOver.time") + this.getFormattedTime(this.state.gameTime) + '\n';
|
|
||||||
const onDismiss = () => {
|
|
||||||
this.onDialogDismiss();
|
|
||||||
this.startGame();
|
|
||||||
};
|
|
||||||
this.setState({
|
|
||||||
dialogVisible: true,
|
|
||||||
dialogTitle: i18n.t("screens.game.gameOver.text"),
|
|
||||||
dialogMessage: message,
|
|
||||||
dialogButtons: [
|
|
||||||
{
|
|
||||||
title: i18n.t("screens.game.gameOver.exit"),
|
|
||||||
onPress: () => this.props.navigation.goBack()
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: i18n.t("screens.game.resume"),
|
|
||||||
onPress: onDismiss
|
|
||||||
}
|
|
||||||
],
|
|
||||||
onDialogDismiss: onDismiss,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
startGame = () => {
|
startGame = () => {
|
||||||
this.logic.startGame(this.onTick, this.onClock, this.onGameEnd);
|
this.logic.startGame(this.onTick, this.onClock, this.onGameEnd);
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
Loading…
Reference in a new issue