At the end of the day, all of these code examples only define each of the individual pieces of JavaScript's functionality. Continuing with our Player
class concept that we have been using throughout this chapter, we then put some finishing touches to our example "Player in a game" class structure.
function Game() { // An array to hold all our player objects var players = new Array(); // Game Constructor // Reference to the game element in the document. var gameElement = document.getElementById('game'); // Get the game element size. var gameElementWidth = gameElement.offsetWidth; var gameElementHeight = gameElement.offsetHeight; // Be sure to update these values if the window is // to ever be resized. window.onresize = function() { console.log("NOTICE: Browser Resize: " + gameElementWidth + " x " + gameElementHeight); gameElementWidth = gameElement.offsetWidth; gameElementHeight = gameElement.offsetHeight; }; // Player Class...