245 lines
4.8 KiB
JavaScript
245 lines
4.8 KiB
JavaScript
appControllers.controller('Suchspiel', function($scope, $ionicPlatform, $cordovaMedia, $state, $timeout) {
|
|
|
|
|
|
$scope.showmentor=false;
|
|
$scope.showmentorbravo=false;
|
|
$scope.spiele=[];
|
|
$scope.spieleview=[];
|
|
$scope.tierfinden='';
|
|
$scope.randomid=0;
|
|
$scope.error = false;
|
|
|
|
|
|
$ionicPlatform.ready(function() {
|
|
|
|
/*
|
|
* Sounds definieren
|
|
*/
|
|
$scope.sounds=[];
|
|
$scope.sounds.push('');
|
|
|
|
var tiersound1 = new Media('/android_asset/www/sounds/finde_elefant.mp3', mentorausblenden,null);
|
|
var tiersound2 = new Media('/android_asset/www/sounds/finde_esel.mp3', mentorausblenden,null);
|
|
var tiersound3 = new Media('/android_asset/www/sounds/finde_hahn.mp3', mentorausblenden,null);
|
|
var tiersound4 = new Media('/android_asset/www/sounds/finde_hund.mp3', mentorausblenden,null);
|
|
var tiersound5 = new Media('/android_asset/www/sounds/finde_katze.mp3', mentorausblenden,null);
|
|
var tiersound6 = new Media('/android_asset/www/sounds/finde_kuh.mp3', mentorausblenden,null);
|
|
var tiersound7 = new Media('/android_asset/www/sounds/finde_maus.mp3', mentorausblenden,null);
|
|
var tiersound8 = new Media('/android_asset/www/sounds/finde_schaf.mp3', mentorausblenden,null);
|
|
|
|
var bravosound = new Media('/android_asset/www/sounds/bravo.mp3', goto_newspiel,null);
|
|
var falschsound = new Media('/android_asset/www/sounds/falsch.mp3', null,null);
|
|
|
|
$scope.bravosound=bravosound;
|
|
$scope.falschsound=falschsound;
|
|
|
|
$scope.sounds.push(tiersound1);
|
|
$scope.sounds.push(tiersound2);
|
|
$scope.sounds.push(tiersound3);
|
|
$scope.sounds.push(tiersound4);
|
|
$scope.sounds.push(tiersound5);
|
|
$scope.sounds.push(tiersound6);
|
|
$scope.sounds.push(tiersound7);
|
|
$scope.sounds.push(tiersound8);
|
|
|
|
});
|
|
|
|
|
|
/*
|
|
* Tiere definieren
|
|
*/
|
|
var tier = {
|
|
id: 1,
|
|
bild: 'elefant.jpg',
|
|
sound1: 'sound_elefant.mp3',
|
|
antwort: ''
|
|
};
|
|
$scope.spiele.push(tier);
|
|
|
|
|
|
var tier1 = {
|
|
id: 2,
|
|
bild: 'esel.jpg',
|
|
sound1: 'sound_esel.mp3',
|
|
antwort: ''
|
|
};
|
|
$scope.spiele.push(tier1);
|
|
|
|
|
|
var tier2 = {
|
|
id: 3,
|
|
bild: 'hahn.jpg',
|
|
sound1: 'sound_hahn.mp3',
|
|
antwort: ''
|
|
};
|
|
$scope.spiele.push(tier2);
|
|
|
|
|
|
var tier3 = {
|
|
id: 4,
|
|
bild: 'hund.jpg',
|
|
sound1: 'sound_hund.mp3',
|
|
sound2: ''
|
|
};
|
|
$scope.spiele.push(tier3);
|
|
|
|
|
|
var tier4 = {
|
|
id: 5,
|
|
bild: 'katze.jpg',
|
|
sound1: 'sound_katze.mp3',
|
|
sound2: ''
|
|
};
|
|
$scope.spiele.push(tier4);
|
|
|
|
|
|
var tier5 = {
|
|
id: 6,
|
|
bild: 'kuh.jpg',
|
|
sound1: 'sound_kuh.mp3',
|
|
sound2: ''
|
|
};
|
|
$scope.spiele.push(tier5);
|
|
|
|
|
|
var tier6 = {
|
|
id: 7,
|
|
bild: 'maus.jpg',
|
|
sound1: 'sound_maus.mp3',
|
|
sound2: ''
|
|
};
|
|
$scope.spiele.push(tier6);
|
|
|
|
|
|
var tier7 = {
|
|
id: 8,
|
|
bild: 'schaf.jpg',
|
|
sound1: 'sound_schaf.mp3',
|
|
sound2: ''
|
|
};
|
|
$scope.spiele.push(tier7);
|
|
|
|
/*
|
|
* Wiederholung der Aufgabe
|
|
*/
|
|
$scope.hilfe = function() {
|
|
$scope.showmentor=true;
|
|
$scope.sounds[$scope.randomid].play();
|
|
}
|
|
|
|
|
|
/*
|
|
* Mentor ausblenden
|
|
*/
|
|
function mentorausblenden(){
|
|
$timeout(function () { $scope.showmentor=false; }, 10);
|
|
}
|
|
|
|
|
|
/*
|
|
* Antwort prüfen
|
|
*/
|
|
$scope.answer = function(src) {
|
|
|
|
if (src==$scope.randomid){
|
|
|
|
$timeout(function () {
|
|
$scope.spiele=shuffleArray($scope.spiele);
|
|
$scope.chunkedData = chunk($scope.spiele, 4);
|
|
$timeout(function () {
|
|
$scope.spiele=shuffleArray($scope.spiele);
|
|
$scope.chunkedData = chunk($scope.spiele, 4);
|
|
$timeout(function () {
|
|
$scope.spiele=shuffleArray($scope.spiele);
|
|
$scope.chunkedData = chunk($scope.spiele, 4);
|
|
}, 500);
|
|
}, 500);
|
|
}, 500);
|
|
$timeout(function () { $scope.showmentorbravo=true; }, 0);
|
|
$scope.bravosound.play();
|
|
}
|
|
else{
|
|
$scope.falschsound.play();
|
|
$scope.error = true;
|
|
$timeout(function () {
|
|
$scope.error = false;
|
|
}, 1000);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
* Neues Spiel
|
|
*/
|
|
function goto_newspiel(){
|
|
|
|
$timeout(function () {
|
|
$scope.showmentor=true;
|
|
$scope.showmentorbravo=false;
|
|
},0);
|
|
$scope.randomid = getRandomInt(1, 8);
|
|
$scope.sounds[$scope.randomid].play();
|
|
}
|
|
|
|
/*
|
|
* 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;
|
|
}
|
|
|
|
/*
|
|
* TierArray 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);
|
|
|
|
/*
|
|
* Neues Spiel starten
|
|
*/
|
|
goto_newspiel();
|
|
|
|
}); |