Premium Essay

Nt1420 Unit 4 Assignment

Submitted By
Words 740
Pages 3
// This project is submitted as part of the assessment for Year 9 IST.
// This is all my own work. I have referenced any work used from other
// sources and have not plagiarised the work of others.
// (signed) Maximilian Evans

//Starting Variables

//Game Length Variable var timer = 30;

//Game Running? Variable var gameRunning = false;

//Current Score Variable var currentScore = 0;

//Mole Hit? Variable var moleHit = false;

//Number of Moles Variable var i = 40;

//==========================================================\\
//START GAME FUNCTION \\
//This function runs when either the start button or restart\\
//button is clicked. It resets the variables, iterates the \\
//game timer, as well as …show more content…
clearTimeout(countdown); //Resets the timer timer = 30; //Resets the score currentScore = 0; clearTimeout(currentScore); //Shows reset button document.getElementById("restart-button").style.display = "block"; //Resets number of moles shown clearTimeout(molesDisplayed); //Sets moles to starting image document.getElementById("mole-1").style.backgroundImage = "url(images/mole_1.png)"; document.getElementById("mole-2").style.backgroundImage = "url(images/mole_2.png)"; document.getElementById("mole-3").style.backgroundImage = "url(images/mole_3.png)"; document.getElementById("mole-1").style.display = "block"; document.getElementById("mole-2").style.display = "block"; document.getElementById("mole-3").style.display = "block"; //Stops moles showing clearTimeout(displayMole); //Resets score currentScore = 0; } }, 1000); //Resets displayed moles var displayedMoles = 0;

var molesDisplayed = setInterval(function moles() { //Updates number of moles shown document.getElementById("moles-shown").innerHTML = (displayedMoles); //Iternates number of displayed moles by 1 displayedMoles = displayedMoles + …show more content…
function displayMoles() { //Selects random number to choose a mole var firstMole = Math.floor(Math.random() * 4);

var displayMole = setInterval(function displayMole() { //Hides all moles document.getElementById("mole-1").style.display = "none"; document.getElementById("mole-2").style.display = "none"; document.getElementById("mole-3").style.display = "none"; //If all moles shown, it hides all if (i === 0){ document.getElementById("mole-1").style.display = "none"; document.getElementById("mole-2").style.display = "none"; document.getElementById("mole-3").style.display = "none"; return; } else if (i > 40) { document.getElementById("mole-1").style.display = "block"; document.getElementById("mole-2").style.display = "block"; document.getElementById("mole-3").style.display = "block"; } else { //Shows Mole1 if random number is 1 if (firstMole == 1) { //Iternates i by -1 i = i - 1; //Displays mole document.getElementById("mole-1").style.display =

Similar Documents