diff --git a/commands/Games/connect4.js b/commands/Games/connect4.js index b7a4a5aa..3d2f5973 100755 --- a/commands/Games/connect4.js +++ b/commands/Games/connect4.js @@ -203,7 +203,6 @@ class Connect4 extends Command { const playerTwo = opponent.user; const board = generateBoard(); let lastMove = 'None'; - let gameOver = false; let winner = null; // Global var for updating the collected interaction @@ -249,13 +248,11 @@ class Connect4 extends Command { let displayName = opponentUser.displayName; // Replace content and move if the game is over - if (gameOver) { + if (AIEngine.gameStatus().gameOver) { content = winner ? `Congrats, ${winner}!` : "Looks like it's a draw..."; move = `Final Move: **${lastMove}**`; displayName = currentUser.displayName; - } - - if (opponentUser.bot) { + } else if (opponentUser.bot) { content = ''; move = `I placed mine in **${lastMove}**.`; } @@ -271,7 +268,7 @@ class Connect4 extends Command { `, ); - const buttons = await getButtons(gameOver); + const buttons = await getButtons(AIEngine.gameStatus().gameOver); // Return an object without content built in so it doesn't edit a space if (!content) return { embeds: [embed], components: buttons }; @@ -287,7 +284,7 @@ class Connect4 extends Command { let currentEmoji; let opponentEmoji; - while (!gameOver && board.some((row) => row.includes(null))) { + while (!AIEngine.gameStatus().gameOver && board.some((row) => row.includes(null))) { let sign; if (turn === 1) { currentUser = playerOne; @@ -317,9 +314,13 @@ class Connect4 extends Command { const content = await getContent(currentUser, opponentUser, opponentEmoji, currentEmoji); await collected.editReply(content).catch(console.error); + if (AIEngine.winner) console.log(`The winner is ${AIEngine.winner}`); if (verifyWin(board)) { + console.log('verifiyWin'); winner = currentUser; - gameOver = true; + AIEngine.gameOver = true; + // Log this to see what I can use + console.log(AIEngine); break; } turn === 1 ? (turn = 2) : (turn = 1); @@ -337,7 +338,7 @@ class Connect4 extends Command { if (!collected) { // They never pressed the button, end the game due to time and edit the message directly since collected doesn't exist - gameOver = true; + AIEngine.gameOver = true; winner = 'time'; this.client.games.delete(msg.channel.id); @@ -362,7 +363,7 @@ class Connect4 extends Command { } else if (selectedColumn.toLowerCase() === 'stop') { // The player pressed the stop sign, stop the game and let the other person win. winner = opponentUser; - gameOver = true; + AIEngine.gameOver = true; break; } else { i = Number.parseInt(selectedColumn, 10) - 1; @@ -385,7 +386,7 @@ class Connect4 extends Command { // Check if the last move made them a winner, stop the game if (verifyWin(board)) { winner = currentUser; - gameOver = true; + AIEngine.gameOver = true; break; } @@ -396,6 +397,7 @@ class Connect4 extends Command { // Change turn to the opposite of what it is turn === 1 ? (turn = 2) : (turn = 1); } + console.log('game over'); // Delete the game and set content to function rather than pasting it three times this.client.games.delete(msg.channel.id); @@ -410,6 +412,7 @@ class Connect4 extends Command { // Check if the game ever played so we can edit the interaction, or just edit the message if (collected) return collected.editReply(content).catch(console.error); + console.log('finished'); return message.edit(content).catch(console.error); } catch (err) { // An error occurred, delete the game and send the error to chat.