|
|
|
@ -15,6 +15,7 @@ const Controls = function() { |
|
|
|
|
document.addEventListener('G-countdown', this.msgCountdown.bind(this));
|
|
|
|
|
document.addEventListener('G-players', this.msgPlayers.bind(this));
|
|
|
|
|
document.addEventListener('G-state', this.msgState.bind(this)); |
|
|
|
|
document.addEventListener('G-win', this.msgWin.bind(this)); |
|
|
|
|
|
|
|
|
|
// Click handlers
|
|
|
|
|
document.getElementById('controls-moves-reset').addEventListener('click', this.onClickMovesReset.bind(this)); |
|
|
|
@ -25,7 +26,10 @@ const Controls = function() { |
|
|
|
|
document.getElementById('controls-options-robots').addEventListener('click', this.onClickOptionsRobots.bind(this)); |
|
|
|
|
document.getElementById('controls-options-walls').addEventListener('click', this.onClickOptionsWalls.bind(this)); |
|
|
|
|
|
|
|
|
|
document.getElementById('controls-countdown-skip').addEventListener('click', this.onClickSkip.bind(this)); |
|
|
|
|
document.getElementById('controls-countdown-skip').addEventListener('click', this.onClickCountdownSkip.bind(this)); |
|
|
|
|
|
|
|
|
|
document.getElementById('controls-win-replay').addEventListener('click', this.onClickWinReplay.bind(this)); |
|
|
|
|
document.getElementById('controls-win-next').addEventListener('click', this.onClickWinNext.bind(this)); |
|
|
|
|
|
|
|
|
|
this.setState('CONNECTING'); |
|
|
|
|
} |
|
|
|
@ -70,7 +74,7 @@ Controls.prototype.setState = function(state) { |
|
|
|
|
'controls-moves', |
|
|
|
|
'controls-options', |
|
|
|
|
'controls-players', |
|
|
|
|
'controls-solution', |
|
|
|
|
'controls-win', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
blocks.forEach(id => document.getElementById(id).style.display = 'none'); |
|
|
|
@ -80,7 +84,7 @@ Controls.prototype.setState = function(state) { |
|
|
|
|
CONNECTING: ['controls-connection'], |
|
|
|
|
PLAY: ['controls-players', 'controls-moves', 'controls-options'], |
|
|
|
|
COUNTDOWN: ['controls-players', 'controls-moves', 'controls-countdown'], |
|
|
|
|
SOLUTION: ['controls-players', 'controls-solution'] |
|
|
|
|
WIN: ['controls-players', 'controls-win'] |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
(STATE[state] || []).forEach(id => document.getElementById(id).style.display = 'block'); |
|
|
|
@ -109,12 +113,16 @@ Controls.prototype.msgConnectionError = function() { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Controls.prototype.msgCountdown = function(evt) { |
|
|
|
|
this.setState('COUNTDOWN'); |
|
|
|
|
|
|
|
|
|
document.getElementById('controls-countdown-moves').innerHTML = evt.detail.body.moveCount; |
|
|
|
|
document.getElementById('controls-countdown-player').innerHTML = this.names[evt.detail.body.id]; |
|
|
|
|
document.getElementById('controls-countdown-player').innerHTML = `${this.names[evt.detail.body.id]} has a solution!`; |
|
|
|
|
|
|
|
|
|
const { duration, timestamp } = evt.detail.body; |
|
|
|
|
|
|
|
|
|
this.countdownStart(evt.detail.body.duration); |
|
|
|
|
const now = new Date().getTime(); |
|
|
|
|
const diff = Math.ceil((now - timestamp) / 1000); |
|
|
|
|
const remaining = duration - diff; |
|
|
|
|
|
|
|
|
|
this.countdownStart(remaining); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Controls.prototype.msgSkip = function() { |
|
|
|
@ -160,6 +168,11 @@ Controls.prototype.msgState = function(evt) { |
|
|
|
|
this.setState(evt.detail.body); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Controls.prototype.msgWin = function(evt) { |
|
|
|
|
document.getElementById('controls-win-message').innerHTML = `Congratulations ${this.names[evt.detail.body.id]} !`; |
|
|
|
|
document.getElementById('controls-win-count').innerHTML = evt.detail.body.moveCount; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//===== Click handlers
|
|
|
|
|
|
|
|
|
|
Controls.prototype.dispatch = function(evt, data) { |
|
|
|
@ -197,96 +210,17 @@ Controls.prototype.onClickMovesUndo = function() { |
|
|
|
|
|
|
|
|
|
// Countdown block
|
|
|
|
|
|
|
|
|
|
Controls.prototype.onClickSkip = function() { |
|
|
|
|
Controls.prototype.onClickCountdownSkip = function() { |
|
|
|
|
this.dispatch('L-skip'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//===== THE TRASH BIN OF HISTORY
|
|
|
|
|
// Controls.prototype.msgRobots = function(evt) {
|
|
|
|
|
// this.starts = [];
|
|
|
|
|
// this.moves = [];
|
|
|
|
|
|
|
|
|
|
// evt.detail.body.forEach(({ id, i, j}) => {
|
|
|
|
|
// this.starts.push({ id, i, j });
|
|
|
|
|
// this.moves.push({ id, i, j });
|
|
|
|
|
// });
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// Controls.prototype.msgGuess = function(evt) {
|
|
|
|
|
// const blurbs = [ " has a solution: ", " can do it in ", " says, maybe ", " wagers ",
|
|
|
|
|
// " reckons ", " is pretty sure it's ", ", confidently: ", " wants it to be ",
|
|
|
|
|
// " says ", " hazards ", " guesses ", " thinks it might be "];
|
|
|
|
|
// const blurb = blurbs[Math.floor(Math.random() * blurbs.length)];
|
|
|
|
|
|
|
|
|
|
// const msg = evt.detail;
|
|
|
|
|
// const guess = msg.guess;
|
|
|
|
|
|
|
|
|
|
// this.currentWinningGuess = guess;
|
|
|
|
|
|
|
|
|
|
// document.getElementById('controls-panic').querySelector('.controls-alert-urgent').innerHTML = (`${this.names[msg.id]}${blurb}${guess} moves.`);
|
|
|
|
|
// this.showPanic();
|
|
|
|
|
// this.countdownStart(5);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Controls.prototype.msgReset = function() {
|
|
|
|
|
// // Broadcast starting locations.
|
|
|
|
|
// this.moves = [];
|
|
|
|
|
// this.starts.forEach(move => {
|
|
|
|
|
// const evtMove = new CustomEvent('L-move', { detail: move });
|
|
|
|
|
// document.dispatchEvent(evtMove);
|
|
|
|
|
// });
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// Controls.prototype.msgUndo = function(evt) {
|
|
|
|
|
// if (this.moves.length <= this.starts.length) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const { id } = this.moves.pop();
|
|
|
|
|
|
|
|
|
|
// const indexOfPreviousMove = this.moves.reduce((acc, v, i) => (v.id === id ? i : acc), -1);
|
|
|
|
|
// const previousMove = this.moves.splice(indexOfPreviousMove, 1);
|
|
|
|
|
|
|
|
|
|
// const evtMove = new CustomEvent('L-move', { detail: previousMove[0] });
|
|
|
|
|
// document.dispatchEvent(evtMove);
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// Controls.prototype.msgAttempt = function() {
|
|
|
|
|
// alert("Ready for winning attempt!");
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// Controls.prototype.showWaiting = function() {
|
|
|
|
|
// document.getElementById('controls-start').parentNode.style.display = '';
|
|
|
|
|
// document.getElementById('controls-walls').parentNode.style.display = '';
|
|
|
|
|
// document.getElementById('controls-robots').parentNode.style.display = '';
|
|
|
|
|
|
|
|
|
|
// document.getElementById('controls-stop').parentNode.style.display = 'none';
|
|
|
|
|
// // document.getElementById('controls-moves-reset').parentNode.style.display = 'none';
|
|
|
|
|
// document.getElementById('controls-guesses').style.display = 'none';
|
|
|
|
|
// document.getElementById('controls-panic').style.display = 'none';
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// Controls.prototype.showPanic = function() {
|
|
|
|
|
// this.showGuessing();
|
|
|
|
|
// document.getElementById('controls-panic').style.display = '';
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// Controls.prototype.onClickStart = function() {
|
|
|
|
|
// this.dispatch('L-start');
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// Controls.prototype.onClickStop = function() {
|
|
|
|
|
// this.dispatch('L-stop');
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// Controls.prototype.msgStop = function() {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// document.addEventListener('L-reset', this.msgReset.bind(this));
|
|
|
|
|
// document.addEventListener('L-undo', this.msgUndo.bind(this));
|
|
|
|
|
// document.addEventListener('G-stop', this.msgStop.bind(this));
|
|
|
|
|
// document.addEventListener('G-start', this.msgStart.bind(this));
|
|
|
|
|
// document.addEventListener('G-guess', this.msgGuess.bind(this));
|
|
|
|
|
// document.getElementById('controls-start').addEventListener('click', this.onClickStart.bind(this));
|
|
|
|
|
// document.getElementById('controls-stop').addEventListener('click', this.onClickStop.bind(this));
|
|
|
|
|
// Win block
|
|
|
|
|
Controls.prototype.onClickWinReplay = function() { |
|
|
|
|
// this.dispatch('L-skip');
|
|
|
|
|
alert('win replay') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Controls.prototype.onClickWinNext = function() { |
|
|
|
|
// this.dispatch('L-skip');
|
|
|
|
|
alert('win next') |
|
|
|
|
} |