parent
9ebdfe6e97
commit
7bfab9163b
16 changed files with 362 additions and 178 deletions
@ -0,0 +1,63 @@ |
||||
require('../../sass/high-score/high-score.scss'); |
||||
|
||||
import { Component } from 'react'; |
||||
import { connect } from 'react-redux'; |
||||
import Initials from './initials.component'; |
||||
|
||||
import * as ModeActions from '../../actions/mode.actions'; |
||||
import HighScoreCtrl from '../../controllers/high-score/high-score.controller'; |
||||
|
||||
let listener; |
||||
|
||||
export class Welcome extends Component { |
||||
componentDidMount() { |
||||
listener = HighScoreCtrl.keydown.bind(HighScoreCtrl); |
||||
window.addEventListener('keydown', listener); |
||||
|
||||
// HighScoreCtrl.setDispatch(this.props.dispatch);
|
||||
// HighScoreCtrl.retrieveScores();
|
||||
// HighScoreCtrl.updateScores(ScorebarCtrl.currentScore);
|
||||
}; |
||||
|
||||
componentWillUnmount() { |
||||
window.removeEventListener('keydown', listener); |
||||
}; |
||||
|
||||
render() { |
||||
// var entries = [];
|
||||
// this.props.values.map(function(v, i) {
|
||||
// entries.push(<HofRow initials={v.initials} score={v.score} rank={v.rank} key={i} />);
|
||||
// });
|
||||
|
||||
if (WelcomeCtrl.isHighScore() > 0) { |
||||
return ( |
||||
<div className='welcome'> |
||||
<img src="res/title.png" /> |
||||
<div className='spacer'></div> |
||||
<div className='line'>New high score!</div> |
||||
<div className='line'>Enter your initials:</div> |
||||
<Initials /> |
||||
</div> |
||||
); |
||||
} |
||||
else { |
||||
return ( |
||||
<div className='welcome'> |
||||
<img src="res/title.png" /> |
||||
<div className='line'>Press Spacebar for new game</div> |
||||
high scores here |
||||
</div> |
||||
); |
||||
} |
||||
|
||||
|
||||
}; |
||||
}; |
||||
|
||||
const select = (state) => { |
||||
return { |
||||
values: state.welcome.scores |
||||
} |
||||
}; |
||||
|
||||
export default connect(select)(Welcome); |
@ -1,6 +1,6 @@ |
||||
import { Component } from 'react'; |
||||
|
||||
export default class HighScoreEntry extends Component { |
||||
export default class HofRow extends Component { |
||||
render() { |
||||
return ( |
||||
<div className='entry'> |
@ -0,0 +1,71 @@ |
||||
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; |
@ -1,43 +1,30 @@ |
||||
import * as WelcomeActions from '../../actions/welcome/welcome.actions'; |
||||
import InitialsCtrl from './initials.controller'; |
||||
import * as ModeActions from '../../actions/mode.actions'; |
||||
import SETTINGS from '../../AppSettings'; |
||||
|
||||
let dispatch; |
||||
let update = true; |
||||
|
||||
const HighScoreCtrl = { |
||||
setDispatch: (d) => dispatch = d, |
||||
|
||||
keydown: (e) => { |
||||
if (update === true) { |
||||
InitialsCtrl.keydown(e); |
||||
} |
||||
else if (e.keyCode === 32) { |
||||
this.props.dispatch(ModeActions.options()); |
||||
} |
||||
}, |
||||
|
||||
getHighScore: () => { |
||||
const scores = localStorage.getItem(SETTINGS.LOCAL_STORAGE_KEY); |
||||
const emptyScores = [ |
||||
{ initials: "AAA", score: "0" }, |
||||
{ initials: "AAA", score: "0" }, |
||||
{ initials: "AAA", score: "0" }, |
||||
{ initials: "AAA", score: "0" }, |
||||
{ initials: "AAA", score: "0" }, |
||||
]; |
||||
|
||||
if (scores !== null) { |
||||
return scores[0].score; |
||||
} |
||||
|
||||
return 0; |
||||
}, |
||||
|
||||
gameOver: (score) => { |
||||
const WelcomeCtrl = { |
||||
setDispatch: (d) => dispatch = d, |
||||
|
||||
updateFromLocalStorage: () => { |
||||
const scores = localStorage.getItem(SETTINGS.LOCAL_STORAGE_KEY) || emptyScores; |
||||
dispatch(WelcomeActions.updateScores(scores)); |
||||
}, |
||||
|
||||
retrieveScores: () => { |
||||
const scores = localStorage.getItem(SETTINGS.LOCAL_STORAGE_KEY); |
||||
|
||||
if (scores !== null) { |
||||
dispatch(WelcomeActions.updateScores(scores)); |
||||
keydown: (e) => { |
||||
if (e.keyCode === 32) { |
||||
dispatch(ModeActions.options()); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
export default HighScoreCtrl; |
||||
export default WelcomeCtrl; |
||||
|
@ -0,0 +1,30 @@ |
||||
const Immutable = require('immutable'); |
||||
|
||||
import * as WelcomeActions from '../../actions/welcome/welcome.actions'; |
||||
|
||||
const initial = { |
||||
scores: [], |
||||
initials: [] |
||||
}; |
||||
|
||||
const reducer = (state = initial, action) => { |
||||
if (action.type !== WelcomeActions.WELCOME_ACTION) { |
||||
return state; |
||||
} |
||||
|
||||
switch (action.action) { |
||||
case WelcomeActions.UPDATE_SCORES: |
||||
return Immutable.Map(state) |
||||
.set('scores', action.scores) |
||||
.toObject(); |
||||
|
||||
case WelcomeActions.UPDATE_INITIALS: |
||||
return Immutable.Map(state) |
||||
.set('initials', action.initials) |
||||
.toObject(); |
||||
} |
||||
|
||||
return state; |
||||
}; |
||||
|
||||
export default reducer; |
@ -0,0 +1,16 @@ |
||||
@keyframes blink { |
||||
50% { |
||||
opacity: 0.6; |
||||
} |
||||
} |
||||
|
||||
@-webkit-keyframes blink { |
||||
50% { |
||||
opacity: 0.6; |
||||
} |
||||
} |
||||
|
||||
.blink { |
||||
animation: blink 1s step-start 0s infinite; |
||||
-webkit-animation: blink 1s step-start 0s infinite; |
||||
} |
@ -0,0 +1,104 @@ |
||||
.high-score { |
||||
$w: 350px; |
||||
|
||||
padding:20px; |
||||
text-align:center; |
||||
|
||||
img { |
||||
width:$w; |
||||
} |
||||
|
||||
.line { |
||||
line-height:30px; |
||||
} |
||||
|
||||
.spacer { |
||||
height:100px; |
||||
} |
||||
|
||||
@keyframes blink { |
||||
50% { |
||||
opacity: 0.6; |
||||
} |
||||
} |
||||
|
||||
@-webkit-keyframes blink { |
||||
50% { |
||||
opacity: 0.6; |
||||
} |
||||
} |
||||
|
||||
.blink { |
||||
animation: blink 1s step-start 0s infinite; |
||||
-webkit-animation: blink 1s step-start 0s infinite; |
||||
} |
||||
|
||||
.initial { |
||||
display:inline-block; |
||||
} |
||||
|
||||
// .highscores { |
||||
// margin:0 auto; |
||||
// width:350px; |
||||
// } |
||||
// |
||||
// .newgame { |
||||
// margin:20px 0; |
||||
// transition:opacity 0.1s ease; |
||||
// |
||||
// &.hidden { |
||||
// opacity: 0.5; |
||||
// } |
||||
// } |
||||
} |
||||
// |
||||
// .highscores { |
||||
// $w: 350px; |
||||
// |
||||
// font-size: 0; |
||||
// |
||||
// hr { |
||||
// border:0; |
||||
// border-top:1px solid #ccc; |
||||
// margin:20px auto; |
||||
// width: $w; |
||||
// } |
||||
// |
||||
// .blink { |
||||
// animation: blinker 1s none infinite; |
||||
// } |
||||
// |
||||
// @keyframes blinker { |
||||
// 50% { opacity: 0.6; } |
||||
// } |
||||
// |
||||
// .line { |
||||
// font-size:16px; |
||||
// line-height:30px; |
||||
// margin: 10px auto; |
||||
// text-align:center; |
||||
// width:$w; |
||||
// }; |
||||
// |
||||
// .entry { |
||||
// font-size:16px; |
||||
// line-height:40px; |
||||
// } |
||||
// |
||||
// .rank { |
||||
// display:inline-block; |
||||
// text-align:left; |
||||
// width:50px; |
||||
// } |
||||
// |
||||
// .initials { |
||||
// display:inline-block; |
||||
// width:100px; |
||||
// } |
||||
// |
||||
// .score { |
||||
// display:inline-block; |
||||
// text-align:right; |
||||
// width:200px; |
||||
// } |
||||
// } |
Loading…
Reference in new issue