Backgrounddetection eingebaut (Soundstop), Bildschirm aktiv halten, Controller separiert
This commit is contained in:
parent
379f039d51
commit
562e25fa3d
@ -11,3 +11,4 @@ Plugins
|
||||
|
||||
ionic plugin add cordova-plugin-screen-orientation
|
||||
cordova plugin add cordova-plugin-media
|
||||
cordova plugin add https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git
|
||||
@ -52,7 +52,7 @@ to {background-position: -2000px 0;}
|
||||
width: 256px;
|
||||
height: 2560px;
|
||||
background: url('../img/mentor.png') left center;
|
||||
-webkit-animation: mentorsprite 4.5s steps(10) infinite;
|
||||
-webkit-animation: mentorsprite 3.8s steps(10) infinite;
|
||||
}
|
||||
|
||||
@-webkit-keyframes mentorsprite {
|
||||
@ -73,7 +73,7 @@ to {background-position: -2000px 0;}
|
||||
width: 256px;
|
||||
height: 1024px;
|
||||
background: url('../img/mentor_bravo.png') left center;
|
||||
-webkit-animation: mentorspritebravo 2.5s steps(4) infinite;
|
||||
-webkit-animation: mentorspritebravo 2.8s steps(4) infinite;
|
||||
}
|
||||
|
||||
@-webkit-keyframes mentorspritebravo {
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
<!-- your app's js -->
|
||||
<script src="js/app.js"></script>
|
||||
<script src="js/controllers.js"></script>
|
||||
<script src="js/home_controller.js"></script>
|
||||
<script src="js/suchspiel_controller.js"></script>
|
||||
<script src="js/services.js"></script>
|
||||
</head>
|
||||
<body ng-app="kinderspiel">
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// the 2nd parameter is an array of 'requires'
|
||||
angular.module('kinderspiel', ['ionic', 'ngCordova','ngAnimate', 'ngDraggable', 'kinderspiel.controllers', 'kinderspiel.services'])
|
||||
|
||||
.run(function($ionicPlatform) {
|
||||
.run(function($ionicPlatform, $state, backgroundsounds_mediahandler) {
|
||||
$ionicPlatform.ready(function() {
|
||||
if(window.cordova && window.cordova.plugins.Keyboard) {
|
||||
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
|
||||
@ -20,7 +20,55 @@ angular.module('kinderspiel', ['ionic', 'ngCordova','ngAnimate', 'ngDraggable',
|
||||
if(window.StatusBar) {
|
||||
StatusBar.styleDefault();
|
||||
}
|
||||
|
||||
/*
|
||||
* Bildschirm in Landscape modus drehen und halten
|
||||
*/
|
||||
screen.lockOrientation('landscape');
|
||||
|
||||
/*
|
||||
* Bildschirm aktiv halten
|
||||
*/
|
||||
window.plugins.insomnia.keepAwake();
|
||||
/*
|
||||
* Bildschirm aktiv halten ausschalten
|
||||
*/
|
||||
//window.plugins.insomnia.allowSleepAgain();
|
||||
|
||||
/*
|
||||
* Homebutton und Backgroundinfos abrufen
|
||||
*/
|
||||
document.addEventListener("resume", onResume, false);
|
||||
function onResume() {
|
||||
setTimeout(function() {
|
||||
backgroundsounds_mediahandler.setbackgroundstate(false);
|
||||
backgroundsounds_mediahandler.playbackgroundmusic();
|
||||
console.log("The application is resuming from the background" + backgroundsounds_mediahandler.getbackgroundstate());
|
||||
}, 0);
|
||||
}
|
||||
|
||||
document.addEventListener("pause", onPause, false);
|
||||
function onPause() {
|
||||
setTimeout(function() {
|
||||
backgroundsounds_mediahandler.setbackgroundstate(true);
|
||||
backgroundsounds_mediahandler.stopbackgroundmusic();
|
||||
console.log("The application is going to the background" + backgroundsounds_mediahandler.getbackgroundstate());
|
||||
}, 0);
|
||||
}
|
||||
/*
|
||||
* Backbutton Handling
|
||||
*/
|
||||
$ionicPlatform.registerBackButtonAction(function (event) {
|
||||
if($state.current.name=="home"){
|
||||
backgroundsounds_mediahandler.stopbackgroundmusic();
|
||||
navigator.app.exitApp(); //<-- remove this line to disable the exit
|
||||
}
|
||||
else {
|
||||
navigator.app.backHistory();
|
||||
}
|
||||
}, 100);
|
||||
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
@ -42,7 +90,7 @@ angular.module('kinderspiel', ['ionic', 'ngCordova','ngAnimate', 'ngDraggable',
|
||||
.state('spiel1', {
|
||||
url: '/spiel1',
|
||||
templateUrl: 'templates/spiel1.html',
|
||||
controller: 'Spiel1Ctrl'
|
||||
controller: 'Suchspiel'
|
||||
})
|
||||
|
||||
|
||||
|
||||
@ -1,286 +1 @@
|
||||
angular.module('kinderspiel.controllers', [])
|
||||
|
||||
.controller('home', function($scope, $ionicPlatform, $cordovaMedia, $state ) {
|
||||
|
||||
$scope.showmentor=false;
|
||||
|
||||
$ionicPlatform.ready(function() {
|
||||
var media = new Media('/android_asset/www/sounds/TORN.MID', fertig,null);
|
||||
//var media = new Media('/android_asset/www/sounds/hintergrundmusik1.mp3', fertig,null);
|
||||
var media1 = new Media('/android_asset/www/sounds/bravo.mp3', null,null);
|
||||
var mediastartespiel1 = new Media('/android_asset/www/sounds/spiel1.mp3', goto_spiel1,null);
|
||||
$scope.mymedia=media;
|
||||
$scope.mymedia1=media1;
|
||||
$scope.mediastartespiel1=mediastartespiel1;
|
||||
|
||||
$scope.mymedia.play();
|
||||
$scope.mymedia.setVolume('0.3');
|
||||
});
|
||||
|
||||
$scope.play = function(src) {
|
||||
var media = new Media(src, null, null);
|
||||
$cordovaMedia.play(media);
|
||||
}
|
||||
|
||||
|
||||
$scope.starte_spiel1 = function(){
|
||||
|
||||
}
|
||||
|
||||
$scope.starte_spiel2 = function(){
|
||||
$scope.mymedia1.play();
|
||||
$scope.mymedia1.setVolume('1.0');
|
||||
}
|
||||
|
||||
function fertig(){
|
||||
$scope.mymedia.play();
|
||||
$scope.mymedia.setVolume('0.3');
|
||||
}
|
||||
|
||||
|
||||
$scope.starte_spiel1 = function(){
|
||||
$scope.showmentor=true;
|
||||
$scope.mediastartespiel1.play();
|
||||
$scope.mediastartespiel1.setVolume('1.0');
|
||||
}
|
||||
|
||||
function goto_spiel1() {
|
||||
$scope.mediastartespiel1.release();
|
||||
$scope.showmentor=false;
|
||||
$state.go('spiel1');
|
||||
}
|
||||
|
||||
})
|
||||
.controller('Spiel1Ctrl', 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() {
|
||||
$scope.sounds=[];
|
||||
$scope.sounds.push('');
|
||||
|
||||
var media = new Media('/android_asset/www/sounds/hintergrundmusik1.mp3', fertig,null);
|
||||
|
||||
var tiersound1 = new Media('/android_asset/www/sounds/finde_elefant.mp3', null,null);
|
||||
var tiersound2 = new Media('/android_asset/www/sounds/finde_esel.mp3', null,null);
|
||||
var tiersound3 = new Media('/android_asset/www/sounds/finde_hahn.mp3', null,null);
|
||||
var tiersound4 = new Media('/android_asset/www/sounds/finde_hund.mp3', null,null);
|
||||
var tiersound5 = new Media('/android_asset/www/sounds/finde_katze.mp3', null,null);
|
||||
var tiersound6 = new Media('/android_asset/www/sounds/finde_kuh.mp3', null,null);
|
||||
var tiersound7 = new Media('/android_asset/www/sounds/finde_maus.mp3', null,null);
|
||||
var tiersound8 = new Media('/android_asset/www/sounds/finde_schaf.mp3', null,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.mymedia=media;
|
||||
|
||||
$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);
|
||||
|
||||
|
||||
//$scope.mymedia.play();
|
||||
//$scope.mymedia.setVolume('0.1');
|
||||
});
|
||||
|
||||
|
||||
function fertig(){
|
||||
$scope.mymedia.play();
|
||||
$scope.mymedia.setVolume('0.1');
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
$scope.hilfe = function() {
|
||||
$scope.showmentor=true;
|
||||
$timeout(function () {
|
||||
$scope.showmentor=false;
|
||||
}, 3500);
|
||||
$scope.sounds[$scope.randomid].play();
|
||||
}
|
||||
|
||||
$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);
|
||||
$scope.showmentorbravo=true;
|
||||
$timeout(function () {
|
||||
$scope.showmentorbravo=false;
|
||||
$timeout(function () {$scope.showmentor=true;}, 1200);
|
||||
}, 2400);
|
||||
$scope.bravosound.play();
|
||||
}
|
||||
else{
|
||||
$scope.falschsound.play();
|
||||
$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.showmentor=true;
|
||||
|
||||
$scope.randomid = getRandomInt(1, 8);
|
||||
//$scope.play('/android_asset/www/sounds/' + $scope.sounds[$scope.randomid]);
|
||||
$timeout(function () {
|
||||
$scope.showmentor=false;
|
||||
}, 3500);
|
||||
$scope.sounds[$scope.randomid].play();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
//4 Splaten Aufteilung
|
||||
|
||||
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);
|
||||
|
||||
goto_newspiel();
|
||||
|
||||
});
|
||||
var appControllers = angular.module('kinderspiel.controllers', []);
|
||||
23
www/js/home_controller.js
Normal file
23
www/js/home_controller.js
Normal file
@ -0,0 +1,23 @@
|
||||
appControllers.controller('home', function($scope, $ionicPlatform, $cordovaMedia, $state, backgroundsounds_mediahandler ) {
|
||||
|
||||
$scope.showmentor=false;
|
||||
|
||||
$ionicPlatform.ready(function() {
|
||||
var mediastartespiel1 = new Media('/android_asset/www/sounds/spiel1.mp3', spiel1_intro_finish,null);
|
||||
$scope.mediastartespiel1=mediastartespiel1;
|
||||
backgroundsounds_mediahandler.playbackgroundmusic();
|
||||
});
|
||||
|
||||
$scope.spiel1_intro = function(){
|
||||
$scope.showmentor=true;
|
||||
$scope.mediastartespiel1.play();
|
||||
$scope.mediastartespiel1.setVolume('1.0');
|
||||
}
|
||||
|
||||
function spiel1_intro_finish() {
|
||||
$scope.mediastartespiel1.release();
|
||||
$scope.showmentor=false;
|
||||
$state.go('spiel1');
|
||||
}
|
||||
|
||||
});
|
||||
@ -1,67 +1,45 @@
|
||||
angular.module('kinderspiel.services', [])
|
||||
|
||||
// for media plugin : http://plugins.cordova.io/#/package/org.apache.cordova.media
|
||||
.factory('MediaSrv', function($q, $cordovaMedia, $ionicPlatform){
|
||||
var service = {
|
||||
loadMedia: loadMedia,
|
||||
getStatusMessage: getStatusMessage,
|
||||
getErrorMessage: getErrorMessage
|
||||
};
|
||||
.factory("backgroundsounds_mediahandler", function($ionicPlatform, $cordovaMedia) {
|
||||
|
||||
/*
|
||||
* Checkvariable ob App im Hintergrund ist
|
||||
*/
|
||||
var inbackground=false;
|
||||
|
||||
function loadMedia(src, onStop, onError, onStatus){
|
||||
var defer = $q.defer();
|
||||
$ionicPlatform.ready(function(){
|
||||
var mediaStatus = {
|
||||
code: 0,
|
||||
text: getStatusMessage(0)
|
||||
};
|
||||
var mediaSuccess = function(){
|
||||
mediaStatus.code = 4;
|
||||
mediaStatus.text = getStatusMessage(4);
|
||||
if(onStop){onStop();}
|
||||
};
|
||||
var mediaError = function(err){
|
||||
_logError(src, err);
|
||||
if(onError){onError(err);}
|
||||
};
|
||||
var mediaStatus = function(status){
|
||||
mediaStatus.code = status;
|
||||
mediaStatus.text = getStatusMessage(status);
|
||||
if(onStatus){onStatus(status);}
|
||||
};
|
||||
|
||||
if($ionicPlatform.is('android')){src = '/android_asset/www/' + src;}
|
||||
var media = new $window.Media(src, mediaSuccess, mediaError, mediaStatus);
|
||||
media.status = mediaStatus;
|
||||
defer.resolve(media);
|
||||
/*
|
||||
* Soundfiles Variablen
|
||||
*/
|
||||
var backgroundmusic='';
|
||||
$ionicPlatform.ready(function() {
|
||||
var mybackground_music = new Media('/android_asset/www/sounds/TORN.MID', loopbackgroundmusic ,null);
|
||||
backgroundmusic=mybackground_music;
|
||||
});
|
||||
return defer.promise;
|
||||
|
||||
|
||||
function loopbackgroundmusic(){
|
||||
if (inbackground == false){
|
||||
backgroundmusic.play();
|
||||
backgroundmusic.setVolume('0.3');
|
||||
}
|
||||
}
|
||||
|
||||
function _logError(src, err){
|
||||
console.error('MediaSrv error', {
|
||||
code: err.code,
|
||||
text: getErrorMessage(err.code)
|
||||
});
|
||||
}
|
||||
|
||||
function getStatusMessage(status){
|
||||
if(status === 0){return 'Media.MEDIA_NONE';}
|
||||
else if(status === 1){return 'Media.MEDIA_STARTING';}
|
||||
else if(status === 2){return 'Media.MEDIA_RUNNING';}
|
||||
else if(status === 3){return 'Media.MEDIA_PAUSED';}
|
||||
else if(status === 4){return 'Media.MEDIA_STOPPED';}
|
||||
else {return 'Unknown status <'+status+'>';}
|
||||
return {
|
||||
playbackgroundmusic: function() {
|
||||
if (inbackground == false){
|
||||
backgroundmusic.play();
|
||||
backgroundmusic.setVolume('0.3');
|
||||
}
|
||||
|
||||
function getErrorMessage(code){
|
||||
if(code === 1){return 'MediaError.MEDIA_ERR_ABORTED';}
|
||||
else if(code === 2){return 'MediaError.MEDIA_ERR_NETWORK';}
|
||||
else if(code === 3){return 'MediaError.MEDIA_ERR_DECODE';}
|
||||
else if(code === 4){return 'MediaError.MEDIA_ERR_NONE_SUPPORTED';}
|
||||
else {return 'Unknown code <'+code+'>';}
|
||||
},
|
||||
stopbackgroundmusic: function() {
|
||||
backgroundmusic.stop();
|
||||
},
|
||||
setbackgroundstate: function(mybool) {
|
||||
inbackground=mybool;
|
||||
},
|
||||
getbackgroundstate: function() {
|
||||
return inbackground;
|
||||
}
|
||||
|
||||
return service;
|
||||
});
|
||||
};
|
||||
})
|
||||
246
www/js/suchspiel_controller.js
Normal file
246
www/js/suchspiel_controller.js
Normal file
@ -0,0 +1,246 @@
|
||||
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', null,null);
|
||||
var tiersound2 = new Media('/android_asset/www/sounds/finde_esel.mp3', null,null);
|
||||
var tiersound3 = new Media('/android_asset/www/sounds/finde_hahn.mp3', null,null);
|
||||
var tiersound4 = new Media('/android_asset/www/sounds/finde_hund.mp3', null,null);
|
||||
var tiersound5 = new Media('/android_asset/www/sounds/finde_katze.mp3', null,null);
|
||||
var tiersound6 = new Media('/android_asset/www/sounds/finde_kuh.mp3', null,null);
|
||||
var tiersound7 = new Media('/android_asset/www/sounds/finde_maus.mp3', null,null);
|
||||
var tiersound8 = new Media('/android_asset/www/sounds/finde_schaf.mp3', null,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;
|
||||
$timeout(function () {
|
||||
$scope.showmentor=false;
|
||||
}, 3500);
|
||||
$scope.sounds[$scope.randomid].play();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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);
|
||||
$scope.showmentorbravo=true;
|
||||
$timeout(function () {
|
||||
$scope.showmentorbravo=false;
|
||||
$timeout(function () {$scope.showmentor=true;}, 1200);
|
||||
}, 2400);
|
||||
$scope.bravosound.play();
|
||||
}
|
||||
else{
|
||||
$scope.falschsound.play();
|
||||
$scope.error = true;
|
||||
$timeout(function () {
|
||||
$scope.error = false;
|
||||
}, 1000);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Neues Spiel
|
||||
*/
|
||||
function goto_newspiel() {
|
||||
|
||||
$scope.showmentor=true;
|
||||
|
||||
$scope.randomid = getRandomInt(1, 8);
|
||||
//$scope.play('/android_asset/www/sounds/' + $scope.sounds[$scope.randomid]);
|
||||
$timeout(function () {
|
||||
$scope.showmentor=false;
|
||||
}, 3500);
|
||||
$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();
|
||||
|
||||
});
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
<div class="row">
|
||||
<div style="width: 100%; text-align: center;" class="col">
|
||||
<img class="myborder" src="img/elefant.jpg" height="128" width="128" ng-click="starte_spiel1()">
|
||||
<img class="myborder" src="img/elefant.jpg" height="128" width="128" ng-click="spiel1_intro()">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mentorborder" ng-show="showmentor">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user