|
|
|
@ -52,6 +52,14 @@ |
|
|
|
|
width: 8px; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.board-robot { |
|
|
|
|
border-radius: 18px; |
|
|
|
|
height: 36px; |
|
|
|
|
margin: 2px; |
|
|
|
|
position: absolute; |
|
|
|
|
width: 36px; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.square{ |
|
|
|
|
background: #ddd; |
|
|
|
|
border-style: solid; |
|
|
|
@ -168,21 +176,6 @@ |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://github.com/websockets/ws |
|
|
|
|
// const WebSocket = require('ws'); |
|
|
|
|
|
|
|
|
|
// const ws = new WebSocket('ws://www.host.com/path'); |
|
|
|
|
|
|
|
|
|
// ws.on('open', function open() { |
|
|
|
|
// ws.send('something'); |
|
|
|
|
// }); |
|
|
|
|
|
|
|
|
|
// ws.on('message', function incoming(data) { |
|
|
|
|
// console.log(data); |
|
|
|
|
// }); |
|
|
|
|
|
|
|
|
|
// BROWSER |
|
|
|
|
var connection = new WebSocket('ws://localhost:8080/ricochet', ['soap', 'xmpp']); |
|
|
|
|
|
|
|
|
|
// connection.onopen = function (evt) {}; |
|
|
|
@ -191,6 +184,7 @@ |
|
|
|
|
connection.onmessage = function (msg) { |
|
|
|
|
const data = JSON.parse(msg.data) |
|
|
|
|
if (!data.head || !data.body) { |
|
|
|
|
console.warn("Unprocessable entity: ", msg) |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -204,6 +198,13 @@ |
|
|
|
|
case 'walls': |
|
|
|
|
Board.placeWalls(data.body); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'robots': |
|
|
|
|
Board.placeRobots(data.body); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
console.warn("Unhandled message: ", msg) |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -237,6 +238,21 @@ |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
placeRobots: (robots) => { |
|
|
|
|
robots.forEach(robot => { |
|
|
|
|
const [color, x, y] = robot; |
|
|
|
|
console.warn(color) |
|
|
|
|
|
|
|
|
|
const r = document.createElement('div'); |
|
|
|
|
r.className = 'board-robot'; |
|
|
|
|
r.style.background = color; |
|
|
|
|
r.style.left = 40 * x + 'px'; |
|
|
|
|
r.style.top = 40 * y + 'px'; |
|
|
|
|
|
|
|
|
|
document.getElementById('board').appendChild(r); |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
placeWall: (id, className, x, y) => { |
|
|
|
|
if (document.getElementById(id)) { |
|
|
|
|
return; |
|
|
|
@ -248,13 +264,11 @@ |
|
|
|
|
w.style.left = y + 'px'; |
|
|
|
|
w.className = className; |
|
|
|
|
|
|
|
|
|
const board = document.getElementById('board'); |
|
|
|
|
board.appendChild(w); |
|
|
|
|
document.getElementById('board').appendChild(w); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
placeWalls: (walls) => { |
|
|
|
|
walls.forEach(buffer => { |
|
|
|
|
const wall = new Int8Array(buffer); |
|
|
|
|
walls.forEach(wall => { |
|
|
|
|
const [x, y, north, south, east, west] = wall; |
|
|
|
|
|
|
|
|
|
const pxX = 40 * x; |
|
|
|
|