656 lines
15 KiB
JavaScript
656 lines
15 KiB
JavaScript
appControllers.controller('Suchspiel', function($scope, $ionicPlatform, $cordovaMedia, $state, $timeout,$q) {
|
|
|
|
|
|
/*
|
|
* Initialisierung
|
|
*/
|
|
|
|
//Mentor-Animation ausschalten
|
|
$scope.showmentor=false;
|
|
$scope.showmentorbravo=false;
|
|
|
|
//Kartenarray + ListenAnsichtArray
|
|
$scope.spiele=[];
|
|
$scope.spielealletiere=[];
|
|
$scope.spielelistensort=[];
|
|
|
|
//Zufallsgenerator ID = TierindexID
|
|
$scope.randomid=0;
|
|
$scope.spielrunden=0;
|
|
$scope.falscheantwort=0;
|
|
|
|
//Karten-Index zum geben / nehmen
|
|
$scope.cardindex=0;
|
|
|
|
//CSS-Steuerung (alias für addClass)
|
|
$scope.CSSErrorCode=99;
|
|
$scope.CSSAusblendung='';
|
|
$scope.CSSEinblendung='';
|
|
$scope.CSSFalscheAntwort = false;
|
|
$scope.CCSInittimer = false;
|
|
|
|
//SpieleTimer
|
|
$scope.Spielzeit = 180;
|
|
$scope.showgametimer = false;
|
|
|
|
//Spielzeit vorbei
|
|
$scope.spielvorbei=false;
|
|
$scope.beantwortet=false;
|
|
|
|
//Mentor Zufallseinblendung
|
|
$scope.randomMentor=0;
|
|
|
|
$scope.punkte=0;
|
|
$scope.punktebonus=0;
|
|
|
|
|
|
//Zeitmessung für PunkteBonus
|
|
$scope.rundenstart = '';
|
|
$scope.rundenende = '';
|
|
|
|
|
|
$ionicPlatform.ready(function() {
|
|
|
|
/*
|
|
* Sounds definieren
|
|
*/
|
|
$scope.sounds=[];
|
|
$scope.bravosounds=[];
|
|
$scope.falschsounds=[];
|
|
$scope.aufloesung='';
|
|
/*
|
|
* Sounds laden
|
|
*/
|
|
var tiersound1 = new Media('/android_asset/www/sounds/soundsneu/finde_affe.mp3', mentorausblenden,null);
|
|
var tiersound2 = new Media('/android_asset/www/sounds/soundsneu/finde_esel.mp3', mentorausblenden,null);
|
|
var tiersound3 = new Media('/android_asset/www/sounds/soundsneu/finde_hase.mp3', mentorausblenden,null);
|
|
var tiersound4 = new Media('/android_asset/www/sounds/soundsneu/finde_hund.mp3', mentorausblenden,null);
|
|
var tiersound5 = new Media('/android_asset/www/sounds/soundsneu/finde_kamel.mp3', mentorausblenden,null);
|
|
var tiersound6 = new Media('/android_asset/www/sounds/soundsneu/finde_katze.mp3', mentorausblenden,null);
|
|
var tiersound7 = new Media('/android_asset/www/sounds/soundsneu/finde_krokodil.mp3', mentorausblenden,null);
|
|
var tiersound8 = new Media('/android_asset/www/sounds/soundsneu/finde_kuh.mp3', mentorausblenden,null);
|
|
var tiersound9 = new Media('/android_asset/www/sounds/soundsneu/finde_loewe.mp3', mentorausblenden,null);
|
|
var tiersound10 = new Media('/android_asset/www/sounds/soundsneu/finde_maus.mp3', mentorausblenden,null);
|
|
var tiersound11 = new Media('/android_asset/www/sounds/soundsneu/finde_nashorn.mp3', mentorausblenden,null);
|
|
var tiersound12 = new Media('/android_asset/www/sounds/soundsneu/finde_nilpferd.mp3', mentorausblenden,null);
|
|
var tiersound13 = new Media('/android_asset/www/sounds/soundsneu/finde_schaf.mp3', mentorausblenden,null);
|
|
var tiersound14 = new Media('/android_asset/www/sounds/soundsneu/finde_schildkroete.mp3', mentorausblenden,null);
|
|
var tiersound15 = new Media('/android_asset/www/sounds/soundsneu/finde_schwein.mp3', mentorausblenden,null);
|
|
var tiersound16 = new Media('/android_asset/www/sounds/soundsneu/finde_stier.mp3', mentorausblenden,null);
|
|
|
|
var bravosound1 = new Media('/android_asset/www/sounds/soundsneu/erfolg_1.mp3', karteausblenden,null);
|
|
var bravosound2 = new Media('/android_asset/www/sounds/soundsneu/erfolg_2.mp3', karteausblenden,null);
|
|
var bravosound3 = new Media('/android_asset/www/sounds/soundsneu/erfolg_3.mp3', karteausblenden,null);
|
|
var bravosound4 = new Media('/android_asset/www/sounds/soundsneu/erfolg_4.mp3', karteausblenden,null);
|
|
var bravosound5 = new Media('/android_asset/www/sounds/soundsneu/erfolg_5.mp3', karteausblenden,null);
|
|
|
|
|
|
var falschsound1 = new Media('/android_asset/www/sounds/soundsneu/niederlage_1.mp3', mentorausblenden,null);
|
|
var falschsound2 = new Media('/android_asset/www/sounds/soundsneu/niederlage_2.mp3', mentorausblenden,null);
|
|
var falschsound3 = new Media('/android_asset/www/sounds/soundsneu/niederlage_3.mp3', mentorausblenden,null);
|
|
var falschsound4 = new Media('/android_asset/www/sounds/soundsneu/niederlage_4.mp3', mentorausblenden,null);
|
|
var falschsound5 = new Media('/android_asset/www/sounds/soundsneu/niederlage_5.mp3', mentorausblenden,null);
|
|
|
|
var kartegebensound = new Media('/android_asset/www/sounds/karte.mp3', kartegeben,null);
|
|
var aufloesungsound = new Media('/android_asset/www/sounds/soundsneu/aufloesung.mp3', aufloesung,null);
|
|
|
|
|
|
/*
|
|
* Sounds in $Scope referenzieren
|
|
*/
|
|
$scope.kartegebensound=kartegebensound;
|
|
$scope.aufloesung=aufloesungsound;
|
|
|
|
$scope.bravosounds.push(bravosound1);
|
|
$scope.bravosounds.push(bravosound2);
|
|
$scope.bravosounds.push(bravosound3);
|
|
$scope.bravosounds.push(bravosound4);
|
|
$scope.bravosounds.push(bravosound5);
|
|
|
|
|
|
$scope.falschsounds.push(falschsound1);
|
|
$scope.falschsounds.push(falschsound2);
|
|
$scope.falschsounds.push(falschsound3);
|
|
$scope.falschsounds.push(falschsound4);
|
|
$scope.falschsounds.push(falschsound5);
|
|
|
|
|
|
/*
|
|
* Tiere definieren
|
|
*/
|
|
var tier = {
|
|
id: 0,
|
|
bild: 'Affe.png',
|
|
sound1: tiersound1,
|
|
display: false,
|
|
einblendecssid: 'affeein',
|
|
ausblendecssid: 'affeaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier);
|
|
|
|
|
|
var tier1 = {
|
|
id: 1,
|
|
bild: 'Esel.png',
|
|
sound1: tiersound2,
|
|
display: false,
|
|
einblendecssid: 'eselein',
|
|
ausblendecssid: 'eselaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier1);
|
|
|
|
|
|
var tier2 = {
|
|
id: 2,
|
|
bild: 'Hase.png',
|
|
sound1: tiersound3,
|
|
display: false,
|
|
einblendecssid: 'haseein',
|
|
ausblendecssid: 'haseaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier2);
|
|
|
|
|
|
var tier3 = {
|
|
id: 3,
|
|
bild: 'Hund.png',
|
|
sound1: tiersound4,
|
|
display: false,
|
|
einblendecssid: 'hundein',
|
|
ausblendecssid: 'hundaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier3);
|
|
|
|
|
|
var tier4 = {
|
|
id: 4,
|
|
bild: 'Kamel.png',
|
|
sound1: tiersound5,
|
|
display: false,
|
|
einblendecssid: 'kamelein',
|
|
ausblendecssid: 'kamelaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier4);
|
|
|
|
|
|
var tier5 = {
|
|
id: 5,
|
|
bild: 'Katze.png',
|
|
sound1: tiersound6,
|
|
display: false,
|
|
einblendecssid: 'katzeein',
|
|
ausblendecssid: 'katzeaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier5);
|
|
|
|
|
|
var tier6 = {
|
|
id: 6,
|
|
bild: 'Krokodil.png',
|
|
sound1: tiersound7,
|
|
display: false,
|
|
einblendecssid: 'krokodilein',
|
|
ausblendecssid: 'krokodilaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier6);
|
|
|
|
|
|
var tier7 = {
|
|
id: 7,
|
|
bild: 'Kuh.png',
|
|
sound1: tiersound8,
|
|
display: false,
|
|
einblendecssid: 'kuhein',
|
|
ausblendecssid: 'kuhaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier7);
|
|
|
|
|
|
var tier8 = {
|
|
id: 8,
|
|
bild: 'Loewe.png',
|
|
sound1: tiersound9,
|
|
display: false,
|
|
einblendecssid: 'loeweein',
|
|
ausblendecssid: 'loeweaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier8);
|
|
|
|
var tier9 = {
|
|
id: 9,
|
|
bild: 'Maus.png',
|
|
sound1: tiersound10,
|
|
display: false,
|
|
einblendecssid: 'mausein',
|
|
ausblendecssid: 'mausaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier9);
|
|
|
|
var tier10 = {
|
|
id: 10,
|
|
bild: 'Nashorn.png',
|
|
sound1: tiersound11,
|
|
display: false,
|
|
einblendecssid: 'nashornein',
|
|
ausblendecssid: 'nashornaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier10);
|
|
|
|
var tier11 = {
|
|
id: 11,
|
|
bild: 'Nilpferd.png',
|
|
sound1: tiersound12,
|
|
display: false,
|
|
einblendecssid: 'nilpferdein',
|
|
ausblendecssid: 'nilpferdaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier11);
|
|
|
|
var tier12 = {
|
|
id: 12,
|
|
bild: 'Schaf.png',
|
|
sound1: tiersound13,
|
|
display: false,
|
|
einblendecssid: 'schafein',
|
|
ausblendecssid: 'schafaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier12);
|
|
|
|
var tier13 = {
|
|
id: 13,
|
|
bild: 'Schildkroete.png',
|
|
sound1: tiersound14,
|
|
display: false,
|
|
einblendecssid: 'schildkroeteein',
|
|
ausblendecssid: 'schildkroeteaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier13);
|
|
|
|
|
|
var tier14 = {
|
|
id: 14,
|
|
bild: 'Schwein.png',
|
|
sound1: tiersound15,
|
|
display: false,
|
|
einblendecssid: 'schweinein',
|
|
ausblendecssid: 'schweinaus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier14);
|
|
|
|
|
|
var tier15 = {
|
|
id: 15,
|
|
bild: 'Stier.png',
|
|
sound1: tiersound16,
|
|
display: false,
|
|
einblendecssid: 'stierein',
|
|
ausblendecssid: 'stieraus',
|
|
sortid: 0
|
|
};
|
|
$scope.spielealletiere.push(tier15);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Wiederholung der Aufgabe
|
|
*/
|
|
$scope.hilfe = function() {
|
|
console.log("Hilfe geklickt");
|
|
$scope.showmentor=true;
|
|
$scope.spiele[$scope.randomid].sound1.play();
|
|
}
|
|
|
|
|
|
/*
|
|
* Mentor ausblenden, nach Soundausgabe
|
|
*/
|
|
function mentorausblenden(){
|
|
$timeout(function () { $scope.showmentor=false; $scope.cardindex=0}, 10);
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
* Antwort prüfen
|
|
*/
|
|
$scope.PlayerAnswer = function(src) {
|
|
|
|
/*
|
|
* Einblende-effekte zurücksetzen
|
|
*/
|
|
$scope.CSSEinblendung='';
|
|
|
|
/*
|
|
* Prüfen ob schon einmal geklickt wurde
|
|
*/
|
|
if ($scope.beantwortet==false){
|
|
|
|
/*
|
|
* Antwort ist richtig
|
|
*/
|
|
$scope.beantwortet=true;
|
|
if (src==$scope.randomid){
|
|
$timeout(function () {
|
|
$scope.punkte=$scope.punkte + 1000;
|
|
$scope.rundenende = new Date().getTime();
|
|
//Zeitbonus
|
|
$scope.punktebonus=1000 / (($scope.rundenende - $scope.rundenstart)/1000);
|
|
console.log($scope.rundenende - $scope.rundenstart + " Start:" + $scope.rundenstart + " Ende:" + $scope.rundenende);
|
|
$scope.punktebonus=Math.round($scope.punktebonus);
|
|
|
|
$scope.punkte = $scope.punkte + $scope.punktebonus;
|
|
|
|
$scope.randomMentor=getRandomInt(1, 2);
|
|
if ($scope.randomMentor==2){
|
|
$scope.showmentorbravo=true;
|
|
}
|
|
else{
|
|
$scope.showmentor=true;
|
|
}
|
|
|
|
$scope.cardindex=0;
|
|
}, 0);
|
|
$scope.bravosounds[getRandomInt(0, 4)].play();
|
|
}
|
|
else{
|
|
|
|
/*
|
|
* Antwort war dreimal falsch
|
|
*/
|
|
if ($scope.falscheantwort==2){
|
|
|
|
/*
|
|
* Richtige Karte pulsieren lassen
|
|
*/
|
|
$scope.CSSErrorCode=$scope.randomid;
|
|
$scope.CSSFalscheAntwort= false;
|
|
/*
|
|
* Nach 3 sekunden Fehler zurücksetzen und Karten neu vergeben
|
|
*/
|
|
$scope.showmentor=true;
|
|
$scope.aufloesung.play();
|
|
}
|
|
else {
|
|
/*
|
|
* Antwort ist falsch
|
|
*/
|
|
$scope.showmentor=true;
|
|
$scope.falschsounds[getRandomInt(0, 4)].play();
|
|
$scope.CSSFalscheAntwort = true;
|
|
$timeout(function () {
|
|
$scope.CSSFalscheAntwort = false;
|
|
$scope.beantwortet=false;
|
|
$scope.falscheantwort=$scope.falscheantwort + 1
|
|
}, 1000);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Neues Spiel starten
|
|
*/
|
|
function goto_newspiel(){
|
|
$scope.CSSErrorCode=99;
|
|
$scope.falscheantwort=0;
|
|
$scope.CSSEinblendung='';
|
|
$scope.cardindex=0;
|
|
|
|
kartenmischen();
|
|
|
|
//$timeout(function () { $scope.kartegebensound.play(); }, 2000);
|
|
kartegeben();
|
|
}
|
|
|
|
|
|
/*
|
|
* Karten austeilen
|
|
*/
|
|
function kartegeben(){
|
|
$timeout(function () {
|
|
$scope.spielelistensort[$scope.cardindex].display=true;
|
|
|
|
for(var i = 0; i < $scope.spiele.length; i++) {
|
|
var data= $scope.spiele[i];
|
|
if (data.id==$scope.spielelistensort[$scope.cardindex].id){
|
|
$scope.CSSEinblendung=data.einblendecssid;
|
|
console.log("Einblende Schleife ID: " + $scope.CSSEinblendung);
|
|
}
|
|
}
|
|
$scope.cardindex=$scope.cardindex + 1;
|
|
}, 0);
|
|
/*
|
|
* Interner Zähler bis alle Karten gegeben wurden
|
|
*/
|
|
if ($scope.cardindex < 7 ){
|
|
$scope.kartegebensound.play();
|
|
}
|
|
else{
|
|
$scope.CSSEinblendung='';
|
|
/*
|
|
* Zufallszahl 3x mal generieren lassen, zufälliger
|
|
*/
|
|
$scope.randomid=getRandomInt(0, 7);
|
|
$scope.randomid=getRandomInt(0, 7);
|
|
$scope.randomid=getRandomInt(0, 7);
|
|
|
|
|
|
$scope.rundenstart = new Date().getTime();
|
|
/*
|
|
* Mentor anzeigen und Sound wiedergeben
|
|
*/
|
|
$scope.showmentor=true;
|
|
$scope.spiele[$scope.randomid].sound1.play();
|
|
console.log("ELSE-Zweig Einblende -ID: " + $scope.CSSEinblendung);
|
|
console.log("CardIndex: " + $scope.cardindex);
|
|
console.log("Zufallsid: " + $scope.randomid);
|
|
console.log("Tiersuchen: " + $scope.spiele[$scope.randomid].bild);
|
|
}
|
|
console.log("Einblende funktion ID: " + $scope.CSSEinblendung);
|
|
}
|
|
|
|
/*
|
|
* Karten wieder einsammeln, runde beendet
|
|
*/
|
|
function karteausblenden(){
|
|
$timeout(function () { $scope.showmentorbravo=false; $scope.showmentor=false;}, 0);
|
|
|
|
if ($scope.spielvorbei==false){
|
|
|
|
if ($scope.cardindex < 8 ){
|
|
|
|
for(var i = 0; i < $scope.spiele.length; i++) {
|
|
var data= $scope.spiele[i];
|
|
if (data.id==$scope.spielelistensort[$scope.cardindex].id){
|
|
$scope.CSSAusblendung=data.ausblendecssid;
|
|
}
|
|
}
|
|
$timeout(function () {
|
|
$scope.spielelistensort[$scope.cardindex].display=false;
|
|
$scope.chunkedData = chunk($scope.spielelistensort, 4);
|
|
$scope.cardindex=$scope.cardindex + 1;
|
|
karteausblenden();
|
|
}, 500);
|
|
}
|
|
else{
|
|
$scope.beantwortet=false;
|
|
$scope.CSSAusblendung='';
|
|
goto_newspiel();
|
|
}
|
|
|
|
}
|
|
else{
|
|
//Belohnung hier rein
|
|
$state.go('home');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
* SpieleTimer Funktion
|
|
*/
|
|
function SpieleTimer(){
|
|
if ($scope.Spielzeit > 0){
|
|
|
|
$scope.Spielzeit=$scope.Spielzeit - 1;
|
|
$timeout(function () {
|
|
SpieleTimer();
|
|
}, 1000);
|
|
|
|
}
|
|
else{
|
|
$scope.spielvorbei=true;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
function aufloesung(){
|
|
|
|
$scope.CSSErrorCode=99;
|
|
$scope.cardindex=0;
|
|
karteausblenden();
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
* Drei mal mischen :)
|
|
*/
|
|
function kartenmischen(){
|
|
$scope.spielealletiere=shuffleArray($scope.spielealletiere);
|
|
$scope.spielealletiere=shuffleArray($scope.spielealletiere);
|
|
$scope.spielealletiere=shuffleArray($scope.spielealletiere);
|
|
|
|
$scope.spiele=[];
|
|
for(var i = 0; i < 8; i++) {
|
|
var data= $scope.spielealletiere[i];
|
|
data.id=i;
|
|
$scope.spiele.push(data);
|
|
}
|
|
|
|
|
|
$scope.spielelistensort=[];
|
|
//for(var i = 0; i < $scope.spiele.length; i++) {
|
|
for(var i = 0; i < 8; i++) {
|
|
var data= $scope.spiele[i];
|
|
data.sortid=i;
|
|
$scope.spielelistensort.push(data);
|
|
}
|
|
$scope.chunkedData = chunk($scope.spielelistensort, 4);
|
|
}
|
|
|
|
|
|
/*
|
|
* Zufallsgenerator um per Zufall neue Aufgabe definieren
|
|
*/
|
|
function getRandomInt(min, max) {
|
|
var tmpInt=0;
|
|
min = Math.ceil(min);
|
|
max = Math.floor(max);
|
|
tmpInt = Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
if (tmpInt > max){
|
|
tmpInt=max;
|
|
}
|
|
|
|
if (tmpInt < min){
|
|
tmpInt=min;
|
|
}
|
|
return tmpInt;
|
|
}
|
|
|
|
/*
|
|
* Karten per Zufall mischen
|
|
*/
|
|
var shuffleArray = function(array) {
|
|
var m = array.length, t, i;
|
|
|
|
// While there remain elements to shuffle
|
|
while (m) {
|
|
// Pick a remaining element…
|
|
i = Math.floor(Math.random() * m--);
|
|
|
|
// And swap it with the current element.
|
|
t = array[m];
|
|
array[m] = array[i];
|
|
array[i] = t;
|
|
}
|
|
|
|
return array;
|
|
}
|
|
|
|
/*
|
|
* TierArray nach x Spalten Aufteilen (Darstellung)
|
|
*/
|
|
function chunk(arr, size) {
|
|
var newArr = [];
|
|
for (var i=0; i<arr.length; i+=size) {
|
|
newArr.push(arr.slice(i, i+size));
|
|
}
|
|
return newArr;
|
|
}
|
|
//$scope.chunkedData = chunk($scope.spiele, 4);
|
|
|
|
|
|
/*
|
|
* Initial - Neues Spiel starten (erste runde) von 3 runter zählen
|
|
*/
|
|
$scope.inittimercounter=3;
|
|
$scope.showinittimer=true;
|
|
$scope.CCSInittimer=true;
|
|
|
|
$timeout(function () {
|
|
$scope.CCSInittimer=false;
|
|
inittimer();
|
|
}, 1500);
|
|
|
|
|
|
|
|
function inittimer(){
|
|
$scope.CCSInittimer=true;
|
|
if ($scope.inittimercounter > 1){
|
|
$scope.inittimercounter=$scope.inittimercounter - 1;
|
|
|
|
$timeout(function () {
|
|
$scope.CCSInittimer=false;
|
|
inittimer();
|
|
}, 1000);
|
|
|
|
}
|
|
else{
|
|
$scope.inittimercounter='Los gehts!';
|
|
$timeout(function () {
|
|
$scope.showinittimer=false;
|
|
$scope.showgametimer = true;
|
|
SpieleTimer();
|
|
goto_newspiel();
|
|
}, 1000);
|
|
}
|
|
}
|
|
|
|
|
|
}); |