Skip to content

Instantly share code, notes, and snippets.

@RyotaMitaraiWeb
Created August 28, 2019 16:30
Show Gist options
  • Save RyotaMitaraiWeb/d80f92fa7b15797ff2d19609bb6df603 to your computer and use it in GitHub Desktop.
Save RyotaMitaraiWeb/d80f92fa7b15797ff2d19609bb6df603 to your computer and use it in GitHub Desktop.
'use strict';
let location = {
name: 'Route 10',
grass: {
area: 'grass area',
pokemon: {
herdier: {
name: 'Herdier', // will be used for formatting later
levels: [33, 35, 34],
typeOfEncounter: 'grass',
},
bouffalant: {
name: 'Herdier',
levels: [33, 35, 34],
typeOfEncounter: 'grass',
},
vullaby: {
name: 'Vullaby',
levels: [34, 36, 35],
typeOfEncounter: 'grass',
},
rufflet: {
name: 'Rufflet',
levels: [34, 36, 35],
typeOfEncounter: 'grass',
},
sawk: {
name: 'Sawk',
levels: [35, 37, 36],
typeOfEncounter: 'grass',
},
throh: {
name: 'Throh',
levels: [35, 37, 36],
typeOfEncounter: 'grass',
},
foongus: {
name: 'Foongus',
levels: [32, 34, 33],
typeOfEncounter: 'grass',
},
amoonguss: {
name: 'Amoonguss',
levels: [35, 37, 36],
typeOfEncounter: 'grass',
},
},
},
cave: { // NOTE: The actual Route 10 does not have an actual cave area, I am making it up
area: 'cave area',
pokemon: {
zubat: {
name: 'Zubat',
levels: [20, 22, 21],
typeOfEncounter: 'cave',
},
golbat: {
name: 'Golbat',
levels: [25, 27, 26],
typeOfEncounter: 'cave',
},
boldore: {
name: 'Boldore',
levels: [26, 28, 27],
typeOfEncounter: 'cave',
},
excadrill: {
name: 'Excadrill',
levels: [31, 33, 32],
typeOfEncounter: 'cave',
},
durant: {
name: 'Durant',
levels: [31, 33, 32],
typeOfEncounter: 'cave',
},
heatmor: {
name: 'Heatmor',
levels: [31, 33, 32],
typeOfEncounter: 'cave',
},
deino: {
name: 'Deino',
levels: [25, 27, 26],
typeOfEncounter: 'cave',
},
},
},
catchPokemon: function() { // This method determines if the Pokemon is caught (50%)
let capture = Math.floor(Math.random() * 2);
if (capture) {
return true; // success
} else {
return false; // failure
}
},
shinyPokemon: function() {
let shiny = Math.floor(Math.random() * 4096 + 1); // shiny rate with shiny charm
if (shiny === 1) {
return true; // shiny has appeared
} else {
return false; // shiny has not appeared
}
},
fightPokemon: function(type) {
let encounteredMons = [];
for (let mon in type.pokemon) {
if (type.pokemon[mon]) {
encounteredMons.push(type.pokemon[mon]); // puts all the objects into an array so one can be picked at random later.
}
}
let pokemon = Math.floor(Math.random() * encounteredMons.length); // determines which Pokemon appears
let levelOfMon = Math.floor(Math.random() * 2); // determines the level at which the Pokemon will appear.
console.log(`You encountered a level ${encounteredMons[pokemon].levels[levelOfMon]}${this.shinyPokemon() ? ` shiny` : ``} ${encounteredMons[pokemon].name} in the ${encounteredMons[pokemon].typeOfEncounter}! ${this.catchPokemon() ? `It was caught successfully!` : `It broke out of the Poke Ball and fled!`}`);
},
walk: function(type) {
if (!type) {
return console.log(`You can't go to nowhere!`); // if invalid value is put
}
console.log(`You decided to enter Route 10's ${type.area}!`);
let amountOfEncounters = 0; // will record how many times was a Pokemon encountered
let step = 0; // will be used to run the loop
let captured = 0; // will record how many Pokemon were caught
let shiny = 0;
for (step; step <= 499; step++) {
let encounter = Math.floor(Math.random() * 100); // decides if there's encounter (10% chance)
if (encounter <= 9) { // will run if there's an encounter
amountOfEncounters++;
this.shinyPokemon();
this.catchPokemon(); // this and above are so they can roll different numbers each time.
this.fightPokemon(type); // will trigger the method that deals with determining the Pokemon
if (this.catchPokemon()) { // will increase its value for each Pokemon that is caught
captured++;
}
if (this.shinyPokemon()) { // will increase its value for each shiny Pokemon that was encountered.
shiny++;
}
}
}
return console.log(`You decided to leave ${this.name} to take some rest.\nAmount of encounters: ${amountOfEncounters}.\nAmount of Pokemon caught: ${captured}\nAmount of shiny Pokemon encountered: ${shiny}`);
}
}
location.walk(location.grass);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment