Snake Movement Handler Setup
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class Playground {
|
||||
constructor() {
|
||||
constructor(){
|
||||
// Spielgröße (width * height) Felder
|
||||
this.width = 20;
|
||||
this.height = 20;
|
||||
@@ -8,7 +8,7 @@ class Playground {
|
||||
this.tiles = this.createPlayground();
|
||||
}
|
||||
|
||||
createPlayground() {
|
||||
createPlayground(){
|
||||
const tilesArray = [];
|
||||
|
||||
for (let i = 0; i < this.width; i++) {
|
||||
@@ -22,14 +22,14 @@ class Playground {
|
||||
return tilesArray;
|
||||
}
|
||||
|
||||
getTile(x, y) {
|
||||
getTile(x, y){
|
||||
if (x < 0 || x >= this.width || y < 0 || y >= this.height) {
|
||||
return null; // Ungültiges feld
|
||||
}
|
||||
return this.tiles[x][y];
|
||||
}
|
||||
|
||||
setTile(x, y, object) {
|
||||
setTile(x, y, object){
|
||||
if (x < 0 || x >= this.width || y < 0 || y >= this.height) {
|
||||
return false; // Ungültiges feld
|
||||
}
|
||||
|
||||
22
backend/src/SocketIO/GameManager/Game/Classes/Snake/Snake.js
Normal file
22
backend/src/SocketIO/GameManager/Game/Classes/Snake/Snake.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const SocketUser = require("../../../../Classes/SocketUser");
|
||||
const Playground = require("../Playground/Playground");
|
||||
|
||||
class Snake{
|
||||
/** @param {SocketUser} player @param {Playground} playground */
|
||||
constructor(player, playground, color, startTiles) {
|
||||
this.player = player;
|
||||
this.playground = playground;
|
||||
this.color = color;
|
||||
|
||||
this.tiles = [];
|
||||
this.nextMovement = null;
|
||||
|
||||
this.player.socket.on("movement", (data) => { this.updateNextMovement(data) })
|
||||
}
|
||||
|
||||
updateNextMovement(data){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Snake;
|
||||
@@ -15,8 +15,8 @@ class GameLoop{
|
||||
this.io.to(`game-${this.game.code}`).emit("loop", {
|
||||
code: this.game.code,
|
||||
playground: {
|
||||
height: this.playground.height,
|
||||
width: this.playground.width,
|
||||
// height: this.playground.height,
|
||||
// width: this.playground.width,
|
||||
tiles: this.playground.tiles,
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user