updated gameplay

This commit is contained in:
s2
2013-04-06 12:28:09 +02:00
parent 48ca2eae8b
commit 74dd36d0a8
2 changed files with 23 additions and 12 deletions

View File

@@ -11,6 +11,7 @@ if (typeof(sw) == 'undefined') {
var shuffle = function(obj) {
return obj.sort( function() { return 0.5 - Math.random(); } );
};
var getKey = function(obj) {
var word = [];
for(var k in obj) word.push(k);
@@ -35,16 +36,21 @@ if (typeof(sw) == 'undefined') {
filtered.push(word);
filtered = shuffle(filtered);
sw.currentWord = word;
return {word: word, similar: filtered};
};
var startGame = function() {
$("#main").empty().html('views/index.ejs', selectWordsForGame());
var startGame = function(word) {
if(typeof(word) == 'undefined') {
word = selectWordsForGame();
}
sw.currentWord = word;
$("#main").empty().html('views/index.ejs', word);
$('.currentword').animate({
opacity : 0
}, 1000, 'linear');
};
var gameOver = function() {
sw.gameover = true;
var result = 'Sehr gut!';
if (sw.wrongWords > 1 || sw.finaltime > 50) {
@@ -53,7 +59,7 @@ if (typeof(sw) == 'undefined') {
if (sw.wrongWords > 1 || sw.finaltime > 60) {
result = 'geht so...';
};
if (sw.wrongWords > 1 && sw.finaltime < 40) {
if (sw.wrongWords >= 1 && sw.finaltime < 40) {
result = 'Du bist sehr schnell, aber du hast Fehler gemacht';
};
@@ -61,8 +67,9 @@ if (typeof(sw) == 'undefined') {
};
var startNewGame = function() {
var playforwords = 10;
var playforrounds = 20;
sw.correctWords = 0;
sw.rounds = 1;
sw.wrongWords = 0;
sw.time = Math.round((new Date()).getTime() / 1000);
sw.gameover = false;
@@ -72,7 +79,7 @@ if (typeof(sw) == 'undefined') {
$('.num-of-words').html(sw.correctWords + (sw.correctWords == 1 ? ' word' : ' words'));
$('.time-words').html(Math.round((new Date()).getTime() / 1000) - sw.time);
if(playforwords > sw.correctWords + sw.wrongWords) {
if(playforrounds >= sw.rounds) {
setTimeout(function() {
updateBadges();
}, 100);
@@ -111,28 +118,31 @@ if (typeof(sw) == 'undefined') {
$(document).on('click', '.word-button', function(ev, el) {
el = $(ev.currentTarget);
if (el.hasClass('disabled')) {
return;
}
$('.word-button').addClass('disabled');
if(sw.currentWord == el.html()) {
var wrongWord = undefined;
if(sw.currentWord.word == el.html()) {
sw.correctWords = sw.correctWords + 1;
sw.rounds += 1;
el.addClass('btn-success');
} else {
wrongWord = sw.currentWord;
sw.wrongWords = sw.wrongWords + 1;
el.addClass('btn-danger');
}
setTimeout(function() {
$('.word-button[data-word="' + sw.currentWord + '"]').addClass('btn-success');
if(sw.gameover) {
setTimeout(function() {
gameOver();
}, 1000);
} else {
setTimeout(function() {
startGame();
startGame(wrongWord);
}, 1000);
}
}, 1000);
@@ -143,6 +153,7 @@ if (typeof(sw) == 'undefined') {
sw.words = [];
sw.correctWords = 0;
sw.wrongWords = 0;
sw.rounds = 0;
sw.time = 0;
sw.finaltime = 0;
sw.gameover = false;