Minispiel2 komplett eingebunden
This commit is contained in:
270
www/spielsets/minispielset2/js/minispiel_controller.js
Normal file
270
www/spielsets/minispielset2/js/minispiel_controller.js
Normal file
@@ -0,0 +1,270 @@
|
||||
appControllers.controller('Minispiel2', function($scope, $rootScope, $ionicPlatform, $cordovaMedia, backgroundsounds_mediahandler, $state, $timeout,$q, $http) {
|
||||
|
||||
|
||||
/*
|
||||
* Initialisierung
|
||||
*/
|
||||
$scope.spieleallebilder=[];
|
||||
$scope.chunkedDataBilder = [];
|
||||
$scope.chunkedDataBilderMask = [];
|
||||
|
||||
$scope.spielendecounter=4;
|
||||
|
||||
|
||||
/*
|
||||
* Spielset laden
|
||||
*/
|
||||
$http.get('spielsets/minispielset2/spielset.json').success(function(data) {
|
||||
$scope.spieleallebilder = data;
|
||||
bildermischen();
|
||||
});
|
||||
|
||||
|
||||
//$scope.$on("$ionicView.beforeEnter", function(event, data){
|
||||
|
||||
//});
|
||||
|
||||
|
||||
|
||||
$ionicPlatform.ready(function() {
|
||||
|
||||
/*
|
||||
* Sounds definieren
|
||||
*/
|
||||
|
||||
$scope.lachensounds=[];
|
||||
$scope.gamesounds=[];
|
||||
|
||||
|
||||
/*
|
||||
* Spiele IntroSounds laden
|
||||
* Typen: successsound -> Bravo, super, tollgemacht Sounds
|
||||
* Typen: failuresound -> Leider daneben, versuchs nochmal
|
||||
* Typen: cardsound -> Kartenlegegeräusch
|
||||
* Typen: solutionsound -> Auflösungsgeräusch, das wäre das Tier gewesen
|
||||
* Typen: gameoversound -> Spielzu ende Zeit für minispiel etc.
|
||||
* Typen: backgroundmusic -> Hintergrundmusik
|
||||
*/
|
||||
$http.get('spielsets/minispielset1/systemsounds.json').success(function(data) {
|
||||
|
||||
for(var i = 0; i < data.length; i++) {
|
||||
|
||||
if (data[i].type=='lachensound'){
|
||||
$scope.lachensounds.push(data[i].sound);
|
||||
}
|
||||
else if (data[i].type=='gamesound'){
|
||||
$scope.gamesounds.push(data[i].sound);
|
||||
|
||||
$timeout(function () {
|
||||
//playsound('gamesound', $scope.gamesounds[0], minispielstart,'1.0');
|
||||
}, 1000);
|
||||
}
|
||||
else if (data[i].type=='backgroundmusic'){
|
||||
//backgroundsounds_mediahandler.setbackgroundsoundfile(data[i].sound);
|
||||
//backgroundsounds_mediahandler.playbackgroundmusic();
|
||||
}
|
||||
|
||||
}//for-Schleife
|
||||
|
||||
});//$http
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Drei mal mischen :)
|
||||
*/
|
||||
function bildermischen(){
|
||||
$scope.spieleallebilder=shuffleArray($scope.spieleallebilder);
|
||||
$scope.spieleallebilder=shuffleArray($scope.spieleallebilder);
|
||||
$scope.spieleallebilder=shuffleArray($scope.spieleallebilder);
|
||||
|
||||
$scope.spiele=[];
|
||||
|
||||
for(var i = 0; i < 4; i++) {
|
||||
var data= $scope.spieleallebilder[i];
|
||||
data.id=i;
|
||||
$scope.spiele.push(data);
|
||||
}
|
||||
|
||||
$scope.chunkedDataBilder = chunk($scope.spiele, 1);
|
||||
$scope.chunkedDataBilderMask = chunk($scope.spiele, 2);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Play-Sound
|
||||
* playtype-> Bravo,Falsch oder Gamesound
|
||||
* soundfile-> Pfad zur sounddatei
|
||||
* callbackfunction-> Funktion die nach erfolgreichem abspielen gestarte wird
|
||||
* volume-> Lautstärke z.B. 1.0
|
||||
*/
|
||||
function playsound(playtype, soundfile, callbackfunction, volume){
|
||||
|
||||
$ionicPlatform.ready(function() {
|
||||
|
||||
if (playtype=='lachensound'){
|
||||
|
||||
/*
|
||||
* Nur durchführen wenn Bär nicht lacht
|
||||
*/
|
||||
if ($scope.bin_am_lachen==false){
|
||||
|
||||
try{
|
||||
|
||||
lachensound.release();
|
||||
|
||||
}
|
||||
catch(e){
|
||||
|
||||
//Soundfile Objekt gabs nicht oder Freigabefehler
|
||||
console.log("Sounddatei nicht da");
|
||||
}
|
||||
|
||||
lachensound = new Media(soundfile, callbackfunction ,null);
|
||||
$scope.bin_am_lachen=true;
|
||||
lachensound.play();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if (playtype=='gamesound'){
|
||||
|
||||
try{
|
||||
|
||||
//versuchen Soundfile freizugeben
|
||||
gamesound.release();
|
||||
|
||||
}
|
||||
catch(e){
|
||||
|
||||
//Soundfile Objekt gabs nicht oder Freigabefehler
|
||||
console.log("Sounddatei nicht da");
|
||||
}
|
||||
|
||||
gamesound = new Media(soundfile, callbackfunction ,null);
|
||||
gamesound.play();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$scope.onDragComplete=function(data,evt){
|
||||
|
||||
for(var i = 0; i < $scope.spiele.length; i++) {
|
||||
|
||||
if (data.id==$scope.spiele[i].id){
|
||||
$scope.spiele[i].dragged=false;
|
||||
}
|
||||
}
|
||||
console.log("drag success, data:", data);
|
||||
}
|
||||
|
||||
$scope.onDragStart=function(data,evt){
|
||||
|
||||
for(var i = 0; i < $scope.spiele.length; i++) {
|
||||
|
||||
if (data.id==$scope.spiele[i].id){
|
||||
$scope.spiele[i].dragged=true;
|
||||
}
|
||||
}
|
||||
console.log("drag start, data:", data);
|
||||
}
|
||||
|
||||
$scope.onDragStop=function(data,evt){
|
||||
|
||||
for(var i = 0; i < $scope.spiele.length; i++) {
|
||||
|
||||
if (data.id==$scope.spiele[i].id){
|
||||
$scope.spiele[i].dragged=false;
|
||||
}
|
||||
}
|
||||
console.log("drag stop, data:", data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$scope.onDropComplete=function(data,evt,dropid){
|
||||
|
||||
//richtige form erwischt
|
||||
if (data.id==dropid){
|
||||
for(var i = 0; i < $scope.spiele.length; i++) {
|
||||
|
||||
if (data.id==$scope.spiele[i].id){
|
||||
$scope.spiele[i].display=false;
|
||||
$scope.spiele[i].bildmaske=$scope.spiele[i].bild;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$scope.spielendecounter=$scope.spielendecounter - 1;
|
||||
}
|
||||
console.log("dropid: " + dropid + " drop success, data:", data);
|
||||
|
||||
if ($scope.spielendecounter==0){
|
||||
|
||||
$timeout(function () { $state.go('home'); }, 5000);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Bilder per Zufall mischen
|
||||
*/
|
||||
function shuffleArray(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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Bilder richtig in Zeilen ausgeben
|
||||
*/
|
||||
function chunk(arr, size) {
|
||||
var newArr = [];
|
||||
for (var i=0; i<arr.length; i+=size) {
|
||||
newArr.push(arr.slice(i, i+size));
|
||||
}
|
||||
return newArr;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user