/*
Description: "guessing.js" is a simple guess the number game made to illustrate the basics
of game programming.
Author: David Johnston
Date: 2016
Version: 1
Usage: Invoked via guessing.html
*/
// game constants -------------------------------------------------------------
const TITLE = "Guessing Game";
const MAXNUM = 20;
const CLUELOWER = "It's lower than that.";
const CLUEHIGHER = "It's higher than that.";
const REPSUCCESS = "Yes! You got it!";
const NAIREPLY = "That doesn't appear to be an integer. Try again.";
const R00 = "Ha! Ha! You're wrong!";
const R01 = "Nope! Try again.";
const R02 = "Sigh. You're not very good at this.";
const R03 = "You god-awful shovel-full of fermenting garbage.";
const R04 = "You nauseating bunch of illiterate rat cysts.";
const R05 = "You insolent lump of unimpressive hogwash.";
const ENTERKEY = 13; // the keycode for the enter key
// game variables -------------------------------------------------------------
var theNumber = Math.floor(Math.random() * MAXNUM);
var guess = "0"; // will be a *string* entered by player
var score = MAXNUM; // score counts down from this number
var replies = [R00, R01, R02, R03, R04, R05];
var repliesIndex = 0;
var comment = "This will be changed later in the code.";
var gameIsOver = false;
// get and set up the page title ----------------------------------------------
var pageTitle = document.getElementById("pageTitle");
pageTitle.innerHTML = TITLE;
var headingArea = document.getElementById("headingArea");
headingArea.innerHTML = TITLE;
// get and setup (if needed) the other page elements --------------------------
var scoreArea = document.getElementById("scoreArea");
scoreArea.innerHTML = "Score: " + MAXNUM;
var instructionArea = document.getElementById("instructionArea");
instructionArea.innerHTML = "Guess an integer between 0 and " + MAXNUM + ".";
var playArea = document.getElementById("playArea");
var commentArea = document.getElementById("commentArea");
commentArea.innerHTML = REPINIT;
var guessField = document.getElementById("guessField");
var guessLength = ((MAXNUM.toString()).length).toString();
guessField.setAttribute("maxlength", guessLength);
guessField.setAttribute("size", guessLength);
var guessButton = document.getElementById("guessButton");
guessButton.setAttribute("onclick","checkGuess()");
var resetButton = document.getElementById("resetButton");
resetButton.setAttribute("onclick","location.reload()");