Skip to content

Instantly share code, notes, and snippets.

@MorenoMdz
Created June 28, 2018 22:43
Show Gist options
  • Select an option

  • Save MorenoMdz/701c54fd9bcf0a4b3e2006f7c0fd963a to your computer and use it in GitHub Desktop.

Select an option

Save MorenoMdz/701c54fd9bcf0a4b3e2006f7c0fd963a to your computer and use it in GitHub Desktop.
Quick zombie text adventure js game
/**
* 1. Zombie Game
* -------------
* A. Write Scenarios
* B. Store a list of possible scenarios
* C. Alert a random scenario from the list
*
* A. Create a list of weapons
* B. Save a list of weapons
* C. Alert which weapon the player finds
*
* ---
*
* 2. What syntax or coding pattern might you use
*/
let beginningScenarios = ['Hospital', 'White House Fields', 'Conveniece Store'];
let weaponList = ['Ak', 'Vector', 'Dick'];
function randomNumber(range) {
return Math.round(Math.random() * range);
}
let scenario = randomNumber(beginningScenarios.length - 1);
let weapon = randomNumber(weaponList.length - 1);
console.log(
`You wake up at the ${
beginningScenarios[scenario]
} and you go search for a weapon...`
);
let weaponFound = weaponList[weapon];
console.log(
`Then, you find a ${weaponFound}, but a zombie jumps in front of you, so you prepare your attack and...`
);
let survival = randomNumber(2);
if (survival === 0) {
console.log(`You attack but your ${weaponFound} Zombie wins`);
} else if (survival > 0) {
console.log(`You win, you have killed the zombie with your ${weaponFound}!`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment