Compare commits

..

No commits in common. "0b19f848147464782222b097836e924ff41de791" and "8eeb0dee35acba42383c951c8b6288a76829dae7" have entirely different histories.

View File

@ -40,13 +40,11 @@ $(document).ready(function() {
/************ UTIL *************/
/*******************************/
function random(min, max)
{
function random(min, max) {
return Math.floor(Math.random()*(max-min+1)+min);
}
function shuffleArray(array)
{
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
@ -56,8 +54,7 @@ $(document).ready(function() {
return array;
}
function findInArray(array, elem)
{
function findInArray(array, elem, size) {
for (var j = 0; j < array.length; j++) {
if (array[j] === elem)
return true;
@ -70,16 +67,14 @@ $(document).ready(function() {
/*******************************/
// loading json file
$.getJSON('pokemon.json', function(pk)
{
var json = $.getJSON('pokemon.json', function(pk) {
var pklist = pk;
var pokemon_generation_list = new Array();
// starting the game for the first time and creating the layout
function firstGame()
{
$('article #game').fadeToggle('quick', function()
{
function firstGame() {
$('article #game').fadeToggle('quick', function() {
document.removeEventListener('keydown', funcListener);
$('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>');
@ -87,57 +82,51 @@ $(document).ready(function() {
max_chrono = $('article select.time option:selected').attr('id');
max_questions = $('article select.questions option:selected').attr('id');
if (max_questions == "infinite") infinite = true;
if (max_questions == "set")
{
if (max_questions == "set") {
whole_set = true;
// set max_questions depending on generation
// if it's not all generation, we check list of available pokemons
if (pokemon_generation_list.length > 0)
max_questions = pokemon_generation_list.length;
else // else, it's all the generation, from the first one to the regional forms
max_questions = REG[1] + 1;
}
choosePokemon();
game();
});
}
// allows to start the game when pressing enter
document.addEventListener('keydown', funcListener = function(event)
{
document.addEventListener('keydown', funcListener = function(event) {
if (event.keyCode == 13) // press enter
firstGame();
});
// start the game when clicking on start game
$('article #container .button input.start').click(function()
{
$('article #container .button input.start').click(function() {
firstGame();
});
function generations()
{
function generations() {
// create the list of the different generations
function createGenerationList(name)
{
function createGenerationList(name) {
if ( $('article input[name="'+name+'"]').is(':checked') )
gen_list[gen_list.length] = name;
}
// create the list of all possible pokemons for selected options
function generatePokemonList()
{
function evaluateByGeneration(index, name, variable)
{
if (gen_list[index] == name)
{
function generatePokemonList() {
function evaluateByGeneration(index, name, variable) {
if (gen_list[index] == name) {
for (j = (variable[0] - 1); j <= (variable[1] - 1); j++)
pokemon_generation_list[pokemon_generation_list.length] = j;
}
}
if (gen_list.length > 0)
{
for (i in gen_list)
{
if (gen_list.length > 0) {
for (i in gen_list) {
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, "7g", G7); evaluateByGeneration(i, "8g", G8); evaluateByGeneration(i, "9g", G9);
@ -168,35 +157,40 @@ $(document).ready(function() {
}
// multiple artworks
function imageType(result)
{
function randomizer(result)
{
if (pk.mn[result]["sprite"])
return pklist.mn[result]["num"] + '-' + random(0, pk.mn[result]["sprite"] - 1);
else
{
if (pk.mn[result]["origin"] == "Kanto")
{
randomValue = random(0, 2);
if (randomValue == 0)
return pklist.mn[result]["num"];
else if (randomValue == 1)
return pklist.mn[result]["num"]+'RB';
else if (randomValue == 2)
return pklist.mn[result]["num"]+'RG';
function imageType(result) {
var four_types = [351, 386, 585, 586, 676, 741, 800];
var three_types = [249, 250, 384, 412, 413, 718, 745, 898];
var two_types = [251, 252, 255, 258, 374, 387, 390, 393, 421, 422, 423, 487, 492, 495, 498, 501, 521, 550, 555,
592, 593, 641, 642, 643, 644, 645, 647, 648, 668, 678, 681, 720, 746, 774, 791, 792, 802, 849,
876, 877, 888, 889, 892, 905, "G892"];
function randomizer() {
if (result >= MEGA[0]) return (pklist.mn[result-1]["num"])
if (result === 25) return (result+'-'+random(0, 16));
if (result === 666) return (result+'-'+random(0, 20));
if (result === 646) return (result+'-'+random(0, 6));
if (result === 479) return (result+'-'+random(0, 5));
for (i in four_types) {
if (four_types[i] == result) return (result+'-'+random(0, 3));
}
return pklist.mn[result]["num"];
for (i in three_types) {
if (three_types[i] == result) return (result+'-'+random(0, 2));
}
for (i in two_types) {
if (two_types[i] == result) return (result+'-'+random(0, 1));
}
image_name = randomizer(result);
if (result > 151) return result;
if ((tmp = random(0, 2)) == 0) return result;
else if (tmp == 1) return (result+'RB');
else return (result+'RG');
}
image_name = randomizer(result+1);
image_memory = new Image();
image_memory.src = 'pokemon/' + image_name + '.png';
return image_name;
}
function recursiveOptions(options, lang)
{
function recursiveOptions(options, lang) {
tmp = pokemon_generation_list[random(0, pokemon_generation_list.length - 1)];
// checking if it's already there, if it is, recursion
@ -207,8 +201,7 @@ $(document).ready(function() {
}
// choosing the four options
function chooseOptions(result, lang)
{
function chooseOptions(result, lang) {
options = new Array();
options[0] = pklist.mn[result][lang];
for (var i = 1; i < 4; i++)
@ -216,25 +209,20 @@ $(document).ready(function() {
options = shuffleArray(options);
}
function choosePokemon()
{
function choosePokemon() {
lang = $('article select.lang option:selected').attr('id');
silhouette = $('article input[name="silhouette"]:checked').attr('id');
resultIndex = Math.floor((available_pokemon.length - 1) * Math.random());
result = available_pokemon[resultIndex];
result = random(0, available_pokemon.length - 1);
if (!infinite)
available_pokemon.splice(resultIndex, 1);
available_pokemon.splice(result, 1);
answer = pklist.mn[result][lang];
chooseOptions(result, lang);
imageType(result);
imageType(result + 1);
}
function game()
{
choosePokemon();
function game() {
questions++;
chrono = max_chrono;
$('article #container').addClass('game_active');
@ -250,11 +238,9 @@ $(document).ready(function() {
$('article #container #answers').append('<span><input type="submit" class="option a4" name="a4" value="'+options[3]+'"></span>')
// timer setting
var clock = setInterval(function()
{
var clock = setInterval(function() {
chrono--;
if (chrono === 0)
{
if (chrono === 0) {
clearInterval(clock);
showAnswer(false); // timer has ended, so it's a bad answer
}
@ -262,16 +248,12 @@ $(document).ready(function() {
}, 1000);
// checking if the answer is good or not
$('article .option').click(function()
{
$('article .option').click(function() {
clearInterval(clock);
($(this).attr('value') == answer) ? showAnswer(true) : showAnswer(false);
});
document.addEventListener('keydown', funcListener = function(event)
{
function checkAnswer(v)
{
document.addEventListener('keydown', funcListener = function(event) {
function checkAnswer(v) {
clearInterval(clock);
($('#answers input.a'+v).attr('value') == answer) ? showAnswer(true) : showAnswer(false);
}
@ -281,25 +263,21 @@ $(document).ready(function() {
else if (event.keyCode == 52 || event.keyCode == 76) checkAnswer(4);
});
function showAnswer(ok)
{
function showAnswer(ok) {
document.removeEventListener('keydown', funcListener);
$('article .pokemon img').removeClass('silhouette');
if (ok)
{
if (ok) {
good_answers++;
$('article #answers').empty().append("<p class=\"final_answer\"><span class=\"good\">That's right!</span> \
The answer is <strong>"+ answer +"</strong>!</p>");
}
else
{
} else {
bad_answers++;
$('article #answers').empty().append("<p class=\"final_answer\"><span class=\"bad\">Too bad...</span> \
The answer was <strong>"+ answer +"</strong>!</p>");
}
choosePokemon();
var wait = max_wait;
clock = setInterval(function()
{
clock = setInterval(function() {
wait--;
if (wait === 0) {
if (!infinite) questions < max_questions ? game() : score();
@ -308,10 +286,9 @@ $(document).ready(function() {
}, 1000);
}
function score()
{
function generateTwitterText()
{
function score() {
function generateTwitterText() {
var start_sentence = 'I got ';
var end_sentence = 'Can you get a better score than me?';
var score_sentence = (Math.floor(good_answers/max_questions*100))+'% Pokémons right!'
@ -320,11 +297,9 @@ $(document).ready(function() {
else return start_sentence+good_answers+" good Pokémon answers! "+end_sentence;
}
function generateSeed()
{
function generateSeed() {
gen = '';
if (gen_list.length < (gen_number + extra_number))
{
if (gen_list.length < (gen_number + extra_number)) {
for (i in gen_list)
gen += gen_list[i].substring(0,1);
}
@ -344,7 +319,6 @@ $(document).ready(function() {
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').addClass('diploma');
$('article #container').removeClass('game_active');
@ -365,14 +339,12 @@ $(document).ready(function() {
// class="start_again" name="start_again" value="Play again!"></p>');
// copy seed in clipboard
$("article #container #copyseed").click(function()
{
$("article #container #copyseed").click(function() {
$('article #container #seed input').select();
document.execCommand("copy");
});
$('article #container .button input.start_again').click(function()
{
$('article #container .button input.start_again').click(function() {
score = questions = good_answers = bad_answers = 0;
chrono = max_chrono;
$('article #container .chrono').show();