diff --git a/README.txt b/README.txt index 606bb0d..a2a70e0 100644 --- a/README.txt +++ b/README.txt @@ -9,23 +9,26 @@ Any movement, including initial locations, is represented by pushing or popping A victory state can be stored by taking a snapshot of the current stack. -## Icons +## Credit Icons from [https://game-icons.net](https://game-icons.net) ## TODO - win declare - replay stack -- countdown skip -- Extract loader from join.css and kill join.css, join.js +- countdown skip - slide arrows - chat box - no cancel from name prompt -- restore state on join +- clear out the trash bins of history (client) +- handle conn interrupt +- donate link heart fill in not underline +- Robots not resizing (shadows do though) - limit concurrent players, make sure connections are closed - move websocket server to /core - dynamic socket server resolution - walls and winstate algorithm +- restore name prompt - tutorial - donate link diff --git a/assets/gas-giant.png b/assets/gas-giant.png new file mode 100644 index 0000000..f6a4551 Binary files /dev/null and b/assets/gas-giant.png differ diff --git a/assets/stars.png b/assets/stars.png new file mode 100644 index 0000000..9fdb59c Binary files /dev/null and b/assets/stars.png differ diff --git a/client/connection.js b/client/connection.js index a877f8b..7bf511d 100644 --- a/client/connection.js +++ b/client/connection.js @@ -39,7 +39,8 @@ Connection.prototype.connect = function(){ const names = ["Biff", "Morty", "Herb", "Chester", "Lyle", "Cap", "Dale", "Ned", "Mindy", "Frankie", "Gabriel", "Mona", "Dolores", "Sepulveda", "Venus", "Blingbing", "Cyrpt"] const r = Math.floor(Math.random() * names.length); - const rawInput = names[r] //prompt("What is your name?"); + const rawInput = names[r] + // const rawInput = prompt("What is your name?"); this.ws = new WebSocket('ws://localhost:8080/ricochet?name=' + rawInput); @@ -74,14 +75,15 @@ Connection.prototype.onReceiveMessage = function({ data }) { let eventName; switch (msg.type) { - case 'connected': eventName = 'G-connected'; break; case 'countdown': eventName = 'G-countdown'; break; + case 'connected': eventName = 'G-connected'; break; case 'guess': eventName = 'G-guess'; break; case 'players': eventName = 'G-players'; break; case 'robots': eventName = 'G-robots'; break; case 'skip': eventName = 'G-skip'; break; case 'solve': eventName = 'G-solve'; break; case 'start': eventName = 'G-start'; break; + case 'state': eventName = 'G-state'; break; case 'stop': eventName = 'G-stop'; break; case 'walls': eventName = 'G-walls'; break; case 'winstate': eventName = 'G-winstate'; break; diff --git a/client/controls.js b/client/controls.js index 9f3ba5d..d7ffb14 100644 --- a/client/controls.js +++ b/client/controls.js @@ -4,35 +4,35 @@ const Controls = function() { - const evt = new Event('L-join'); - document.dispatchEvent(evt); - - // this.starts = []; // this.timers = {}; // // "Local" and "Global" messages -// document.addEventListener('L-connected', this.msgConnected.bind(this)); + document.addEventListener('L-conn-error', this.msgConnectionError.bind(this)); document.addEventListener('L-stack', this.msgStack.bind(this)); // document.addEventListener('L-reset', this.msgReset.bind(this)); // document.addEventListener('L-undo', this.msgUndo.bind(this)); // document.addEventListener('G-guess', this.msgGuess.bind(this)); - document.addEventListener('G-countdown', this.msgCountdown.bind(this)); + document.addEventListener('G-connected', this.msgCountdown.bind(this)); + document.addEventListener('G-countdown', this.msgConnected.bind(this)); document.addEventListener('G-players', this.msgPlayers.bind(this)); - document.addEventListener('G-skip', this.msgSkip.bind(this)); - document.addEventListener('G-start', this.msgStart.bind(this)); - document.addEventListener('G-stop', this.msgStop.bind(this)); + // document.addEventListener('G-skip', this.msgSkip.bind(this)); + // document.addEventListener('G-start', this.msgStart.bind(this)); + document.addEventListener('G-state', this.msgState.bind(this)); + // document.addEventListener('G-stop', this.msgStop.bind(this)); // Click handlers - document.getElementById('controls-reset').addEventListener('click', this.onClickReset.bind(this)); - document.getElementById('controls-robots').addEventListener('click', this.onClickRobots.bind(this)); - document.getElementById('controls-skip').addEventListener('click', this.onClickSkip.bind(this)); - document.getElementById('controls-start').addEventListener('click', this.onClickStart.bind(this)); - document.getElementById('controls-stop').addEventListener('click', this.onClickStop.bind(this)); - document.getElementById('controls-submit').addEventListener('click', this.onClickSubmit.bind(this)); - document.getElementById('controls-undo').addEventListener('click', this.onClickUndo.bind(this)); - document.getElementById('controls-walls').addEventListener('click', this.onClickWalls.bind(this)); + // document.getElementById('controls-reset').addEventListener('click', this.onClickReset.bind(this)); + // document.getElementById('controls-robots').addEventListener('click', this.onClickRobots.bind(this)); + // document.getElementById('controls-skip').addEventListener('click', this.onClickSkip.bind(this)); + // document.getElementById('controls-start').addEventListener('click', this.onClickStart.bind(this)); + // document.getElementById('controls-stop').addEventListener('click', this.onClickStop.bind(this)); + // document.getElementById('controls-submit').addEventListener('click', this.onClickSubmit.bind(this)); + // document.getElementById('controls-undo').addEventListener('click', this.onClickUndo.bind(this)); + // document.getElementById('controls-walls').addEventListener('click', this.onClickWalls.bind(this)); + + this.setState('CONNECTING'); } //===== Countdown @@ -84,62 +84,81 @@ const Controls = function() { // document.getElementById('controls-panic').style.display = ''; // }; +Controls.prototype.setState = function(state) { + const blocks = [ + 'controls-connection', + 'controls-countdown', + 'controls-moves', + 'controls-options', + 'controls-players', + 'controls-solution', + ]; + + blocks.forEach(id => document.getElementById(id).style.display = 'none'); + + // IDs to show for each state. + const STATE = { + CONNECTING: ['controls-connection'], + PLAY: ['controls-players', 'controls-moves', 'controls-options'], + COUNTDOWN: ['controls-players', 'controls-moves', 'controls-countdown'], + SOLUTION: ['controls-players', 'controls-solution'] + }; + + (STATE[state] || []).forEach(id => document.getElementById(id).style.display = 'block'); +}; + //===== Message handlers +Controls.prototype.msgConnected = function() { + +}; + +Controls.prototype.msgConnectionError = function() { + this.setState('CONNECTING'); +}; + Controls.prototype.msgCountdown = function(evt) { - // this.showWaiting(); - console.error(evt); - alert("COUNTDOWN RECEIVED"); + }; Controls.prototype.msgStack = function(evt) { const robots = evt.detail.reduce((acc, { id }) => acc.has(id) ? acc : acc.add(id), new Set()); const moveCount = evt.detail.length - robots.size; - document.getElementById('controls-moves').innerHTML = moveCount; - document.getElementById('controls-undo').style.display = moveCount > 0 ? 'block' : 'none'; + // document.getElementById('controls-moves').innerHTML = moveCount; + // document.getElementById('controls-undo').style.display = moveCount > 0 ? 'block' : 'none'; }; Controls.prototype.msgPlayers = function(evt) { - const container = document.getElementById('controls-players'); - const names = evt.detail.body; - const keys = Object.keys(names); - - if (keys.length > 0) { - const nobody = document.getElementById('controls-players-nobody'); - nobody && nobody.parentNode.removeChild(nobody); - } + this.names = evt.detail.body; - keys.forEach(connectionId => { - const id = `player-${connectionId}`; - - if (document.getElementById(id)) { - return; - } - - const n = document.createElement('div'); - n.id = id; - n.innerHTML = names[connectionId]; - n.className = 'controls-player'; - container.appendChild(n) + const container = document.getElementById('controls-players'); + container.querySelectorAll('.controls-player').forEach(el => { + container.removeChild(el); }); - this.names = names; + const keys = Object.keys(this.names); + if (keys.length > 1) { + keys.forEach(connectionId => { + const n = document.createElement('div'); + n.innerHTML = this.names[connectionId]; + n.className = 'controls-player'; + container.appendChild(n) + }); + } - container.querySelectorAll('.controls-player').forEach(el => { - const id = el.id.split('player-').pop(); - if (!this.names[id]) { - container.removeChild(el); - } - }); + const msg = container.querySelector('.controls-message'); + msg.innerHTML = (keys.length > 1 ? '' : 'Nobody is in the game yet.'); + msg.style.display = (keys.length > 1 ? 'none' : 'block'); }; Controls.prototype.msgSkip = function() { // this.coundownComplete(); }; -Controls.prototype.msgStart = function() { - // +Controls.prototype.msgState = function(evt) { + // this.setState(evt.detail.body); + this.setState('SOLUTION') }; Controls.prototype.msgStop = function() { diff --git a/client/grid.js b/client/grid.js index c716211..bec1af2 100644 --- a/client/grid.js +++ b/client/grid.js @@ -432,35 +432,3 @@ Grid.prototype.msgWinState = function(evt) { this.winstate = evt.detail.body; this.drawWinState(); }; - -//============ THE TRASH BIN OF HISTORY -// Content.prototype.drawRobot = function({ id, i, j }) { -// const robot = document.getElementById(`robot-${id}`); -// const arrows = document.getElementById(`arrows-${id}`); - -// const { x, y } = this.ijToXy({ i, j }); -// const s = this.squares.sideLength; - -// robot.style.display = 'block'; -// robot.style.left = x + 'px'; -// robot.style.top = y + 'px'; -// robot.dataset.i = i; -// robot.dataset.j = j; - -// this.robots[`${i}-${j}`] = id; - -// arrows.style.display = 'block'; -// arrows.style.left = (x - s) + 'px'; -// arrows.style.top = (y - s) + 'px'; -// }; - -// Content.prototype.ijToXy = function({ i, j }) { -// if ((i !== 0 && !i) || (j !== 0 && !j)) { -// return -// } - -// return { -// x: this.squares.x0 + i * this.squares.sideLength, -// y: this.squares.y0 + j * this.squares.sideLength -// } -// }; \ No newline at end of file diff --git a/client/join.js b/client/join.js deleted file mode 100644 index 6167789..0000000 --- a/client/join.js +++ /dev/null @@ -1,52 +0,0 @@ -const Join = function() { - document.addEventListener('L-conn-error', this.onConnectionError.bind(this)); - document.addEventListener('L-conn-open', this.onConnectionOpen.bind(this)); - - document.getElementById('join-setup-start').addEventListener('click', this.onClickStart.bind(this)); - document.getElementById('join-setup-go').addEventListener('click', this.onClickStart.bind(this)); - document.getElementById('join-setup-back').addEventListener('click', this.onClickBack.bind(this)); - - this.showSetup(); -}; - -Join.prototype.showSetup = function() { - document.getElementById('join-setup').style.display = 'block'; - document.getElementById('join-connect').style.display = 'none'; - document.getElementById('join-error').style.display = 'none'; -}; - -Join.prototype.showLoad = function() { - document.getElementById('join-setup').style.display = 'none'; - document.getElementById('join-connect').style.display = 'block'; - document.getElementById('join-error').style.display = 'none'; -}; - -Join.prototype.showError = function() { - document.getElementById('join-setup').style.display = 'none'; - document.getElementById('join-connect').style.display = 'none'; - document.getElementById('join-error').style.display = 'block'; -}; - -Join.prototype.onClickBack = function() { - this.showSetup(); -}; - -Join.prototype.onClickGo = function() { - this.showLoad(); -}; - -Join.prototype.onClickStart = function() { - this.showLoad(); - - const evt = new Event('L-join'); - document.dispatchEvent(evt); -}; - -Join.prototype.onConnectionError = function() { - this.showError(); -}; - -Join.prototype.onConnectionOpen = function() { - document.getElementById('join').style.display = 'none'; - this.showSetup(); -}; \ No newline at end of file diff --git a/controls.css b/controls.css deleted file mode 100644 index 3d48329..0000000 --- a/controls.css +++ /dev/null @@ -1,100 +0,0 @@ -#controls-container { - background: #e7e7e7; - border: solid #e7e7e7; - border-width: 0 10px; - bottom: 0; - left: 20px; - position: absolute; - top: 0; - width: 300px; - z-index: 1; -} - -.controls-title { - background-color: #639978; - background-image: url('sprite-robots.png'); - /*color: #fff;*/ - font-size: 12px; - line-height: 48px; - margin-bottom: 24px; - text-align: center; -} - -.controls-subtitle { - background-color: #4D3243; - background-image: linear-gradient(90deg, #4D3243, #3C2132); - color: #fff; - padding: 12px; - margin: 24px 0 12px 0; -} - -.controls-alert-info { - background: #21dfae; - color: #222; - padding: 12px; - margin: 24px 0 12px 0; -} - -.controls-alert-urgent { - background: #DE4F21; - color: #fff; - padding: 12px; - margin: 24px 0 12px 0; -} - -.controls-row { - align-items: center; - display: flex; - flex-direction: row; - padding: 8px; -} - -.controls-row :nth-child(2) { - flex: 1; - margin: 0 8px; - width: 100%; -} - -.controls-player { - padding: 8px; -} - -#controls-footer { - bottom: 0; - left: 0; - padding: 24px; - position: absolute; - right: 0; - text-align: center; -} - -#controls-footer a { - color: #639699; - font-size: 24px; - text-decoration: none; -} - -#controls-footer a:hover { - text-decoration: underline; -} - -.controls-button { - background: none; - border: 1px solid #888; - color: #444; - cursor: pointer; - font-size: 12px; - padding: 4px 8px; -} - -.controls-button:hover { - background: #21dfae; - border-color: #21dfae; - color: #222; -} - -#controls-start { - display: block; - margin: 0 auto; - padding: 4px 8px; -} \ No newline at end of file diff --git a/index.css b/index.css deleted file mode 100644 index 07e9fe9..0000000 --- a/index.css +++ /dev/null @@ -1,16 +0,0 @@ -* { - box-sizing: border-box; - font-family: Montserrat; -} - -body { - overflow: hidden; -} - -/* -PALETTE: -21DFAE Aquamarine -4D3243 Plum -DE4F21 Fire -639699 Cadet -*/ diff --git a/index.html b/index.html index fd6faca..df72504 100644 --- a/index.html +++ b/index.html @@ -1,115 +1,92 @@ -
- - -