diff --git a/src/favicon.ico b/src/favicon.ico new file mode 100644 index 0000000..547f297 Binary files /dev/null and b/src/favicon.ico differ diff --git a/src/game.js b/src/game.js new file mode 100644 index 0000000..d0464ad --- /dev/null +++ b/src/game.js @@ -0,0 +1,202 @@ +'use strict'; +//General +var MOBILE_WIDH = 930; +var WINDOW_W = $(window).width(); +// Sound initialization +ion.sound({ + sounds: [{ + name: "button_tiny", + volume: 0.8, + preload: true + }, { + name: "ta_da", + volume: 0.8, + preload: true + }, { + name: "sad_trombone", + volume: 0.8, + preload: true + } + + ], + volume: 0.5, + path: "./sound/sounds/", + preload: true +}); + +// Get word +// words array located in words.js +var word; +var incercari; +var missArray; +var charArray1; +var charArray2; +var missArray; + +function newGame(wordList) { + + word = wordList[Math.floor(Math.random() * wordList.length)]; + incercari = 6; + charArray1 = []; + charArray2 = []; + missArray = []; + + // Create the arrays + for (var i = 0; i < word.length; i++) { + charArray1[i] = '*'; + } + + for (var i = 0; i < word.length; i++) { + charArray2[i] = word.charAt(i); + } + + // Update page info + $('.word').html(charArray1); + $("#human").attr('src', "./img/" + incercari + ".png"); + $('#incercari').html(incercari); + $('.litera_msg2').html(); +} + +// DOM Elements & Events +$(document).ready(function() { + $('.footer-content').append("

Spanzuratoarea created by" + "@Niutenisu

"); + + var listaCuvinte = localStorage.getItem("listaCuvinte"); + if (listaCuvinte != null) { + $("select[name=lista_cuvinte]").val(listaCuvinte); + newGame(eval(listaCuvinte)); + } else { + newGame(animale_eu); + } + + $("select[name=lista_cuvinte]").on("change", function() { + localStorage.setItem("listaCuvinte", $(this).val()); + }).next().click(function() { + // eval for transforming string into object ref!!! + newGame(eval($(this).prev().val())); // POSSIBLE EXPLOIT!! + // prev for mobile <3 + }); + + $('#game').fadeIn("slow"); + +}); + +$(document).on("keypress", function(e) { + var key = e.keyCode || e.which; + var key2 = String.fromCharCode(key).toLowerCase(); + + ion.sound.play("button_tiny"); + + $('.litera_msg').fadeIn('slow'); + $('.litera').html(key2); + + //already guessed, check, + if (check(key2)) { + $('.litera_msg2').html("aceasta litera se afla in cuvant."); + updateArray(key2); + $('.word').html(charArray1); + } else { + $('.litera_msg2').html("aceasta litera nu se afla in cuvant."); + + incercari--; + + if (incercari > -1) { + $("#human").attr('src', "./img/" + incercari + ".png"); + $('#incercari').html(incercari); + updateLetters(key2); + if (incercari == 0) + gameOver(); + } + } + + // check if arrays are equal + if (arraysEqual(charArray1, charArray2)) { + gameWon(); + } +}) + +function gameWon() { + if (WINDOW_W <= MOBILE_WIDH) { + ion.sound.play("ta_da"); + alert("Felicita e tenersi per mano") + window.location.reload(); // mobile + return; + } + //alert("You're winner!"); + + if (WINDOW_W > MOBILE_WIDH) + $('#gamewon').fadeIn('slow'); + $(document).off(); // Detach keypress handler + ion.sound.play("ta_da"); // Play victory sound + + $('#gamewon img').click(function() { + window.location.reload(); + }); + + $(document).on("keypress", function(e) { + var key = e.keyCode || e.which; + if (key == 13) + window.location.reload(); // Da reset la handlere :-) + }); +} + +function gameOver() { + if (WINDOW_W <= MOBILE_WIDH) { + ion.sound.play("sad_trombone"); + alert("Ai pierdut! CUVANT: " + word); + window.location.reload(); // for mobile phones + return; // for slower mobile phones + } + + $('#incercari_msg').html("Game Over!"); + $('#lose_word').html(word); + + if (WINDOW_W > MOBILE_WIDH) + $('#gameover').fadeIn('slow'); + $(document).off(); // Detach keypress handler + ion.sound.play("sad_trombone"); + + $('#gameover img').click(function() { + window.location.reload(); + }); + $(document).on("keypress", function(e) { + var key = e.keyCode || e.which; + if (key == 13) + window.location.reload(); + }); +} + +function check(guess) { + return word.indexOf(guess) > -1; +} + +function updateLetters(guess) { + + var len = missArray.length; + if (!($.inArray(guess, missArray) > -1)) { + missArray[len] = guess; + } + $('.litere').html(missArray + " "); + +} + +function updateArray(guess) { + guess = guess.toLowerCase(); + + for (i = 0; i < charArray1.length; i++) { + if (charArray2[i] == guess) { + charArray1[i] = guess; + } + } +} + +function arraysEqual(a, b) { + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; + + for (var i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + return true; +} diff --git a/src/game.min.js b/src/game.min.js new file mode 100644 index 0000000..658b57f --- /dev/null +++ b/src/game.min.js @@ -0,0 +1 @@ +function newGame(a){for(word=a[Math.floor(Math.random()*a.length)],incercari=6,charArray1=[],charArray2=[],missArray=[],i=0;i=WINDOW_W?(ion.sound.play("ta_da"),alert("Felicita e tenersi per mano"),void window.location.reload()):(WINDOW_W>MOBILE_WIDH&&$("#gamewon").fadeIn("slow"),$(document).off(),ion.sound.play("ta_da"),$("#gamewon img").click(function(){window.location.reload()}),void $(document).on("keypress",function(a){var r=a.keyCode||a.which;13==r&&window.location.reload()}))}function gameOver(){return MOBILE_WIDH>=WINDOW_W?(ion.sound.play("sad_trombone"),alert("Ai pierdut! CUVANT: "+word),void window.location.reload()):($("#incercari_msg").html("Game Over!"),$("#lose_word").html(word),WINDOW_W>MOBILE_WIDH&&$("#gameover").fadeIn("slow"),$(document).off(),ion.sound.play("sad_trombone"),$("#gameover img").click(function(){window.location.reload()}),void $(document).on("keypress",function(a){var r=a.keyCode||a.which;13==r&&window.location.reload()}))}function check(a){return word.indexOf(a)>-1}function updateLetters(a){var r=missArray.length;$.inArray(a,missArray)>-1||(missArray[r]=a),$(".litere").html(missArray+" ")}function updateArray(a){for(a=a.toLowerCase(),i=0;iSpanzuratoarea created by@Niutenisu

');var listaCuvinte=localStorage.getItem("listaCuvinte");null!=listaCuvinte?($("select[name=lista_cuvinte]").val(listaCuvinte),newGame(eval(listaCuvinte))):newGame(animale_eu),$("select[name=lista_cuvinte]").on("change",function(){localStorage.setItem("listaCuvinte",$(this).val())}).next().click(function(){newGame(eval($(this).prev().val()))}),$("#game").fadeIn("slow")}),$(document).on("keypress",function(a){var r=a.keyCode||a.which,e=String.fromCharCode(r).toLowerCase();ion.sound.play("button_tiny"),$(".litera_msg").fadeIn("slow"),$(".litera").html(e),check(e)?($(".litera_msg2").html("aceasta litera se afla in cuvant."),updateArray(e),$(".word").html(charArray1)):($(".litera_msg2").html("aceasta litera nu se afla in cuvant."),incercari--,incercari>-1&&($("#human").attr("src","./img/"+incercari+".png"),$("#incercari").html(incercari),updateLetters(e),0==incercari&&gameOver())),arraysEqual(charArray1,charArray2)&&gameWon()}); diff --git a/src/hangman2.html b/src/hangman2.html new file mode 100644 index 0000000..0f937c2 --- /dev/null +++ b/src/hangman2.html @@ -0,0 +1,122 @@ + + + + + Spanzuratoarea + + + + + + + + + + + + + + + +

+

Spanzuratoarea!

+ +
+ + + + + + diff --git a/src/img/0.png b/src/img/0.png new file mode 100644 index 0000000..47d2d78 Binary files /dev/null and b/src/img/0.png differ diff --git a/src/img/1.png b/src/img/1.png new file mode 100644 index 0000000..1836d6a Binary files /dev/null and b/src/img/1.png differ diff --git a/src/img/2.png b/src/img/2.png new file mode 100644 index 0000000..96a9f62 Binary files /dev/null and b/src/img/2.png differ diff --git a/src/img/3.png b/src/img/3.png new file mode 100644 index 0000000..2ab2823 Binary files /dev/null and b/src/img/3.png differ diff --git a/src/img/4.png b/src/img/4.png new file mode 100644 index 0000000..d640b95 Binary files /dev/null and b/src/img/4.png differ diff --git a/src/img/5.png b/src/img/5.png new file mode 100644 index 0000000..330e033 Binary files /dev/null and b/src/img/5.png differ diff --git a/src/img/6.png b/src/img/6.png new file mode 100644 index 0000000..0dd8f76 Binary files /dev/null and b/src/img/6.png differ diff --git a/src/img/hang.png b/src/img/hang.png new file mode 100644 index 0000000..9ee8524 Binary files /dev/null and b/src/img/hang.png differ diff --git a/src/img/lose.png b/src/img/lose.png new file mode 100644 index 0000000..0149a89 Binary files /dev/null and b/src/img/lose.png differ diff --git a/src/img/win.png b/src/img/win.png new file mode 100644 index 0000000..a1ee521 Binary files /dev/null and b/src/img/win.png differ diff --git a/src/sound/ion.sound.js b/src/sound/ion.sound.js new file mode 100644 index 0000000..af7a0cd --- /dev/null +++ b/src/sound/ion.sound.js @@ -0,0 +1,345 @@ +/** + * Ion.Sound + * version 2.1.3 Build 47 + * © 2014 Denis Ineshin | IonDen.com + * + * Project page: http://ionden.com/a/plugins/ion.sound/en.html + * GitHub page: https://github.com/IonDen/ion.sound + * + * Released under MIT licence: + * http://ionden.com/a/plugins/licence-en.html + */ + +var ion = ion || {}; + +(function (ion) { + + var warn = function (text) { + if (text && console) { + if (console.warn && typeof console.warn === "function") { + console.warn(text); + } else if (console.log && typeof console.log === "function") { + console.log(text); + } + } + }; + + if (ion.sound) { + warn("ion.sound already exists!"); + return; + } + + if (typeof Audio !== "function" && typeof Audio !== "object") { + var func = function () { + warn("HTML5 Audio is not supported in this browser"); + }; + ion.sound = function () {}; + ion.sound.play = func; + ion.sound.stop = func; + ion.sound.destroy = func; + func(); + return; + } + + + + var Sound, + is_iOS = /iPad|iPhone/.test(navigator.appVersion), + global_sound, + settings = {}, + sounds = {}, + sounds_num, + ext, + i; + + + + if (is_iOS) { + + Sound = function (options) { + this.name = options.name; + this.loop = false; + this.paused = false; + this.sound = null; + this.callback = null; + }; + + Sound.prototype = { + init: function () { + this.sound = global_sound; + }, + + play: function (obj) { + if (!obj) { + obj = {}; + } + + if (obj.loop) { + if (this.paused) { + this._playLoop(this.loop + 1); + } else { + this._playLoop(obj.loop); + } + } else { + this.loop = false; + this._play(); + } + + if (obj.onEnded && typeof obj.onEnded === "function") { + this.callback = obj.onEnded; + } + }, + + _play: function () { + if (this.paused) { + this.paused = false; + } else { + try { + this.sound.currentTime = 0; + } catch (e) {} + } + + this.sound.removeEventListener("ended"); + this.sound.addEventListener("ended", this._ended.bind(this), false); + this.sound.src = settings.path + this.name + ext; + this.sound.load(); + this.sound.play(); + } + } + + } else { + + Sound = function (options) { + this.name = options.name; + this.volume = settings.volume || 0.5; + this.preload = settings.preload ? "auto" : "none"; + this.loop = false; + this.paused = false; + this.sound = null; + this.callback = null; + + if ("volume" in options) { + this.volume = +options.volume; + } + + if ("preload" in options) { + this.preload = options.preload ? "auto" : "none" + } + }; + + Sound.prototype = { + init: function () { + this.sound = new Audio(); + this.sound.src = settings.path + this.name + ext; + this.sound.load(); + this.sound.preload = this.preload; + this.sound.volume = this.volume; + + this.sound.addEventListener("ended", this._ended.bind(this), false); + }, + + play: function (obj) { + if (!obj) { + obj = {}; + } + + if (obj.volume || obj.volume === 0) { + this.volume = +obj.volume; + this.sound.volume = this.volume; + } + + if (obj.loop) { + if (this.paused) { + this._playLoop(this.loop + 1); + } else { + this._playLoop(obj.loop); + } + } else { + this.loop = false; + this._play(); + } + + if (obj.onEnded && typeof obj.onEnded === "function") { + this.callback = obj.onEnded; + } + }, + + _play: function () { + if (this.paused) { + this.paused = false; + } else { + try { + this.sound.currentTime = 0; + } catch (e) {} + } + + this.sound.play(); + } + }; + + } + + Sound.prototype._playLoop = function (loop) { + if (typeof loop === "boolean") { + // FF 3.6 and iOS, + // sound.loop = true not supported or buggy + this.loop = 9999999; + this._play(); + } else if (typeof loop === "number") { + this.loop = loop - 1; + this._play(); + } + }; + + Sound.prototype._ended = function () { + if (this.loop > 0) { + this.loop -= 1; + this._play(); + } + + if (this.callback) { + this.callback(this.name); + } + }; + + Sound.prototype.pause = function () { + this.paused = true; + this.sound.pause(); + }; + + Sound.prototype.stop = function () { + this.loop = false; + this.sound.pause(); + + try { + this.sound.currentTime = 0; + } catch (e) {} + }; + + Sound.prototype.destroy = function () { + this.stop(); + this.sound.removeEventListener("ended", this._ended.bind(this), false); + this.sound.src = ""; + this.sound = null; + }; + + + + var checkSupport = function () { + global_sound = new Audio(); + + var can_play_mp3 = global_sound.canPlayType('audio/mpeg'), + can_play_ogg = global_sound.canPlayType('audio/ogg'), + can_play_aac = global_sound.canPlayType('audio/mp4; codecs="mp4a.40.2"'); + + if (is_iOS) { + + if (can_play_mp3 === "probably") { + ext = ".mp3"; + } else if (can_play_aac === "probably") { + ext = ".aac"; + } else if (can_play_mp3 === "maybe") { + ext = ".mp3"; + } else if (can_play_aac === "maybe") { + ext = ".aac"; + } + + } else { + + if (can_play_mp3 === "probably") { + ext = ".mp3"; + } else if (can_play_ogg === "probably") { + ext = ".ogg"; + } else if (can_play_mp3 === "maybe") { + ext = ".mp3"; + } else if (can_play_ogg === "maybe") { + ext = ".ogg"; + } else { + ext = ".wav"; + } + + } + }; + + var createSound = function (obj) { + sounds[obj.name] = new Sound(obj); + sounds[obj.name].init(); + }; + + ion.sound = function (options) { + settings = JSON.parse(JSON.stringify(options)); + settings.path = settings.path || ""; + settings.volume = settings.volume || 0.5; + settings.preload = settings.preload || false; + settings.mix = settings.mix || true; + + sounds_num = settings.sounds.length; + + if (!sounds_num) { + warn("No sound-files provided!"); + return; + } + + checkSupport(); + + for (i = 0; i < sounds_num; i++) { + createSound(settings.sounds[i]); + } + }; + + ion.sound.version = "2.1.3"; + + ion.sound.play = function (name, options) { + if (sounds[name]) { + sounds[name].play(options); + } + }; + + ion.sound.pause = function (name) { + if (name && sounds[name]) { + sounds[name].pause(); + } else { + for (i in sounds) { + if (!sounds.hasOwnProperty(i)) { + continue; + } + if (sounds[i]) { + sounds[i].pause(); + } + } + } + }; + + ion.sound.stop = function (name) { + if (name && sounds[name]) { + sounds[name].stop(); + } else { + for (i in sounds) { + if (!sounds.hasOwnProperty(i)) { + continue; + } + if (sounds[i]) { + sounds[i].stop(); + } + } + } + }; + + ion.sound.destroy = function (name) { + if (name && sounds[name]) { + sounds[name].destroy(); + sounds[name] = null; + } else { + for (i in sounds) { + if (!sounds.hasOwnProperty(i)) { + continue; + } + if (sounds[i]) { + sounds[i].destroy(); + sounds[i] = null; + } + } + } + }; + +} (ion)); diff --git a/src/sound/ion.sound.min.js b/src/sound/ion.sound.min.js new file mode 100644 index 0000000..66683e2 --- /dev/null +++ b/src/sound/ion.sound.min.js @@ -0,0 +1,2 @@ +// Ion.Sound | version 2.1.3 | https://github.com/IonDen/ion.sound +var ion=ion||{};(function(e){var l=function(a){a&&console&&(console.warn&&"function"===typeof console.warn?console.warn(a):console.log&&"function"===typeof console.log&&console.log(a))};if(e.sound)l("ion.sound already exists!");else if("function"!==typeof Audio&&"object"!==typeof Audio){var g=function(){l("HTML5 Audio is not supported in this browser")};e.sound=function(){};e.sound.play=g;e.sound.stop=g;e.sound.destroy=g;g()}else{var f,m=/iPad|iPhone/.test(navigator.appVersion),k,d={},b={},n,h,c;m?(f=function(a){this.name=a.name;this.paused=this.loop=!1;this.callback=this.sound=null},f.prototype={init:function(){this.sound=k},play:function(a){a||(a={});a.loop?this.paused?this._playLoop(this.loop+1):this._playLoop(a.loop):(this.loop=!1,this._play());a.onEnded&&"function"===typeof a.onEnded&&(this.callback=a.onEnded)},_play:function(){if(this.paused)this.paused=!1;else try{this.sound.currentTime=0}catch(a){}this.sound.removeEventListener("ended");this.sound.addEventListener("ended",this._ended.bind(this),!1);this.sound.src=d.path+this.name+h;this.sound.load();this.sound.play()}}):(f=function(a){this.name=a.name;this.volume=d.volume||.5;this.preload=d.preload?"auto":"none";this.paused=this.loop=!1;this.callback=this.sound=null;"volume"in a&&(this.volume=+a.volume);"preload"in a&&(this.preload=a.preload?"auto":"none")},f.prototype={init:function(){this.sound=new Audio;this.sound.src=d.path+this.name+h;this.sound.load();this.sound.preload=this.preload;this.sound.volume=this.volume;this.sound.addEventListener("ended",this._ended.bind(this),!1)},play:function(a){a||(a={});if(a.volume||0===a.volume)this.volume=+a.volume,this.sound.volume=this.volume;a.loop?this.paused?this._playLoop(this.loop+1):this._playLoop(a.loop):(this.loop=!1,this._play());a.onEnded&&"function"===typeof a.onEnded&&(this.callback=a.onEnded)},_play:function(){if(this.paused)this.paused=!1;else try{this.sound.currentTime=0}catch(a){}this.sound.play()}});f.prototype._playLoop=function(a){"boolean"===typeof a?(this.loop=9999999,this._play()):"number"===typeof a&&(this.loop=a-1,this._play())};f.prototype._ended=function(){0