mirror of
https://github.com/MaciejkaG/statki.git
synced 2024-11-30 00:42:54 +01:00
Major changes
- Added ship removing, after changing their mind or missclicking, a player can rightclick a ship to remove it - Multiple bug fixes and stability improvements
This commit is contained in:
parent
bb17dc47ba
commit
ee0b172067
13
index.js
13
index.js
@ -229,6 +229,8 @@ io.on('connection', async (socket) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await redis.json.set(`game:${playerGame.id}`, '$.state', "preparation");
|
await redis.json.set(`game:${playerGame.id}`, '$.state', "preparation");
|
||||||
|
} else if (io.sockets.adapter.rooms.get(playerGame.id).size > 2) {
|
||||||
|
socket.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,11 +248,20 @@ io.on('connection', async (socket) => {
|
|||||||
socket.emit("toast", "Nie masz już statków tego typu");
|
socket.emit("toast", "Nie masz już statków tego typu");
|
||||||
} else {
|
} else {
|
||||||
await GInfo.placeShip(socket, { type: type, posX: posX, posY: posY, rot: rot });
|
await GInfo.placeShip(socket, { type: type, posX: posX, posY: posY, rot: rot });
|
||||||
socket.emit("placed ship", { type: type, posX: posY, posY: posX, rot: rot });
|
socket.emit("placed ship", { type: type, posX: posX, posY: posY, rot: rot });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('remove ship', async (posX, posY) => {
|
||||||
|
const playerGame = await GInfo.getPlayerGameData(socket);
|
||||||
|
|
||||||
|
if (playerGame.data.state === 'preparation') {
|
||||||
|
const deletedShip = await GInfo.removeShip(socket, posX, posY);
|
||||||
|
socket.emit("removed ship", { posX: posX, posY: posY, type: deletedShip.type });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
socket.on('shoot', async () => {
|
socket.on('shoot', async () => {
|
||||||
const playerGame = await GInfo.getPlayerGameData(socket);
|
const playerGame = await GInfo.getPlayerGameData(socket);
|
||||||
|
|
||||||
|
184
package-lock.json
generated
184
package-lock.json
generated
@ -9,11 +9,11 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.3",
|
||||||
"express-handlebars": "^7.1.2",
|
"express-handlebars": "^7.1.2",
|
||||||
"express-session": "^1.17.3",
|
"express-session": "^1.18.0",
|
||||||
"redis": "^4.6.12",
|
"redis": "^4.6.13",
|
||||||
"socket.io": "^4.7.2",
|
"socket.io": "^4.7.4",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"uuid4": "^2.0.3"
|
"uuid4": "^2.0.3"
|
||||||
}
|
}
|
||||||
@ -52,9 +52,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@redis/client": {
|
"node_modules/@redis/client": {
|
||||||
"version": "1.5.13",
|
"version": "1.5.14",
|
||||||
"resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.13.tgz",
|
"resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.14.tgz",
|
||||||
"integrity": "sha512-epkUM9D0Sdmt93/8Ozk43PNjLi36RZzG+d/T1Gdu5AI8jvghonTeLYV69WVWdilvFo+PYxbP0TZ0saMvr6nscQ==",
|
"integrity": "sha512-YGn0GqsRBFUQxklhY7v562VMOP0DcmlrHHs3IV1mFE3cbxe31IITUkqhBcIhVSI/2JqtWAJXg5mjV4aU+zD0HA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cluster-key-slot": "1.1.2",
|
"cluster-key-slot": "1.1.2",
|
||||||
"generic-pool": "3.9.0",
|
"generic-pool": "3.9.0",
|
||||||
@ -175,12 +175,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/body-parser": {
|
"node_modules/body-parser": {
|
||||||
"version": "1.20.1",
|
"version": "1.20.2",
|
||||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
|
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
|
||||||
"integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
|
"integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bytes": "3.1.2",
|
"bytes": "3.1.2",
|
||||||
"content-type": "~1.0.4",
|
"content-type": "~1.0.5",
|
||||||
"debug": "2.6.9",
|
"debug": "2.6.9",
|
||||||
"depd": "2.0.0",
|
"depd": "2.0.0",
|
||||||
"destroy": "1.2.0",
|
"destroy": "1.2.0",
|
||||||
@ -188,7 +188,7 @@
|
|||||||
"iconv-lite": "0.4.24",
|
"iconv-lite": "0.4.24",
|
||||||
"on-finished": "2.4.1",
|
"on-finished": "2.4.1",
|
||||||
"qs": "6.11.0",
|
"qs": "6.11.0",
|
||||||
"raw-body": "2.5.1",
|
"raw-body": "2.5.2",
|
||||||
"type-is": "~1.6.18",
|
"type-is": "~1.6.18",
|
||||||
"unpipe": "1.0.0"
|
"unpipe": "1.0.0"
|
||||||
},
|
},
|
||||||
@ -227,13 +227,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/call-bind": {
|
"node_modules/call-bind": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.7",
|
||||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz",
|
||||||
"integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==",
|
"integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"es-define-property": "^1.0.0",
|
||||||
|
"es-errors": "^1.3.0",
|
||||||
"function-bind": "^1.1.2",
|
"function-bind": "^1.1.2",
|
||||||
"get-intrinsic": "^1.2.1",
|
"get-intrinsic": "^1.2.4",
|
||||||
"set-function-length": "^1.1.1"
|
"set-function-length": "^1.2.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
@ -337,16 +342,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/define-data-property": {
|
"node_modules/define-data-property": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz",
|
||||||
"integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==",
|
"integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"get-intrinsic": "^1.2.1",
|
"es-define-property": "^1.0.0",
|
||||||
"gopd": "^1.0.1",
|
"es-errors": "^1.3.0",
|
||||||
"has-property-descriptors": "^1.0.0"
|
"gopd": "^1.0.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/depd": {
|
"node_modules/depd": {
|
||||||
@ -417,6 +425,25 @@
|
|||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/es-define-property": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"get-intrinsic": "^1.2.4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/es-errors": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
||||||
|
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/escape-html": {
|
"node_modules/escape-html": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
||||||
@ -431,13 +458,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/express": {
|
"node_modules/express": {
|
||||||
"version": "4.18.2",
|
"version": "4.18.3",
|
||||||
"resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz",
|
"resolved": "https://registry.npmjs.org/express/-/express-4.18.3.tgz",
|
||||||
"integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==",
|
"integrity": "sha512-6VyCijWQ+9O7WuVMTRBTl+cjNNIzD5cY5mQ1WM8r/LEkI2u8EYpOotESNwzNlyCn3g+dmjKYI6BmNneSr/FSRw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"accepts": "~1.3.8",
|
"accepts": "~1.3.8",
|
||||||
"array-flatten": "1.1.1",
|
"array-flatten": "1.1.1",
|
||||||
"body-parser": "1.20.1",
|
"body-parser": "1.20.2",
|
||||||
"content-disposition": "0.5.4",
|
"content-disposition": "0.5.4",
|
||||||
"content-type": "~1.0.4",
|
"content-type": "~1.0.4",
|
||||||
"cookie": "0.5.0",
|
"cookie": "0.5.0",
|
||||||
@ -485,12 +512,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/express-session": {
|
"node_modules/express-session": {
|
||||||
"version": "1.17.3",
|
"version": "1.18.0",
|
||||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.18.0.tgz",
|
||||||
"integrity": "sha512-4+otWXlShYlG1Ma+2Jnn+xgKUZTMJ5QD3YvfilX3AcocOAbIkVylSWEklzALe/+Pu4qV6TYBj5GwOBFfdKqLBw==",
|
"integrity": "sha512-m93QLWr0ju+rOwApSsyso838LQwgfs44QtOP/WBiwtAgPIo/SAh1a5c6nn2BR6mFNZehTpqKDESzP+fRHVbxwQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cookie": "0.4.2",
|
"cookie": "0.6.0",
|
||||||
"cookie-signature": "1.0.6",
|
"cookie-signature": "1.0.7",
|
||||||
"debug": "2.6.9",
|
"debug": "2.6.9",
|
||||||
"depd": "~2.0.0",
|
"depd": "~2.0.0",
|
||||||
"on-headers": "~1.0.2",
|
"on-headers": "~1.0.2",
|
||||||
@ -502,6 +529,19 @@
|
|||||||
"node": ">= 0.8.0"
|
"node": ">= 0.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/express-session/node_modules/cookie": {
|
||||||
|
"version": "0.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz",
|
||||||
|
"integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/express-session/node_modules/cookie-signature": {
|
||||||
|
"version": "1.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz",
|
||||||
|
"integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA=="
|
||||||
|
},
|
||||||
"node_modules/express-session/node_modules/debug": {
|
"node_modules/express-session/node_modules/debug": {
|
||||||
"version": "2.6.9",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
@ -614,15 +654,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/get-intrinsic": {
|
"node_modules/get-intrinsic": {
|
||||||
"version": "1.2.2",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz",
|
||||||
"integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==",
|
"integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"es-errors": "^1.3.0",
|
||||||
"function-bind": "^1.1.2",
|
"function-bind": "^1.1.2",
|
||||||
"has-proto": "^1.0.1",
|
"has-proto": "^1.0.1",
|
||||||
"has-symbols": "^1.0.3",
|
"has-symbols": "^1.0.3",
|
||||||
"hasown": "^2.0.0"
|
"hasown": "^2.0.0"
|
||||||
},
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
@ -685,20 +729,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/has-property-descriptors": {
|
"node_modules/has-property-descriptors": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz",
|
||||||
"integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==",
|
"integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"get-intrinsic": "^1.2.2"
|
"es-define-property": "^1.0.0"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/has-proto": {
|
"node_modules/has-proto": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz",
|
||||||
"integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==",
|
"integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
},
|
},
|
||||||
@ -718,9 +762,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/hasown": {
|
"node_modules/hasown": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.1.tgz",
|
||||||
"integrity": "sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==",
|
"integrity": "sha512-1/th4MHjnwncwXsIW6QMzlvYL9kG5e/CpVvLRZe4XPa8TOUNbCELqmvhDmnkNsAjwaG4+I8gJJL0JBvTTLO9qA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"function-bind": "^1.1.2"
|
"function-bind": "^1.1.2"
|
||||||
},
|
},
|
||||||
@ -1018,9 +1062,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/raw-body": {
|
"node_modules/raw-body": {
|
||||||
"version": "2.5.1",
|
"version": "2.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
|
||||||
"integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
|
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bytes": "3.1.2",
|
"bytes": "3.1.2",
|
||||||
"http-errors": "2.0.0",
|
"http-errors": "2.0.0",
|
||||||
@ -1032,12 +1076,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/redis": {
|
"node_modules/redis": {
|
||||||
"version": "4.6.12",
|
"version": "4.6.13",
|
||||||
"resolved": "https://registry.npmjs.org/redis/-/redis-4.6.12.tgz",
|
"resolved": "https://registry.npmjs.org/redis/-/redis-4.6.13.tgz",
|
||||||
"integrity": "sha512-41Xuuko6P4uH4VPe5nE3BqXHB7a9lkFL0J29AlxKaIfD6eWO8VO/5PDF9ad2oS+mswMsfFxaM5DlE3tnXT+P8Q==",
|
"integrity": "sha512-MHgkS4B+sPjCXpf+HfdetBwbRz6vCtsceTmw1pHNYJAsYxrfpOP6dz+piJWGos8wqG7qb3vj/Rrc5qOlmInUuA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@redis/bloom": "1.2.0",
|
"@redis/bloom": "1.2.0",
|
||||||
"@redis/client": "1.5.13",
|
"@redis/client": "1.5.14",
|
||||||
"@redis/graph": "1.1.1",
|
"@redis/graph": "1.1.1",
|
||||||
"@redis/json": "1.0.6",
|
"@redis/json": "1.0.6",
|
||||||
"@redis/search": "1.1.6",
|
"@redis/search": "1.1.6",
|
||||||
@ -1124,14 +1168,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/set-function-length": {
|
"node_modules/set-function-length": {
|
||||||
"version": "1.1.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.1.tgz",
|
||||||
"integrity": "sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==",
|
"integrity": "sha512-j4t6ccc+VsKwYHso+kElc5neZpjtq9EnRICFZtWyBsLojhmeF/ZBd/elqm22WJh/BziDe/SBiOeAt0m2mfLD0g==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"define-data-property": "^1.1.1",
|
"define-data-property": "^1.1.2",
|
||||||
"get-intrinsic": "^1.2.1",
|
"es-errors": "^1.3.0",
|
||||||
|
"function-bind": "^1.1.2",
|
||||||
|
"get-intrinsic": "^1.2.3",
|
||||||
"gopd": "^1.0.1",
|
"gopd": "^1.0.1",
|
||||||
"has-property-descriptors": "^1.0.0"
|
"has-property-descriptors": "^1.0.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
@ -1162,13 +1208,17 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/side-channel": {
|
"node_modules/side-channel": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz",
|
||||||
"integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
|
"integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"call-bind": "^1.0.0",
|
"call-bind": "^1.0.7",
|
||||||
"get-intrinsic": "^1.0.2",
|
"es-errors": "^1.3.0",
|
||||||
"object-inspect": "^1.9.0"
|
"get-intrinsic": "^1.2.4",
|
||||||
|
"object-inspect": "^1.13.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
@ -1186,9 +1236,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/socket.io": {
|
"node_modules/socket.io": {
|
||||||
"version": "4.7.2",
|
"version": "4.7.4",
|
||||||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.4.tgz",
|
||||||
"integrity": "sha512-bvKVS29/I5fl2FGLNHuXlQaUH/BlzX1IN6S+NKLNZpBsPZIDH+90eQmCs2Railn4YUiww4SzUedJ6+uzwFnKLw==",
|
"integrity": "sha512-DcotgfP1Zg9iP/dH9zvAQcWrE0TtbMVwXmlV4T4mqsvY+gw+LqUGPfx2AoVyRk0FLME+GQhufDMyacFmw7ksqw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"accepts": "~1.3.4",
|
"accepts": "~1.3.4",
|
||||||
"base64id": "~2.0.0",
|
"base64id": "~2.0.0",
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/MaciejkaG/statki-backend#readme",
|
"homepage": "https://github.com/MaciejkaG/statki-backend#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.3",
|
||||||
"express-handlebars": "^7.1.2",
|
"express-handlebars": "^7.1.2",
|
||||||
"express-session": "^1.17.3",
|
"express-session": "^1.18.0",
|
||||||
"redis": "^4.6.12",
|
"redis": "^4.6.13",
|
||||||
"socket.io": "^4.7.2",
|
"socket.io": "^4.7.4",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"uuid4": "^2.0.3"
|
"uuid4": "^2.0.3"
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class Battleships {
|
|||||||
for (var i = 0; i < size; i++) {
|
for (var i = 0; i < size; i++) {
|
||||||
let row = "<div class=\"row\">";
|
let row = "<div class=\"row\">";
|
||||||
for (var n = 0; n < size; n++) {
|
for (var n = 0; n < size; n++) {
|
||||||
row += `<div class="field" data-pos-x="${i}" data-pos-y="${n}"><div class="shipField"><svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 100 100'><path d='M100 0 L0 100 ' stroke='black' stroke-width='3'/><path d='M0 0 L100 100 ' stroke='black' stroke-width='3'/></svg></div></div>`;
|
row += `<div class="field" data-pos-x="${n}" data-pos-y="${i}"><div class="shipField"><svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 100 100'><path d='M100 0 L0 100 ' stroke='black' stroke-width='3'/><path d='M0 0 L100 100 ' stroke='black' stroke-width='3'/></svg></div></div>`;
|
||||||
}
|
}
|
||||||
row += "</div>";
|
row += "</div>";
|
||||||
board += row;
|
board += row;
|
||||||
@ -77,5 +77,7 @@ class Battleships {
|
|||||||
fields.forEach(field => {
|
fields.forEach(field => {
|
||||||
this.getField(field[0], field[1]).children(".shipField").addClass("active");
|
this.getField(field[0], field[1]).children(".shipField").addClass("active");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return fields;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,8 +20,8 @@ refreshBoardView();
|
|||||||
$("#board .field").hover(function () {
|
$("#board .field").hover(function () {
|
||||||
hoveredField = this;
|
hoveredField = this;
|
||||||
// Pokaż "miarki"
|
// Pokaż "miarki"
|
||||||
let posY = parseInt($(this).data("pos-x"));
|
let posX = parseInt($(this).data("pos-x"));
|
||||||
let posX = parseInt($(this).data("pos-y"));
|
let posY = parseInt($(this).data("pos-y"));
|
||||||
let row = bsc.getRow(posY);
|
let row = bsc.getRow(posY);
|
||||||
let column = bsc.getColumn(posX);
|
let column = bsc.getColumn(posX);
|
||||||
|
|
||||||
@ -168,8 +168,8 @@ function refreshBoardView() {
|
|||||||
});
|
});
|
||||||
changedFields.length = 0;
|
changedFields.length = 0;
|
||||||
|
|
||||||
let posY = parseInt($(hoveredField).data("pos-x"));
|
let posX = parseInt($(hoveredField).data("pos-x"));
|
||||||
let posX = parseInt($(hoveredField).data("pos-y"));
|
let posY = parseInt($(hoveredField).data("pos-y"));
|
||||||
let row = bsc.getRow(posY);
|
let row = bsc.getRow(posY);
|
||||||
let column = bsc.getColumn(posX);
|
let column = bsc.getColumn(posX);
|
||||||
|
|
||||||
|
@ -3,11 +3,20 @@ const socket = io();
|
|||||||
var playerIdx;
|
var playerIdx;
|
||||||
var timerDestination = null;
|
var timerDestination = null;
|
||||||
var gamePhase = 'pregame';
|
var gamePhase = 'pregame';
|
||||||
|
var occupiedFields = [];
|
||||||
|
|
||||||
$('.field').on('click', function () {
|
$('.field').on('click', function () {
|
||||||
socket.emit("place ship", selectedShip, $(this).data('pos-x'), $(this).data('pos-y'), shipRotation);
|
socket.emit("place ship", selectedShip, $(this).data('pos-x'), $(this).data('pos-y'), shipRotation);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.field').on('contextmenu', function () {
|
||||||
|
if ($(this).children('.shipField').hasClass('active')) {
|
||||||
|
let originPos = occupiedFields.find((elem) => elem.pos[0] == $(this).data('pos-x') && elem.pos[1] == $(this).data('pos-y')).origin;
|
||||||
|
|
||||||
|
socket.emit("remove ship", originPos[0], originPos[1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
socket.on('toast', (msg) => {
|
socket.on('toast', (msg) => {
|
||||||
Toastify({
|
Toastify({
|
||||||
text: msg,
|
text: msg,
|
||||||
@ -21,11 +30,29 @@ socket.on('toast', (msg) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("placed ship", (data) => {
|
socket.on("placed ship", (data) => {
|
||||||
bsc.placeShip(data);
|
let shipFields = bsc.placeShip(data);
|
||||||
|
shipFields.forEach(field => {
|
||||||
|
occupiedFields.push({pos: field, origin: [data.posX, data.posY]});
|
||||||
|
});
|
||||||
shipsLeft[data.type]--;
|
shipsLeft[data.type]--;
|
||||||
refreshBoardView();
|
refreshBoardView();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("removed ship", (data) => {
|
||||||
|
const shipFields = occupiedFields.filter(elem => {
|
||||||
|
return elem.origin[0] == data.posX && elem.origin[1] == data.posY;
|
||||||
|
});
|
||||||
|
|
||||||
|
shipFields.forEach(field => {
|
||||||
|
bsc.getField(field.pos[0], field.pos[1]).children('.shipField').removeClass("active");
|
||||||
|
});
|
||||||
|
|
||||||
|
occupiedFields = shipFields.filter(n => !occupiedFields.includes(n));
|
||||||
|
|
||||||
|
shipsLeft[data.type]++;
|
||||||
|
refreshBoardView();
|
||||||
|
});
|
||||||
|
|
||||||
socket.on('connect', () => {
|
socket.on('connect', () => {
|
||||||
$(".cover h1").html("Oczekiwanie na serwer...");
|
$(".cover h1").html("Oczekiwanie na serwer...");
|
||||||
});
|
});
|
||||||
|
@ -47,10 +47,31 @@ export class GameInfo {
|
|||||||
async placeShip(socket, shipData) {
|
async placeShip(socket, shipData) {
|
||||||
const gameId = socket.session.activeGame;
|
const gameId = socket.session.activeGame;
|
||||||
const key = `game:${gameId}`;
|
const key = `game:${gameId}`;
|
||||||
const hostId = (await this.redis.json.get(key, {path: '$.hostId'}))[0];
|
const hostId = (await this.redis.json.get(key, {path: '.hostId'}))[0];
|
||||||
|
|
||||||
const playerIdx = socket.request.session.id === hostId ? 0 : 1;
|
const playerIdx = socket.request.session.id === hostId ? 0 : 1;
|
||||||
let res = await this.redis.json.arrAppend(key, `.boards[${playerIdx}].ships`, shipData);
|
await this.redis.json.arrAppend(key, `.boards[${playerIdx}].ships`, shipData);
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeShip(socket, posX, posY) {
|
||||||
|
const gameId = socket.session.activeGame;
|
||||||
|
const key = `game:${gameId}`;
|
||||||
|
const hostId = (await this.redis.json.get(key, { path: '.hostId' }))[0];
|
||||||
|
|
||||||
|
const playerIdx = socket.request.session.id === hostId ? 0 : 1;
|
||||||
|
let playerShips = await this.redis.json.get(key, {path: `.boards[${playerIdx}].ships`});
|
||||||
|
|
||||||
|
var deletedShip;
|
||||||
|
playerShips = playerShips.filter(function (ship) {
|
||||||
|
if (!ship.posX != posX || ship.posY != posY) {
|
||||||
|
deletedShip = ship;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ship.posX != posX || ship.posY != posY
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.redis.json.set(key, `.boards[${playerIdx}].ships`, playerShips);
|
||||||
|
return deletedShip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,11 +172,11 @@ export function checkHit(data, playerIdx, posX, posY) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < ship.type + 2; i++) {
|
for (let i = 0; i < ship.type + 2; i++) {
|
||||||
boardRender[ship.posY + multips[1] * i][ship.posX + multips[0] * i] = true;
|
boardRender[ship.posX + multips[1] * i][ship.posY + multips[0] * i] = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return boardRender[posY][posX];
|
return boardRender[posX][posY];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateShipPosition(ships, type, posX, posY, rot) {
|
export function validateShipPosition(ships, type, posX, posY, rot) {
|
||||||
@ -192,7 +213,7 @@ export function validateShipPosition(ships, type, posX, posY, rot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < ship.type + 1; i++) {
|
for (let i = 0; i < ship.type + 1; i++) {
|
||||||
boardRender[ship.posY + multips[1] * i][ship.posX + multips[0] * i] = true;
|
boardRender[ship.posX + multips[1] * i][ship.posY + multips[0] * i] = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -217,15 +238,15 @@ export function validateShipPosition(ships, type, posX, posY, rot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let x = 0; x <= type; x++) {
|
for (let x = 0; x <= type; x++) {
|
||||||
if (posY + multips[1] * x > 9 || posY + multips[1] * x < 0 || posX + multips[0] * x > 9 || posX + multips[0] * x < 0) {
|
if (posX + multips[1] * x > 9 || posX + multips[1] * x < 0 || posY + multips[0] * x > 9 || posX + multips[0] * x < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let subtrahents = [[0, 0], [0, 1], [1, 0], [0, -1], [-1, 0], [1, 1], [-1, -1], [1, -1], [-1, 1]]; // Usuń cztery ostatnie elementy jeżeli chcesz by statki mogły się stykać rogami
|
let subtrahents = [[0, 0], [0, 1], [1, 0], [0, -1], [-1, 0], [1, 1], [-1, -1], [1, -1], [-1, 1]]; // Usuń cztery ostatnie elementy jeżeli chcesz by statki mogły się stykać rogami
|
||||||
for (let y = 0; y < subtrahents.length; y++) {
|
for (let y = 0; y < subtrahents.length; y++) {
|
||||||
const idxY = posY - subtrahents[y][0] + multips[1] * x;
|
|
||||||
const idxX = posX - subtrahents[y][1] + multips[0] * x;
|
const idxX = posX - subtrahents[y][1] + multips[0] * x;
|
||||||
if (!(idxY < 0 || idxY > 9 || idxX < 0 || idxX > 9) && boardRender[idxY][idxX]) {
|
const idxY = posY - subtrahents[y][0] + multips[1] * x;
|
||||||
|
if (!(idxX < 0 || idxX > 9 || idxY < 0 || idxY > 9) && boardRender[idxX][idxY]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<title>Statki</title>
|
<title>Statki</title>
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400;1,700&family=Poppins:ital,wght@0,600;1,600&family=Roboto+Mono:ital@0;1&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400;1,700&family=Poppins:ital,wght@0,600;1,600&family=Roboto+Mono:ital@0;1&display=swap" rel="stylesheet">
|
||||||
<script src="https://cdn.socket.io/4.7.3/socket.io.min.js"></script>
|
<script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
|
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
|
||||||
<link rel="stylesheet" href="/assets/css/board.css">
|
<link rel="stylesheet" href="/assets/css/board.css">
|
||||||
<link rel="stylesheet" href="/assets/css/main.css">
|
<link rel="stylesheet" href="/assets/css/main.css">
|
||||||
|
Loading…
Reference in New Issue
Block a user