Game.java
+ Finished method switchPlayer and almost finished + Added datafield playerPlaying and gameFinished + Added JavaDoc comments
This commit is contained in:
parent
1860f01b25
commit
962e61fa63
|
@ -1,3 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Klasse: Game
|
||||||
|
*
|
||||||
|
* Diese Klasse beinhaltet die Logik für das Spiel.
|
||||||
|
*
|
||||||
|
* Klasse Language und Gamefield wird im Konstruktor initialisiert
|
||||||
|
*/
|
||||||
public class Game {
|
public class Game {
|
||||||
|
|
||||||
private Gamefield gamefield;
|
private Gamefield gamefield;
|
||||||
|
@ -5,14 +12,29 @@ public class Game {
|
||||||
|
|
||||||
private int player1 = 1;
|
private int player1 = 1;
|
||||||
private int player2 = 2;
|
private int player2 = 2;
|
||||||
|
private int playerPlaying = 1;
|
||||||
|
|
||||||
|
private boolean gameFinished = false;
|
||||||
|
|
||||||
public Game() {
|
public Game() {
|
||||||
gamefield = new Gamefield();
|
gamefield = new Gamefield();
|
||||||
language = new Language("de");
|
language = new Language("de");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Methode: placeField
|
||||||
|
*
|
||||||
|
* Spieler setzt sein Symbol in das gewünschte Feld.
|
||||||
|
* Die Methode überprüft auch, ob der Spieler gewonnen hat.
|
||||||
|
* Wenn der Spieler gewonnen hat, dann wird
|
||||||
|
*
|
||||||
|
* @param field vom Spieler markiertes Feld
|
||||||
|
*/
|
||||||
public void placeField(int field) {
|
public void placeField(int field) {
|
||||||
|
if (gameFinished) {
|
||||||
|
// Fehler aufrufen, dass das Spiel zuende ist.
|
||||||
|
}
|
||||||
|
|
||||||
if (field > 9 || field < 1) {
|
if (field > 9 || field < 1) {
|
||||||
// Fehler aufrufen von Klasse Sprache
|
// Fehler aufrufen von Klasse Sprache
|
||||||
return;
|
return;
|
||||||
|
@ -20,14 +42,23 @@ public class Game {
|
||||||
|
|
||||||
gamefield.setField(field, player1);
|
gamefield.setField(field, player1);
|
||||||
|
|
||||||
|
// Hier überprüfen, ob der Spieler gewonnen hat
|
||||||
|
|
||||||
switchPlayer();
|
switchPlayer();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Methode: switchPlayer
|
||||||
|
*
|
||||||
|
* Diese Methode wechselt den Spieler. Dieser wird von
|
||||||
|
* Methode placeField aufgerufen
|
||||||
|
*/
|
||||||
public void switchPlayer() {
|
public void switchPlayer() {
|
||||||
|
if (playerPlaying == 1) {
|
||||||
|
playerPlaying = player2;
|
||||||
|
} else {
|
||||||
|
playerPlaying = player1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeLanguage(String language) {
|
public void changeLanguage(String language) {
|
||||||
|
|
Loading…
Reference in New Issue