angular.module('starter.controllers', []) .controller('DashCtrl', function($scope, $cordovaMedia, $state) { $scope.play = function(src) { var media = new Media(src, null, null); $cordovaMedia.play(media); } $scope.starte_spiel1 = function() { var media = new Media('/android_asset/www/sounds/spiel1.mp3', goto_spiel1, null); $cordovaMedia.play(media); } $scope.starte_spiel2 = function() { var media = new Media('/android_asset/www/sounds/spiel2.mp3', goto_spiel2, null); $cordovaMedia.play(media); } function goto_spiel1() { $state.go('tab.spiel1'); } function goto_spiel2() { $state.go('tab.spiel2'); } }) .controller('Spiel2Ctrl', function($scope, $cordovaMedia, $state) { $scope.spiele=[]; var tier = { bild: 'elefant.jpg', sound1: 'sound_elefant.mp3', sound2: '' }; $scope.spiele.push(tier); var tier1 = { bild: 'esel.jpg', sound1: 'sound_esel.mp3', sound2: '' }; $scope.spiele.push(tier1); var tier2 = { bild: 'hahn.jpg', sound1: 'sound_hahn.mp3', sound2: '' }; $scope.spiele.push(tier2); var tier3 = { bild: 'hund.jpg', sound1: 'sound_hund.mp3', sound2: '' }; $scope.spiele.push(tier3); var tier4 = { bild: 'katze.jpg', sound1: 'sound_katze.mp3', sound2: '' }; $scope.spiele.push(tier4); var tier5 = { bild: 'kuh.jpg', sound1: 'sound_kuh.mp3', sound2: '' }; $scope.spiele.push(tier5); var tier6 = { bild: 'maus.jpg', sound1: 'sound_maus.mp3', sound2: '' }; $scope.spiele.push(tier6); var tier7 = { bild: 'schaf.jpg', sound1: 'sound_schaf.mp3', sound2: '' }; $scope.spiele.push(tier7); $scope.play = function(src) { var media = new Media(src, null, null); $cordovaMedia.play(media); } }) .controller('Spiel1Ctrl', function($scope, $cordovaMedia, $state, $timeout) { $scope.spiele=[]; $scope.sounds=[]; $scope.tierfinden=''; $scope.randomid=0; $scope.error = false; $scope.sounds.push(''); var tier = { id: 1, bild: 'elefant.jpg', sound1: 'sound_elefant.mp3', antwort: '' }; $scope.spiele.push(tier); $scope.sounds.push('finde_elefant.mp3'); var tier1 = { id: 2, bild: 'esel.jpg', sound1: 'sound_esel.mp3', antwort: '' }; $scope.spiele.push(tier1); $scope.sounds.push('finde_esel.mp3'); var tier2 = { id: 3, bild: 'hahn.jpg', sound1: 'sound_hahn.mp3', antwort: '' }; $scope.spiele.push(tier2); $scope.sounds.push('finde_hahn.mp3'); var tier3 = { id: 4, bild: 'hund.jpg', sound1: 'sound_hund.mp3', sound2: '' }; $scope.spiele.push(tier3); $scope.sounds.push('finde_hund.mp3'); var tier4 = { id: 5, bild: 'katze.jpg', sound1: 'sound_katze.mp3', sound2: '' }; $scope.spiele.push(tier4); $scope.sounds.push('finde_katze.mp3'); var tier5 = { id: 6, bild: 'kuh.jpg', sound1: 'sound_kuh.mp3', sound2: '' }; $scope.spiele.push(tier5); $scope.sounds.push('finde_kuh.mp3'); var tier6 = { id: 7, bild: 'maus.jpg', sound1: 'sound_maus.mp3', sound2: '' }; $scope.spiele.push(tier6); $scope.sounds.push('finde_maus.mp3'); var tier7 = { id: 8, bild: 'schaf.jpg', sound1: 'sound_schaf.mp3', sound2: '' }; $scope.spiele.push(tier7); $scope.sounds.push('finde_schaf.mp3'); $scope.answer = function(src) { if (src==$scope.randomid){ $timeout(function () { $scope.spiele=shuffleArray($scope.spiele); $timeout(function () { $scope.spiele=shuffleArray($scope.spiele); $timeout(function () { $scope.spiele=shuffleArray($scope.spiele); }, 500); }, 500); }, 500); $scope.playwait('/android_asset/www/sounds/bravo.mp3') } else{ $scope.play('/android_asset/www/sounds/falsch.mp3'); $scope.error = true; $timeout(function () { $scope.error = false; }, 1000); } } 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; } function goto_newspiel() { $scope.randomid = getRandomInt(1, 8); $scope.play('/android_asset/www/sounds/' + $scope.sounds[$scope.randomid]); } 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; } $scope.play = function(src) { var media = new Media(src, null, null); $cordovaMedia.play(media); } $scope.playwait = function(src) { var media = new Media(src, goto_newspiel, null); $cordovaMedia.play(media); } goto_newspiel(); });