updated gameplay
This commit is contained in:
@@ -11,6 +11,7 @@ if (typeof(sw) == 'undefined') {
|
|||||||
var shuffle = function(obj) {
|
var shuffle = function(obj) {
|
||||||
return obj.sort( function() { return 0.5 - Math.random(); } );
|
return obj.sort( function() { return 0.5 - Math.random(); } );
|
||||||
};
|
};
|
||||||
|
|
||||||
var getKey = function(obj) {
|
var getKey = function(obj) {
|
||||||
var word = [];
|
var word = [];
|
||||||
for(var k in obj) word.push(k);
|
for(var k in obj) word.push(k);
|
||||||
@@ -35,16 +36,21 @@ if (typeof(sw) == 'undefined') {
|
|||||||
filtered.push(word);
|
filtered.push(word);
|
||||||
filtered = shuffle(filtered);
|
filtered = shuffle(filtered);
|
||||||
|
|
||||||
sw.currentWord = word;
|
|
||||||
return {word: word, similar: filtered};
|
return {word: word, similar: filtered};
|
||||||
};
|
};
|
||||||
|
|
||||||
var startGame = function() {
|
var startGame = function(word) {
|
||||||
$("#main").empty().html('views/index.ejs', selectWordsForGame());
|
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() {
|
var gameOver = function() {
|
||||||
sw.gameover = true;
|
|
||||||
var result = 'Sehr gut!';
|
var result = 'Sehr gut!';
|
||||||
|
|
||||||
if (sw.wrongWords > 1 || sw.finaltime > 50) {
|
if (sw.wrongWords > 1 || sw.finaltime > 50) {
|
||||||
@@ -53,7 +59,7 @@ if (typeof(sw) == 'undefined') {
|
|||||||
if (sw.wrongWords > 1 || sw.finaltime > 60) {
|
if (sw.wrongWords > 1 || sw.finaltime > 60) {
|
||||||
result = 'geht so...';
|
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';
|
result = 'Du bist sehr schnell, aber du hast Fehler gemacht';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,8 +67,9 @@ if (typeof(sw) == 'undefined') {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var startNewGame = function() {
|
var startNewGame = function() {
|
||||||
var playforwords = 10;
|
var playforrounds = 20;
|
||||||
sw.correctWords = 0;
|
sw.correctWords = 0;
|
||||||
|
sw.rounds = 1;
|
||||||
sw.wrongWords = 0;
|
sw.wrongWords = 0;
|
||||||
sw.time = Math.round((new Date()).getTime() / 1000);
|
sw.time = Math.round((new Date()).getTime() / 1000);
|
||||||
sw.gameover = false;
|
sw.gameover = false;
|
||||||
@@ -72,7 +79,7 @@ if (typeof(sw) == 'undefined') {
|
|||||||
$('.num-of-words').html(sw.correctWords + (sw.correctWords == 1 ? ' word' : ' words'));
|
$('.num-of-words').html(sw.correctWords + (sw.correctWords == 1 ? ' word' : ' words'));
|
||||||
$('.time-words').html(Math.round((new Date()).getTime() / 1000) - sw.time);
|
$('.time-words').html(Math.round((new Date()).getTime() / 1000) - sw.time);
|
||||||
|
|
||||||
if(playforwords > sw.correctWords + sw.wrongWords) {
|
if(playforrounds >= sw.rounds) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
updateBadges();
|
updateBadges();
|
||||||
}, 100);
|
}, 100);
|
||||||
@@ -111,28 +118,31 @@ if (typeof(sw) == 'undefined') {
|
|||||||
|
|
||||||
$(document).on('click', '.word-button', function(ev, el) {
|
$(document).on('click', '.word-button', function(ev, el) {
|
||||||
el = $(ev.currentTarget);
|
el = $(ev.currentTarget);
|
||||||
|
|
||||||
if (el.hasClass('disabled')) {
|
if (el.hasClass('disabled')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$('.word-button').addClass('disabled');
|
$('.word-button').addClass('disabled');
|
||||||
if(sw.currentWord == el.html()) {
|
|
||||||
|
var wrongWord = undefined;
|
||||||
|
if(sw.currentWord.word == el.html()) {
|
||||||
sw.correctWords = sw.correctWords + 1;
|
sw.correctWords = sw.correctWords + 1;
|
||||||
|
sw.rounds += 1;
|
||||||
el.addClass('btn-success');
|
el.addClass('btn-success');
|
||||||
} else {
|
} else {
|
||||||
|
wrongWord = sw.currentWord;
|
||||||
sw.wrongWords = sw.wrongWords + 1;
|
sw.wrongWords = sw.wrongWords + 1;
|
||||||
el.addClass('btn-danger');
|
el.addClass('btn-danger');
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
$('.word-button[data-word="' + sw.currentWord + '"]').addClass('btn-success');
|
|
||||||
|
|
||||||
if(sw.gameover) {
|
if(sw.gameover) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
gameOver();
|
gameOver();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
} else {
|
} else {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
startGame();
|
startGame(wrongWord);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
@@ -143,6 +153,7 @@ if (typeof(sw) == 'undefined') {
|
|||||||
sw.words = [];
|
sw.words = [];
|
||||||
sw.correctWords = 0;
|
sw.correctWords = 0;
|
||||||
sw.wrongWords = 0;
|
sw.wrongWords = 0;
|
||||||
|
sw.rounds = 0;
|
||||||
sw.time = 0;
|
sw.time = 0;
|
||||||
sw.finaltime = 0;
|
sw.finaltime = 0;
|
||||||
sw.gameover = false;
|
sw.gameover = false;
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
<span class="label label-success pull-right num-of-words"></span>
|
<span class="label label-success pull-right num-of-words"></span>
|
||||||
<span class="label label pull-right time-words"></span>
|
<span class="label label pull-right time-words"></span>
|
||||||
<div class="hero-unit" style="text-align: center;">
|
<div class="hero-unit" style="text-align: center;">
|
||||||
<h1><%= word %></h1>
|
<h1 class="currentword"><%= word %></h1>
|
||||||
<hr />
|
<hr />
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user