include("mouseinput.js"); include("curtain.js"); include("button.js"); function EndGame(game, camera) { this.system = null; this.canvas = null; this.keyboard = null; this.mouse = null; this.curtain = null; this.playButton = null; this.textMetrics = null; this.init = function(systemObject, canvas) { var stage = this; this.system = systemObject; this.canvas = canvas; this.mouse = new MouseInput(); this.mouse.attach(canvas, this); this.curtain = new Curtain(); this.curtain.init(systemObject, canvas); this.curtain.open(700, function() { stage.isStarted = true; }); this.playButton = new Button(canvas); this.playButton.addClickEvent(this.joinGame); this.showError = false; this.handleResize(canvas); }; this.handleResize = function(canvas) { var buttonOptions = {position: {x: this.canvas.width / 2, y: this.canvas.height / 2}, font:{color:"#DDDDDD", stroke: "#333333", size: 72, family: "sans-serif"}}; if(this.canvas.width < 768) { buttonOptions.font.size = 36; } this.playButton.init("Main Menu", buttonOptions); } this.end = function(callback) { this.mouse.detatch(); this.closeCurtain(callback); } this.closeCurtain = function(callback) { system.theater.stage.curtain.close(700, function() { callback(); }); } this.joinGame = function() { system.theater.changeStage("mainmenu"); } this.updateDelta = function(delta, canvas) { if(system.keyboard.isPressed(Keys.Space) || system.keyboard.isPressed(Keys.Enter)) { this.joinGame(); } this.curtain.updateDelta(delta); }; this.draw = function(context) { var title = "You Win!"; context.font = "72px sans-serif"; context.textAlign = "center"; context.textBaseline = "middle"; var textWidth = context.measureText(title).width; context.fillStyle = "#DDDDDD"; context.strokeStyle = "#333333"; context.lineWidth = 2; if(this.canvas.width < 768) { context.font = "36px sans-serif"; } context.fillText(title, this.canvas.width /2 , 100); var prizeAmount = "$" + system.theater.stages["slotmachine"].prize; context.font = "36px sans-serif"; context.textAlign = "center"; context.textBaseline = "middle"; context.fillStyle = "#DDDDDD"; context.strokeStyle = "#333333"; context.lineWidth = 2; if(this.canvas.width < 768) { context.font = "16px sans-serif"; } context.fillText(prizeAmount, this.canvas.width /2, 200); this.playButton.draw(context); this.curtain.draw(context); }; this.mouseMove = function(canvas, x, y) { this.playButton.mouseMove(x, y); } this.touchMove = function(canvas, x, y) { this.playButton.touchMove(x, y); } this.mouseDown = function(canvas, button, x, y) { this.playButton.mouseDown(button, x, y); } this.touchStart = function(canvas, x, y) { this.playButton.touchStart(x, y); }; };