Refactored the selection of Pokémon
It was causing issues because there were lots of recursions causing errors for large sets (>950 occurrences)
This commit is contained in:
parent
408d9d442c
commit
0e356f0caf
@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
<h1>Flashdex</h1>
|
<h1>Flashdex</h1>
|
||||||
|
|
||||||
|
<p>✨ <strong>Now including the first monsters from Pokémon Scarlet & Violet!</strong></p>
|
||||||
|
|
||||||
<p>The Flashdex is a very simple Pokédex, useful to see your favorite creatures in good resolution. Perfect for learning new names, and to see the different generations and different Pokémon forms!</p>
|
<p>The Flashdex is a very simple Pokédex, useful to see your favorite creatures in good resolution. Perfect for learning new names, and to see the different generations and different Pokémon forms!</p>
|
||||||
|
|
||||||
<div id="flashdex_config">
|
<div id="flashdex_config">
|
||||||
|
89
poketest.js
89
poketest.js
@ -18,7 +18,8 @@ $(document).ready(function() {
|
|||||||
var image_name; // preload
|
var image_name; // preload
|
||||||
var image_memory; // preload
|
var image_memory; // preload
|
||||||
var gen_list = new Array();
|
var gen_list = new Array();
|
||||||
var previous_pokemon = new Array();
|
var available_pokemon = new Array();
|
||||||
|
var domain = "https://poketest.marchal.dev/index.html";
|
||||||
|
|
||||||
/****** Generations ******/
|
/****** Generations ******/
|
||||||
var G1 = [1, 151];
|
var G1 = [1, 151];
|
||||||
@ -33,6 +34,8 @@ $(document).ready(function() {
|
|||||||
var MEGA = [909, 958];
|
var MEGA = [909, 958];
|
||||||
var GIGA = [959, 990];
|
var GIGA = [959, 990];
|
||||||
var REG = [991, 1043];
|
var REG = [991, 1043];
|
||||||
|
var gen_number = 9;
|
||||||
|
var extra_number = 3; // mega, giga, reg
|
||||||
|
|
||||||
/************ UTIL *************/
|
/************ UTIL *************/
|
||||||
/*******************************/
|
/*******************************/
|
||||||
@ -76,7 +79,6 @@ $(document).ready(function() {
|
|||||||
$('article #container').append('<div id="score"><div id="top_game"><h1 class="whois"></h1><h1 class="chrono"></h1></div></div>');
|
$('article #container').append('<div id="score"><div id="top_game"><h1 class="whois"></h1><h1 class="chrono"></h1></div></div>');
|
||||||
$('article #container #score').append('<p class="pokemon"></p><div id="answers"></div>');
|
$('article #container #score').append('<p class="pokemon"></p><div id="answers"></div>');
|
||||||
generations();
|
generations();
|
||||||
choosePokemon();
|
|
||||||
max_chrono = $('article select.time option:selected').attr('id');
|
max_chrono = $('article select.time option:selected').attr('id');
|
||||||
max_questions = $('article select.questions option:selected').attr('id');
|
max_questions = $('article select.questions option:selected').attr('id');
|
||||||
if (max_questions == "infinite") infinite = true;
|
if (max_questions == "infinite") infinite = true;
|
||||||
@ -88,8 +90,9 @@ $(document).ready(function() {
|
|||||||
if (pokemon_generation_list.length > 0)
|
if (pokemon_generation_list.length > 0)
|
||||||
max_questions = pokemon_generation_list.length;
|
max_questions = pokemon_generation_list.length;
|
||||||
else // else, it's all the generation, from the first one to the regional forms
|
else // else, it's all the generation, from the first one to the regional forms
|
||||||
max_questions = REG[1];
|
max_questions = REG[1] + 1;
|
||||||
}
|
}
|
||||||
|
choosePokemon();
|
||||||
game();
|
game();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -126,22 +129,31 @@ $(document).ready(function() {
|
|||||||
for (i in gen_list) {
|
for (i in gen_list) {
|
||||||
evaluateByGeneration(i, "1g", G1); evaluateByGeneration(i, "2g", G2); evaluateByGeneration(i, "3g", G3);
|
evaluateByGeneration(i, "1g", G1); evaluateByGeneration(i, "2g", G2); evaluateByGeneration(i, "3g", G3);
|
||||||
evaluateByGeneration(i, "4g", G4); evaluateByGeneration(i, "5g", G5); evaluateByGeneration(i, "6g", G6);
|
evaluateByGeneration(i, "4g", G4); evaluateByGeneration(i, "5g", G5); evaluateByGeneration(i, "6g", G6);
|
||||||
evaluateByGeneration(i, "7g", G7); evaluateByGeneration(i, "8g", G8);
|
evaluateByGeneration(i, "7g", G7); evaluateByGeneration(i, "8g", G8); evaluateByGeneration(i, "9g", G9);
|
||||||
evaluateByGeneration(i, "mega", MEGA); evaluateByGeneration(i, "gigantamax", GIGA); evaluateByGeneration(i, "regional", REG);
|
evaluateByGeneration(i, "mega", MEGA); evaluateByGeneration(i, "gigantamax", GIGA); evaluateByGeneration(i, "regional", REG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// we parse the list of generation, then check if there are other forms
|
// we parse the list of generation, then check if there are other forms
|
||||||
if ( $('article input[name="gen"]:checked').attr('id') === "all" )
|
if ( $('article input[name="gen"]:checked').attr('id') === "all" )
|
||||||
return;
|
{
|
||||||
for (i = 0; i < 9; i++)
|
gen_list.push("1g"); gen_list.push("2g"); gen_list.push("3g"); gen_list.push("4g"); gen_list.push("5g");
|
||||||
createGenerationList((i + "g"));
|
gen_list.push("6g"); gen_list.push("7g"); gen_list.push("8g"); gen_list.push("9g");
|
||||||
createGenerationList("mega");
|
gen_list.push("mega"); gen_list.push("gigantamax"); gen_list.push("regional");
|
||||||
createGenerationList("gigantamax");
|
generatePokemonList();
|
||||||
createGenerationList("regional");
|
}
|
||||||
generatePokemonList();
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < gen_number; i++)
|
||||||
|
createGenerationList((i + "g"));
|
||||||
|
createGenerationList("mega");
|
||||||
|
createGenerationList("gigantamax");
|
||||||
|
createGenerationList("regional");
|
||||||
|
generatePokemonList();
|
||||||
|
}
|
||||||
|
available_pokemon = [...pokemon_generation_list];
|
||||||
|
max_questions = pokemon_generation_list.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// multiple artworks
|
// multiple artworks
|
||||||
@ -179,11 +191,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function recursiveOptions(options, lang) {
|
function recursiveOptions(options, lang) {
|
||||||
// if it's not all generation, we check list of available pokemons
|
tmp = pokemon_generation_list[random(0, pokemon_generation_list.length - 1)];
|
||||||
if (pokemon_generation_list.length > 0)
|
|
||||||
tmp = pokemon_generation_list[random(0, pokemon_generation_list.length - 1)];
|
|
||||||
else // else, it's all the generation, from the first one to the regional forms
|
|
||||||
tmp = random(0, REG[1] - 1);
|
|
||||||
|
|
||||||
// checking if it's already there, if it is, recursion
|
// checking if it's already there, if it is, recursion
|
||||||
if (!findInArray(options, pklist.mn[tmp][lang]))
|
if (!findInArray(options, pklist.mn[tmp][lang]))
|
||||||
@ -201,42 +209,16 @@ $(document).ready(function() {
|
|||||||
options = shuffleArray(options);
|
options = shuffleArray(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
// avoid repetition of the same pokemon in a short lapse of time
|
|
||||||
function checkPreviousPokemon(pkmn) {
|
|
||||||
if (!whole_set) { // if it's not the whole set, we have to delete some older occurrences
|
|
||||||
if (pokemon_generation_list.length > 0) {
|
|
||||||
if (previous_pokemon.length + 6 > pokemon_generation_list.length)
|
|
||||||
previous_pokemon.splice(0, 6);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (previous_pokemon.length + 6 > REG[1] - 1)
|
|
||||||
previous_pokemon.splice(0, 6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return findInArray(previous_pokemon, pkmn);
|
|
||||||
}
|
|
||||||
|
|
||||||
function choosePokemon() {
|
function choosePokemon() {
|
||||||
// if it's not all generation, we check list of available pokemons
|
|
||||||
if (pokemon_generation_list.length > 0)
|
|
||||||
result = pokemon_generation_list[random(0, pokemon_generation_list.length - 1)];
|
|
||||||
else // else, it's all the generation, from the first one to the regional forms
|
|
||||||
result = random(0, REG[1] - 1);
|
|
||||||
lang = $('article select.lang option:selected').attr('id');
|
lang = $('article select.lang option:selected').attr('id');
|
||||||
silhouette = $('article input[name="silhouette"]:checked').attr('id');
|
silhouette = $('article input[name="silhouette"]:checked').attr('id');
|
||||||
//console.log("result = 0, " + (REG[1] - 1));
|
|
||||||
//console.log("test = " + pklist.mn[0][lang]);
|
result = random(0, available_pokemon.length - 1);
|
||||||
//console.log("test = " + pklist.mn[REG[1] - 1][lang]);
|
if (!infinite)
|
||||||
console.log("number: " + result);
|
available_pokemon.splice(result, 1);
|
||||||
|
|
||||||
answer = pklist.mn[result][lang];
|
answer = pklist.mn[result][lang];
|
||||||
console.log("pokemon: " + answer);
|
chooseOptions(result, lang);
|
||||||
if (checkPreviousPokemon(answer)) { // if it's already been selected within a short lapse of time
|
|
||||||
if (whole_set && questions == max_questions) { } // makes the last question of whole set work
|
|
||||||
else choosePokemon(); // recursive call
|
|
||||||
} else {
|
|
||||||
previous_pokemon[previous_pokemon.length] = answer;
|
|
||||||
chooseOptions(result, lang);
|
|
||||||
}
|
|
||||||
imageType(result + 1);
|
imageType(result + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +277,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
choosePokemon();
|
choosePokemon();
|
||||||
var wait = max_wait;
|
var wait = max_wait;
|
||||||
var clock = setInterval(function() {
|
clock = setInterval(function() {
|
||||||
wait--;
|
wait--;
|
||||||
if (wait === 0) {
|
if (wait === 0) {
|
||||||
if (!infinite) questions < max_questions ? game() : score();
|
if (!infinite) questions < max_questions ? game() : score();
|
||||||
@ -310,16 +292,14 @@ $(document).ready(function() {
|
|||||||
var start_sentence = 'I got ';
|
var start_sentence = 'I got ';
|
||||||
var end_sentence = 'Can you get a better score than me?';
|
var end_sentence = 'Can you get a better score than me?';
|
||||||
var score_sentence = (Math.floor(good_answers/max_questions*100))+'% Pokémons right!'
|
var score_sentence = (Math.floor(good_answers/max_questions*100))+'% Pokémons right!'
|
||||||
var questions_sentence = max_questions + " questions"
|
|
||||||
|
|
||||||
if (!infinite) return start_sentence+score_sentence+" "+end_sentence;
|
if (!infinite) return start_sentence+score_sentence+" "+end_sentence;
|
||||||
else return start_sentence+good_answers+" good Pokémon answers! "+end_sentence;
|
else return start_sentence+good_answers+" good Pokémon answers! "+end_sentence;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateSeed() {
|
function generateSeed() {
|
||||||
s_domain = "https://poketest.marchal.dev/index.html";
|
|
||||||
gen = '';
|
gen = '';
|
||||||
if (gen_list.length > 0) {
|
if (gen_list.length < (gen_number + extra_number)) {
|
||||||
for (i in gen_list)
|
for (i in gen_list)
|
||||||
gen += gen_list[i].substring(0,1);
|
gen += gen_list[i].substring(0,1);
|
||||||
}
|
}
|
||||||
@ -337,7 +317,7 @@ $(document).ready(function() {
|
|||||||
localStorage.setItem('questions', (!whole_set? max_questions : "set"));
|
localStorage.setItem('questions', (!whole_set? max_questions : "set"));
|
||||||
localStorage.setItem('time', max_chrono);
|
localStorage.setItem('time', max_chrono);
|
||||||
|
|
||||||
return s_domain + s_gen + s_lang + s_silhouette + s_questions + s_time;
|
return domain + s_gen + s_lang + s_silhouette + s_questions + s_time;
|
||||||
}
|
}
|
||||||
$('article #container #score .pokemon').after('<div id="seed"></div><div id="share"></div>');
|
$('article #container #score .pokemon').after('<div id="seed"></div><div id="share"></div>');
|
||||||
$('article #container').addClass('diploma');
|
$('article #container').addClass('diploma');
|
||||||
@ -373,6 +353,5 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -138,8 +138,8 @@ article #container.about ul li a { margin-top: 5px; margin-bottom: 5px; font-wei
|
|||||||
.SM2 { background: #589ac8; color: black; padding: 5px; border-radius: 0px 10px 10px 0px; }
|
.SM2 { background: #589ac8; color: black; padding: 5px; border-radius: 0px 10px 10px 0px; }
|
||||||
.SWSH1 { background: #00A1E9; color: black; padding: 5px; border-radius: 10px 0px 0px 10px; }
|
.SWSH1 { background: #00A1E9; color: black; padding: 5px; border-radius: 10px 0px 0px 10px; }
|
||||||
.SWSH2 { background: #BF004F; color: white; padding: 5px; border-radius: 0px 10px 10px 0px; }
|
.SWSH2 { background: #BF004F; color: white; padding: 5px; border-radius: 0px 10px 10px 0px; }
|
||||||
.SV1 { background: #e01715; color: white; padding: 5px; border-radius: 10px 0px 0px 10px; }
|
.SV1 { background: #F34134; color: black; padding: 5px; border-radius: 10px 0px 0px 10px; }
|
||||||
.SV2 { background: #741e85; color: white; padding: 5px; border-radius: 0px 10px 10px 0px; }
|
.SV2 { background: #8334B7; color: white; padding: 5px; border-radius: 0px 10px 10px 0px; }
|
||||||
|
|
||||||
.RB { border-radius:50%; background: linear-gradient(-45deg, #FF1111 50%, #1111FF 50%); display:block; border: 1px solid white; }
|
.RB { border-radius:50%; background: linear-gradient(-45deg, #FF1111 50%, #1111FF 50%); display:block; border: 1px solid white; }
|
||||||
.GS { border-radius:50%; background: linear-gradient(-45deg, #DAA520 50%, #C0C0C0 50%); display:block; border: 1px solid white; }
|
.GS { border-radius:50%; background: linear-gradient(-45deg, #DAA520 50%, #C0C0C0 50%); display:block; border: 1px solid white; }
|
||||||
@ -150,7 +150,7 @@ article #container.about ul li a { margin-top: 5px; margin-bottom: 5px; font-wei
|
|||||||
.SM { border-radius:50%; background: linear-gradient(-45deg, #ef9039 50%, #589ac8 50%); display:block; border: 1px solid white; }
|
.SM { border-radius:50%; background: linear-gradient(-45deg, #ef9039 50%, #589ac8 50%); display:block; border: 1px solid white; }
|
||||||
.SWSH { border-radius:50%; background: linear-gradient(-45deg, #00A1E9 50%, #BF004F 50%); display:block; border: 1px solid white; }
|
.SWSH { border-radius:50%; background: linear-gradient(-45deg, #00A1E9 50%, #BF004F 50%); display:block; border: 1px solid white; }
|
||||||
.LA { border-radius:50%; background: #36597B; display:block; border: 1px solid white; }
|
.LA { border-radius:50%; background: #36597B; display:block; border: 1px solid white; }
|
||||||
.SV { border-radius:50%; background: linear-gradient(-45deg, #e01715 50%, #741e85 50%); display:block; border: 1px solid white; }
|
.SV { border-radius:50%; background: linear-gradient(-45deg, #F34134 50%, #8334B7 50%); display:block; border: 1px solid white; }
|
||||||
|
|
||||||
/**** FOOTER ****/
|
/**** FOOTER ****/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user