added classes for PlayerSatetes
This commit is contained in:
parent
4a8b342577
commit
f98d860b97
BIN
bin/cards/maumau/model/FinishedState.class
Normal file
BIN
bin/cards/maumau/model/FinishedState.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/cards/maumau/model/PlayerState.class
Normal file
BIN
bin/cards/maumau/model/PlayerState.class
Normal file
Binary file not shown.
BIN
bin/cards/maumau/model/WaitForMauMauState.class
Normal file
BIN
bin/cards/maumau/model/WaitForMauMauState.class
Normal file
Binary file not shown.
BIN
bin/cards/maumau/model/WaitForMauState.class
Normal file
BIN
bin/cards/maumau/model/WaitForMauState.class
Normal file
Binary file not shown.
BIN
bin/cards/maumau/model/WaitForNextTurnState.class
Normal file
BIN
bin/cards/maumau/model/WaitForNextTurnState.class
Normal file
Binary file not shown.
18
src/cards/maumau/model/FinishedState.java
Normal file
18
src/cards/maumau/model/FinishedState.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package cards.maumau.model;
|
||||||
|
|
||||||
|
public class FinishedState implements PlayerState {
|
||||||
|
@Override
|
||||||
|
public void nextTurn(int n) {
|
||||||
|
// Do nothing, the game is finished
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mau(Player p) {
|
||||||
|
// Do nothing, the game is finished
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void maumau(Player p) {
|
||||||
|
// Do nothing, the game is finished
|
||||||
|
}
|
||||||
|
}
|
@ -4,103 +4,94 @@ import java.util.ArrayList;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
public class PlayerHandler {
|
||||||
* Handles players in a MauMau game.
|
|
||||||
*/
|
|
||||||
class PlayerHandler {
|
|
||||||
private final MauMau game;
|
private final MauMau game;
|
||||||
private final List<Player> players = new LinkedList<>();
|
private final List<Player> players = new LinkedList<>();
|
||||||
private final List<Player> ranking = new ArrayList<>();
|
private final List<Player> ranking = new ArrayList<>();
|
||||||
private Player remember;
|
private Player remember;
|
||||||
|
|
||||||
/**
|
private PlayerState waitForNextTurnState;
|
||||||
* Constructs a PlayerHandler for the specified MauMau game.
|
private PlayerState waitForMauState;
|
||||||
*
|
private PlayerState waitForMauMauState;
|
||||||
* @param game The MauMau game instance.
|
private PlayerState finishedState;
|
||||||
*/
|
|
||||||
PlayerHandler(MauMau game) {
|
private PlayerState currentState;
|
||||||
|
|
||||||
|
public PlayerHandler(MauMau game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
this.waitForNextTurnState = new WaitForNextTurnState(this);
|
||||||
|
this.waitForMauState = new WaitForMauState(this);
|
||||||
|
this.waitForMauMauState = new WaitForMauMauState(this);
|
||||||
|
this.finishedState = new FinishedState();
|
||||||
|
|
||||||
|
this.currentState = waitForNextTurnState;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void nextTurn(int n) {
|
||||||
* Initiates the next turn in the game.
|
currentState.nextTurn(n);
|
||||||
*
|
|
||||||
* @param n The number of turns to proceed.
|
|
||||||
*/
|
|
||||||
void nextTurn(int n) {
|
|
||||||
//TODO implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void mau(Player p) {
|
||||||
* Handles a player calling "Mau".
|
currentState.mau(p);
|
||||||
*
|
|
||||||
* @param p The player calling "Mau".
|
|
||||||
*/
|
|
||||||
void mau(Player p) {
|
|
||||||
//TODO implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void maumau(Player p) {
|
||||||
* Handles a player calling "Mau-Mau".
|
currentState.maumau(p);
|
||||||
*
|
|
||||||
* @param p The player calling "Mau-Mau".
|
|
||||||
*/
|
|
||||||
void maumau(Player p) {
|
|
||||||
//TODO implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public List<Player> getPlayers() {
|
||||||
* Returns the list of players participating in the game.
|
|
||||||
*
|
|
||||||
* @return The list of players.
|
|
||||||
*/
|
|
||||||
List<Player> getPlayers() {
|
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public List<Player> getRanking() {
|
||||||
* Returns the ranking of players based on the order they finished the game.
|
|
||||||
*
|
|
||||||
* @return The ranking of players.
|
|
||||||
*/
|
|
||||||
List<Player> getRanking() {
|
|
||||||
return ranking;
|
return ranking;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void addPlayer(Player player) {
|
||||||
* Adds a player to the game.
|
// Add player logic
|
||||||
*
|
|
||||||
* @param player The player to add.
|
|
||||||
* @throws IllegalArgumentException if a player with the same name already exists.
|
|
||||||
*/
|
|
||||||
void addPlayer(Player player) {
|
|
||||||
//TODO implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void localNextTurn(int n) {
|
||||||
* Moves to the next player's turn in the game.
|
// Local next turn logic
|
||||||
*
|
|
||||||
* @param n The number of turns to proceed.
|
|
||||||
*/
|
|
||||||
private void localNextTurn(int n) {
|
|
||||||
//TODO implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void finishPlayer(Player p) {
|
||||||
* Finishes a player's participation in the game.
|
// Finish player logic
|
||||||
*
|
|
||||||
* @param p The player to finish.
|
|
||||||
*/
|
|
||||||
private void finishPlayer(Player p) {
|
|
||||||
//TODO implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Player getCurrentPlayer() {
|
||||||
* Returns the current player whose turn it is.
|
return players.isEmpty() ? null : players.get(0);
|
||||||
*
|
}
|
||||||
* @return The current player.
|
|
||||||
*/
|
public void setRemember(Player player) {
|
||||||
Player getCurrentPlayer() {
|
this.remember = player;
|
||||||
return players.isEmpty() ? null : players.getFirst();
|
}
|
||||||
|
|
||||||
|
public Player getRemember() {
|
||||||
|
return remember;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerState getWaitForNextTurnState() {
|
||||||
|
return waitForNextTurnState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerState getWaitForMauState() {
|
||||||
|
return waitForMauState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerState getWaitForMauMauState() {
|
||||||
|
return waitForMauMauState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerState getFinishedState() {
|
||||||
|
return finishedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentState(PlayerState state) {
|
||||||
|
this.currentState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finishGame() {
|
||||||
|
// Finish game logic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
src/cards/maumau/model/PlayerState.java
Normal file
7
src/cards/maumau/model/PlayerState.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package cards.maumau.model;
|
||||||
|
|
||||||
|
public interface PlayerState {
|
||||||
|
void nextTurn(int n);
|
||||||
|
void mau(Player p);
|
||||||
|
void maumau(Player p);
|
||||||
|
}
|
35
src/cards/maumau/model/WaitForMauMauState.java
Normal file
35
src/cards/maumau/model/WaitForMauMauState.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package cards.maumau.model;
|
||||||
|
|
||||||
|
public class WaitForMauMauState implements PlayerState {
|
||||||
|
private final PlayerHandler handler;
|
||||||
|
|
||||||
|
public WaitForMauMauState(PlayerHandler handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void nextTurn(int n) {
|
||||||
|
// Draw a card and proceed to next turn
|
||||||
|
handler.getCurrentPlayer().drawCards(1);
|
||||||
|
handler.localNextTurn(n);
|
||||||
|
handler.setCurrentState(handler.getWaitForNextTurnState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mau(Player p) {
|
||||||
|
// Do nothing or handle invalid state transition
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void maumau(Player p) {
|
||||||
|
if (p == handler.getRemember()) {
|
||||||
|
handler.finishPlayer(p);
|
||||||
|
if (handler.getPlayers().size() == 1) {
|
||||||
|
handler.finishGame();
|
||||||
|
handler.setCurrentState(handler.getFinishedState());
|
||||||
|
} else {
|
||||||
|
handler.setCurrentState(handler.getWaitForNextTurnState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
src/cards/maumau/model/WaitForMauState.java
Normal file
29
src/cards/maumau/model/WaitForMauState.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package cards.maumau.model;
|
||||||
|
|
||||||
|
public class WaitForMauState implements PlayerState {
|
||||||
|
private final PlayerHandler handler;
|
||||||
|
|
||||||
|
public WaitForMauState(PlayerHandler handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void nextTurn(int n) {
|
||||||
|
// Draw a card and proceed to next turn
|
||||||
|
handler.getCurrentPlayer().drawCards(1);
|
||||||
|
handler.localNextTurn(n);
|
||||||
|
handler.setCurrentState(handler.getWaitForNextTurnState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mau(Player p) {
|
||||||
|
if (p == handler.getRemember()) {
|
||||||
|
handler.setCurrentState(handler.getWaitForMauMauState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void maumau(Player p) {
|
||||||
|
// Do nothing or handle invalid state transition
|
||||||
|
}
|
||||||
|
}
|
32
src/cards/maumau/model/WaitForNextTurnState.java
Normal file
32
src/cards/maumau/model/WaitForNextTurnState.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package cards.maumau.model;
|
||||||
|
|
||||||
|
public class WaitForNextTurnState implements PlayerState {
|
||||||
|
private final PlayerHandler handler;
|
||||||
|
|
||||||
|
public WaitForNextTurnState(PlayerHandler handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void nextTurn(int n) {
|
||||||
|
// Logic for next turn
|
||||||
|
if (handler.getCurrentPlayer().getCards().isEmpty()) {
|
||||||
|
handler.setRemember(handler.getCurrentPlayer());
|
||||||
|
handler.localNextTurn(n);
|
||||||
|
handler.setCurrentState(handler.getWaitForMauMauState());
|
||||||
|
} else {
|
||||||
|
handler.localNextTurn(n);
|
||||||
|
handler.setCurrentState(handler.getWaitForMauState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mau(Player p) {
|
||||||
|
// Do nothing or handle invalid state transition
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void maumau(Player p) {
|
||||||
|
// Do nothing or handle invalid state transition
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user