Skip to content
Snippets Groups Projects
Verified Commit e3b21907 authored by Ben Eltschig's avatar Ben Eltschig
Browse files

kleinere Verbesserungen

parent af03f1ea
1 merge request!5Custom server
...@@ -267,7 +267,7 @@ export default class SkribblServer { ...@@ -267,7 +267,7 @@ export default class SkribblServer {
if (this._hasGameStarted){ if (this._hasGameStarted){
if (player.guessedWord||playerIndex==this._drawingPlayer){ if (player.guessedWord||playerIndex==this._drawingPlayer){
// TODO let people who already know the word send ghost messages to others who already know it too // TODO let people who already know the word send ghost messages to others who already know it too
}else if (word===this._word){ }else if (typeof this._word=="string"&&SkribblServer._isCorrect(word,this._word)){
player.guessedWord = true; player.guessedWord = true;
player.guessedIndex = Math.max(...this._clients.map(client=>client.guessedIndex))+1; player.guessedIndex = Math.max(...this._clients.map(client=>client.guessedIndex))+1;
this._clients.forEach((client,index)=>{ this._clients.forEach((client,index)=>{
...@@ -323,10 +323,10 @@ export default class SkribblServer { ...@@ -323,10 +323,10 @@ export default class SkribblServer {
* @param {string} word * @param {string} word
*/ */
static _isClose(guess,word) { static _isClose(guess,word) {
guess = guess.toLowerCase(); guess = guess.toLowerCase().replace(/-/g," ");
word = word.toLowerCase(); word = word.toLowerCase().replace(/-/g," ");
word.replace(/-/g," "); const wordArray = Array.from(word);
guess.replace(/-/g," "); const guessArray = Array.from(guess);
//if equal //if equal
if (guess == word) { if (guess == word) {
...@@ -335,19 +335,9 @@ export default class SkribblServer { ...@@ -335,19 +335,9 @@ export default class SkribblServer {
//either one letter wrong or two letters swapped //either one letter wrong or two letters swapped
if (guess.length == word.length) { if (guess.length == word.length) {
let wordArray = [];
let guessArray = [];
//makes the string into an array
for (var i = 0; i < word.length; i++) {
wordArray[i] = word.charAt(i);
guessArray[i] = guess.charAt(i);
}
//Counts the mistakes and their position //Counts the mistakes and their position
let errorCounter = 0; let errorCounter = 0;
let errorPos = 0; let errorPos = 0;
for (var i = 0; i < wordArray.length; i++) { for (var i = 0; i < wordArray.length; i++) {
if (wordArray[i] != guessArray[i]) { if (wordArray[i] != guessArray[i]) {
if (errorCounter == 0) { if (errorCounter == 0) {
...@@ -363,24 +353,13 @@ export default class SkribblServer { ...@@ -363,24 +353,13 @@ export default class SkribblServer {
errorCounter++; errorCounter++;
} }
} }
//if it hasnt returned false by now, the guess is close //if it hasnt returned false by now, the guess is close
return true; return true;
} }
//if one letter too much //if one letter too much
if (guess.length - 1 == word.length) { if (guess.length - 1 == word.length) {
let wordArray = [];
let guessArray = [];
for (var i = 0; i < word.length; i++) {
wordArray[i] = word.charAt(i);
guessArray[i] = guess.charAt(i);
}
guessArray[guessArray.length] = guess.charAt(guessArray.length);
let errorCounter = 0; //also the offset let errorCounter = 0; //also the offset
for (var i = 0; i < wordArray.length; i++) { for (var i = 0; i < wordArray.length; i++) {
if (wordArray[i] != guessArray[i + errorCounter]) { if (wordArray[i] != guessArray[i + errorCounter]) {
errorCounter++; errorCounter++;
...@@ -389,23 +368,12 @@ export default class SkribblServer { ...@@ -389,23 +368,12 @@ export default class SkribblServer {
} }
} }
} }
return true; return true;
} }
//if one letter too little //if one letter too little
if (guess.length + 1 == word.length) { if (guess.length + 1 == word.length) {
let wordArray = [];
let guessArray = [];
for (var i = 0; i < guess.length; i++) {
wordArray[i] = word.charAt(i);
guessArray[i] = guess.charAt(i);
}
wordArray[wordArray.length] = word.charAt(wordArray.length);
let errorCounter = 0; //also the offset let errorCounter = 0; //also the offset
for (var i = 0; i < guessArray.length; i++) { for (var i = 0; i < guessArray.length; i++) {
if (wordArray[i + errorCounter] != guessArray[i]) { if (wordArray[i + errorCounter] != guessArray[i]) {
errorCounter++; errorCounter++;
...@@ -414,7 +382,6 @@ export default class SkribblServer { ...@@ -414,7 +382,6 @@ export default class SkribblServer {
} }
} }
} }
return true; return true;
} }
...@@ -427,15 +394,8 @@ export default class SkribblServer { ...@@ -427,15 +394,8 @@ export default class SkribblServer {
* @param {string} word * @param {string} word
*/ */
static _isCorrect(guess, word) { static _isCorrect(guess, word) {
guess = guess.toLowerCase(); guess = guess.toLowerCase().replace(/-/g," ");
word = word.toLowerCase(); word = word.toLowerCase().replace(/-/g," ");
word.replace(/-/g," "); return guess==word;
guess.replace(/-/g," ");
if (guess == word) {
return true;
} else {
return true;
}
} }
} }
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment