updated gameplay
This commit is contained in:
@@ -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;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<span class="label label-success pull-right num-of-words"></span>
|
||||
<span class="label label pull-right time-words"></span>
|
||||
<div class="hero-unit" style="text-align: center;">
|
||||
<h1><%= word %></h1>
|
||||
<h1 class="currentword"><%= word %></h1>
|
||||
<hr />
|
||||
<p>
|
||||
|
||||
|
Reference in New Issue
Block a user