This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sends the updated grid to the actuator | |
actuate() { | |
if (this.storageManager.getBestScore() < this.score) { | |
this.storageManager.setBestScore(this.score); | |
} | |
// Clear the state when the game is over (game over only, not win) | |
if (this.over) { | |
this.storageManager.clearGameState(); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sendRemoteMove(grid, metadata) { | |
if (!this.remotePlayer) { | |
this.socket.emit('actuate', { grid: grid, metadata: metadata }); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor(socket, remotePlayer, size, InputManager, Actuator, StorageManager) { | |
this.size = size; // Size of the grid | |
this.inputManager = new InputManager(); | |
this.storageManager = new StorageManager; | |
// Change Actuator to take in remotePlayer as an argument! | |
this.actuator = new Actuator(remotePlayer); | |
this.startTiles = 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GameManager { | |
constructor(socket, remotePlayer, size, InputManager, Actuator, StorageManager) { | |
this.size = size; // Size of the grid | |
this.inputManager = new InputManager(); | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.requestAnimationFrame(function () { | |
var socket = io.connect(window.location.origin); | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
</div> | |
<!-- Below is the script tag you need to add! --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script> | |
<script src="js/utils/keyboard_input_manager.js"></script> | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket.on('disconnect', function() { | |
console.log(`Player ${playerIndex} Disconnected`); | |
connections[playerIndex] = null; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket.on('actuate', function (data) { | |
const { grid, metadata } = data; // Get grid and metadata properties from client | |
const move = { | |
playerIndex, | |
grid, | |
metadata, | |
}; | |
// Emit the move to all other clients |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket.on('actuate', function (data) { | |
const { grid, metadata } = data; // Get grid and metadata properties from client | |
const move = { | |
playerIndex, | |
grid, | |
metadata, | |
}; | |
// Emit the move to all other clients |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket.on('actuate', function (data) { | |
const { grid, metadata } = data; // Get grid and metadata properties from client | |
const move = { | |
playerIndex, | |
grid, | |
metadata, | |
}; | |
// Emit the move to all other clients |