From 1cac60f7e6d1cec7cf45d14956b58f6636b97479 Mon Sep 17 00:00:00 2001 From: Jake Dreher <jdreherschool@gmail.com> Date: Wed, 4 Sep 2024 17:29:28 -0400 Subject: [PATCH] Run prettier --- src/game/game.js | 77 +++++++++++++++++++----------------- src/models/WebSocketModel.js | 17 ++++++-- 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/src/game/game.js b/src/game/game.js index e86bf21..b06b15a 100644 --- a/src/game/game.js +++ b/src/game/game.js @@ -303,41 +303,46 @@ module.exports = { getPlayerView: (gameBoard, pid) => { let updatedBoard = gameBoard.map((row) => row.map((cell) => ({ ...cell }))); - let width = 11; - let height = 11; - - let head = null; - for (var i = 0; i < updatedBoard.length; i++) { - for (var j = 0; j < updatedBoard[i].length; j++) { - let cell = updatedBoard[i][j]; - if (cell.type === cellTypes.PLAYERHEAD && cell.pid === pid) { - console.log("MY Player head found at: ", cell.x, cell.y); - head = cell; - } - } - } - - if (head === null) { - return []; - } - - let playerView = []; - - for (var i = 0; i <= height; i ++) { - let row = []; - for (var j = 0; j <= width; j ++) { - let x = head.x + j - Math.floor(width/2); - let y = head.y + i - Math.floor(height/2); - - if (x < 0 || x >= updatedBoard[0].length || y < 0 || y >= updatedBoard.length) { - row.push(cellTypes.BORDER); - } else { - row.push(updatedBoard[y][x]); - } - } - playerView.push(row); - } - - return playerView; + let width = 11; + let height = 11; + + let head = null; + for (var i = 0; i < updatedBoard.length; i++) { + for (var j = 0; j < updatedBoard[i].length; j++) { + let cell = updatedBoard[i][j]; + if (cell.type === cellTypes.PLAYERHEAD && cell.pid === pid) { + console.log("MY Player head found at: ", cell.x, cell.y); + head = cell; + } + } + } + + if (head === null) { + return []; + } + + let playerView = []; + + for (var i = 0; i <= height; i++) { + let row = []; + for (var j = 0; j <= width; j++) { + let x = head.x + j - Math.floor(width / 2); + let y = head.y + i - Math.floor(height / 2); + + if ( + x < 0 || + x >= updatedBoard[0].length || + y < 0 || + y >= updatedBoard.length + ) { + row.push(cellTypes.BORDER); + } else { + row.push(updatedBoard[y][x]); + } + } + playerView.push(row); + } + + return playerView; }, }; diff --git a/src/models/WebSocketModel.js b/src/models/WebSocketModel.js index 76893fe..d157cc4 100644 --- a/src/models/WebSocketModel.js +++ b/src/models/WebSocketModel.js @@ -37,7 +37,10 @@ class WebSocketModel { } for (let conn of this.games[game].players) { - let playerView = gameModule.getPlayerView(this.games[game].gameBoard, conn.pid); + let playerView = gameModule.getPlayerView( + this.games[game].gameBoard, + conn.pid, + ); conn.connection.send( JSON.stringify({ type: "gameBoard", @@ -149,13 +152,19 @@ class WebSocketModel { let roomId = connection.protocol; if (!this.games[roomId].started) { - this.games[roomId].players.push({connection, pid: this.games[roomId].players.length+1}); + this.games[roomId].players.push({ + connection, + pid: this.games[roomId].players.length + 1, + }); this.games[roomId].gameBoard = gameModule.addPlayer( this.games[roomId].gameBoard, this.games[roomId].players.length, ); } else { - this.games[roomId].players.push({connection, pid: this.games[roomId].players.length+1}); + this.games[roomId].players.push({ + connection, + pid: this.games[roomId].players.length + 1, + }); } connection.send( @@ -166,7 +175,7 @@ class WebSocketModel { ); connection.on("close", () => { - // Need to fix this + // Need to fix this this.games[roomId].players = this.games[roomId].players.filter( (curr) => curr !== this.games[roomId].players, ); -- GitLab