method checkForWin implemented

This commit is contained in:
Leonardo Brandenberger 2021-10-07 22:18:34 +02:00
parent 8d9eac4a40
commit 96a94aa12d
1 changed files with 27 additions and 0 deletions

View File

@ -64,4 +64,31 @@ public class Game {
public void changeLanguage(String language) { public void changeLanguage(String language) {
this.language.setOutputLanguage(language); this.language.setOutputLanguage(language);
} }
public boolean checkForWin() {
if((gamefield.getField(1) == gamefield.getField(2)) && (gamefield.getField(3) == gamefield.getField(1))){
return true;
}
else if((gamefield.getField(4) == gamefield.getField(5)) && (gamefield.getField(6) == gamefield.getField(4))){
return true;
}
else if((gamefield.getField(7) == gamefield.getField(8)) && (gamefield.getField(9) == gamefield.getField(7))){
return true;
}
else if((gamefield.getField(1) == gamefield.getField(4)) && (gamefield.getField(7) == gamefield.getField(1))){
return true;
}
else if((gamefield.getField(2) == gamefield.getField(5)) && (gamefield.getField(8) == gamefield.getField(2))){
return true;
}
else if((gamefield.getField(3) == gamefield.getField(6)) && (gamefield.getField(9) == gamefield.getField(3))){
return true;
}
else if((gamefield.getField(1) == gamefield.getField(5)) && (gamefield.getField(9) == gamefield.getField(1))){
return true;
}
else if((gamefield.getField(3) == gamefield.getField(5)) && (gamefield.getField(7) == gamefield.getField(3))){
return true;
}
return false;
}
} }