Commit 2dc295c4 authored by Terence Martin's avatar Terence Martin

Include code for tracking and rendering score

This includes the global game state routines and values that will be
used to track the score, alter it, and render it to the screen.
parent 1e2b7768
......@@ -4,6 +4,55 @@ var __extends = (this && this.__extends) || function (d, b) {
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var nurdz;
(function (nurdz) {
var game;
(function (game) {
/**
* The number of points the human player has.
*/
var humanScore = 0;
/**
* The number of poitns the computer player has.
*/
var computerScore = 0;
/**
* Reset the score values for both players.
*/
function resetScores() {
humanScore = 0;
computerScore = 0;
}
game.resetScores = resetScores;
/**
* Update the score for the designated player by adding or subtracting the
* provided point value from the score.
*
* @param {PlayerType} player the player to adjust the score for
* @param {number} value the adjustment value; can be positive or
* negative
*/
function adjustScore(player, value) {
// Update the correct score.
if (player == game.PlayerType.PLAYER_HUMAN)
humanScore += value;
else
computerScore += value;
}
game.adjustScore = adjustScore;
/**
* Render the scores of the two players to the screen. This renders the
* scores to a known position on screen.
*
* @param {Renderer} renderer the renderer to use to blit the text.
*/
function renderScores(renderer) {
renderer.drawTxt(humanScore + "", 16, 32, "white");
renderer.drawTxt(computerScore + "", game.STAGE_WIDTH - (5 * 32), 32, "yellow");
}
game.renderScores = renderScores;
})(game = nurdz.game || (nurdz.game = {}));
})(nurdz || (nurdz = {}));
var nurdz;
(function (nurdz) {
var game;
(function (game) {
......
module nurdz.game
{
/**
* The number of points the human player has.
*/
let humanScore : number = 0;
/**
* The number of poitns the computer player has.
*/
let computerScore : number = 0;
/**
* Reset the score values for both players.
*/
export function resetScores () : void
{
humanScore = 0;
computerScore = 0;
}
/**
* Update the score for the designated player by adding or subtracting the
* provided point value from the score.
*
* @param {PlayerType} player the player to adjust the score for
* @param {number} value the adjustment value; can be positive or
* negative
*/
export function adjustScore (player : PlayerType, value : number) : void
{
// Update the correct score.
if (player == PlayerType.PLAYER_HUMAN)
humanScore += value;
else
computerScore += value;
}
/**
* Render the scores of the two players to the screen. This renders the
* scores to a known position on screen.
*
* @param {Renderer} renderer the renderer to use to blit the text.
*/
export function renderScores (renderer : Renderer) : void
{
renderer.drawTxt (humanScore+"", 16, 32, "white");
renderer.drawTxt (computerScore+"", STAGE_WIDTH - (5 * 32), 32, "yellow");
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment