You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.7 KiB
71 lines
1.7 KiB
import * as WelcomeActions from '../../actions/welcome/welcome.actions';
|
|
import InitialsCtrl from './initials.controller';
|
|
import SETTINGS from '../../AppSettings';
|
|
|
|
let dispatch;
|
|
|
|
let finalScore = 800;
|
|
|
|
const scores = [
|
|
{ initials: "AAA", score: "0" },
|
|
{ initials: "AAA", score: "0" },
|
|
{ initials: "AAA", score: "0" },
|
|
{ initials: "AAA", score: "0" },
|
|
{ initials: "AAA", score: "0" },
|
|
];
|
|
|
|
const WelcomeCtrl = {
|
|
setDispatch: (d) => dispatch = d,
|
|
|
|
isHighScore: () => finalScore > 0,
|
|
|
|
gameOver: (score) => {
|
|
let found = -1;
|
|
finalScore = -1;
|
|
|
|
for (let i = 0; i < scores.length; i++) {
|
|
if (scores[i].score < score) {
|
|
found = i;
|
|
}
|
|
}
|
|
|
|
finalScore = -1;
|
|
if (found > -1) {
|
|
// scores.splice(found, { initials: 'ZZZ', score: score });
|
|
// scores.pop();
|
|
finalScore = score;
|
|
}
|
|
},
|
|
|
|
update: () => {
|
|
const scores = localStorage.getItem(SETTINGS.LOCAL_STORAGE_KEY);
|
|
|
|
if (scores !== null) {
|
|
dispatch(WelcomeActions.updateScores(scores));
|
|
}
|
|
},
|
|
|
|
keydown: (e) => {
|
|
if ((gameOverFlag === true && e.keyCode === 13) || (gameOverFlag === true && e.keyCode === 32)) {
|
|
}
|
|
else if (gameOverFlag === true) {
|
|
InitialsCtrl.keydown(e);
|
|
}
|
|
else if (e.keyCode === 32) {
|
|
this.props.dispatch(ModeActions.options());
|
|
}
|
|
},
|
|
|
|
doTheThing: () => {
|
|
const scores = localStorage.getItem(SETTINGS.LOCAL_STORAGE_KEY);
|
|
|
|
if (scores !== null) {
|
|
return scores[0].score;
|
|
}
|
|
|
|
return 0;
|
|
// localStorage.setItem(SETTINGS.LOCAL_STORAGE_KEY, scores);
|
|
},
|
|
};
|
|
|
|
export default WelcomeCtrl;
|
|
|