Compare commits
10 Commits
49d958652a
...
main
Author | SHA1 | Date | |
---|---|---|---|
316339d733 | |||
e58808bbbc | |||
094c17d16a | |||
4b574c50e8 | |||
2638ca09b6 | |||
ad3ec29962 | |||
0f91dc2a13 | |||
bd81bd07ad | |||
87bc479f12 | |||
1178730173 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/cards/maumau/model/Canceled.class
Normal file
BIN
bin/cards/maumau/model/Canceled.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/cards/maumau/model/Finished.class
Normal file
BIN
bin/cards/maumau/model/Finished.class
Normal file
Binary file not shown.
BIN
bin/cards/maumau/model/GameState.class
Normal file
BIN
bin/cards/maumau/model/GameState.class
Normal file
Binary file not shown.
BIN
bin/cards/maumau/model/HandlerState.class
Normal file
BIN
bin/cards/maumau/model/HandlerState.class
Normal file
Binary file not shown.
BIN
bin/cards/maumau/model/Initialized.class
Normal file
BIN
bin/cards/maumau/model/Initialized.class
Normal file
Binary file not shown.
BIN
bin/cards/maumau/model/JackChosen.class
Normal file
BIN
bin/cards/maumau/model/JackChosen.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/cards/maumau/model/Normal.class
Normal file
BIN
bin/cards/maumau/model/Normal.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/cards/maumau/model/SevenChosen.class
Normal file
BIN
bin/cards/maumau/model/SevenChosen.class
Normal file
Binary file not shown.
BIN
bin/cards/maumau/model/SuitChosen.class
Normal file
BIN
bin/cards/maumau/model/SuitChosen.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/test/cards/CardTest.class
Normal file
BIN
bin/test/cards/CardTest.class
Normal file
Binary file not shown.
BIN
bin/test/cards/RankTest.class
Normal file
BIN
bin/test/cards/RankTest.class
Normal file
Binary file not shown.
BIN
bin/test/cards/SuitTest.class
Normal file
BIN
bin/test/cards/SuitTest.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/MauMauDeckTest.class
Normal file
BIN
bin/test/cards/maumau/MauMauDeckTest.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/model/CardHandlerTest.class
Normal file
BIN
bin/test/cards/maumau/model/CardHandlerTest.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/model/MauMau1Test.class
Normal file
BIN
bin/test/cards/maumau/model/MauMau1Test.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/model/MauMau2Test.class
Normal file
BIN
bin/test/cards/maumau/model/MauMau2Test.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/model/MauMau3Test.class
Normal file
BIN
bin/test/cards/maumau/model/MauMau3Test.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/model/MauMau4Test.class
Normal file
BIN
bin/test/cards/maumau/model/MauMau4Test.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/model/MauMau5Test.class
Normal file
BIN
bin/test/cards/maumau/model/MauMau5Test.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/model/MauMau6Test.class
Normal file
BIN
bin/test/cards/maumau/model/MauMau6Test.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/model/MauMau7Test.class
Normal file
BIN
bin/test/cards/maumau/model/MauMau7Test.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/model/MauMau8Test.class
Normal file
BIN
bin/test/cards/maumau/model/MauMau8Test.class
Normal file
Binary file not shown.
BIN
bin/test/cards/maumau/model/MauMau9Test.class
Normal file
BIN
bin/test/cards/maumau/model/MauMau9Test.class
Normal file
Binary file not shown.
BIN
lib/junit-platform-console-standalone-1.11.0-M2.jar
Normal file
BIN
lib/junit-platform-console-standalone-1.11.0-M2.jar
Normal file
Binary file not shown.
@@ -30,16 +30,16 @@ public enum Suit {
|
||||
public String toString() {
|
||||
switch (this) {
|
||||
case HEARTS:
|
||||
return "♥";
|
||||
return "♥︎";
|
||||
|
||||
case DIAMONDS:
|
||||
return "♦";
|
||||
return "♦︎";
|
||||
|
||||
case CLUBS:
|
||||
return "♣";
|
||||
return "♣︎";
|
||||
|
||||
case SPADES:
|
||||
return "♠";
|
||||
return "♠︎";
|
||||
|
||||
default:
|
||||
return "";
|
||||
|
@@ -1,18 +1,20 @@
|
||||
package cards.maumau.model;
|
||||
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.gamestate.*;
|
||||
|
||||
/**
|
||||
* Manages the actions and state transitions within a MauMau game.
|
||||
*/
|
||||
class ActionHandler {
|
||||
public class ActionHandler {
|
||||
private final MauMau game;
|
||||
private Suit chosenSuit;
|
||||
private int ctr7 = 0;
|
||||
|
||||
private GameState gameState;
|
||||
private GameState gameState = GameState.GAME_INITIALIZED;
|
||||
private HandlerState handlerState = new Initialized(this);
|
||||
|
||||
/**
|
||||
* Constructs an ActionHandler for the specified MauMau game.
|
||||
@@ -21,7 +23,18 @@ class ActionHandler {
|
||||
*/
|
||||
ActionHandler(MauMau game) {
|
||||
this.game = game;
|
||||
gameState = new Initialized();
|
||||
}
|
||||
|
||||
void setGameState(GameState gameState) {
|
||||
this.gameState = gameState;
|
||||
}
|
||||
|
||||
void setHandlerState (HandlerState handlerState) {
|
||||
this.handlerState = handlerState;
|
||||
}
|
||||
|
||||
public HandlerState getHandlerState() {
|
||||
return handlerState;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,28 +43,30 @@ class ActionHandler {
|
||||
* @param player The player to be added to the game.
|
||||
*/
|
||||
void addPlayer(Player player) {
|
||||
//TODO implement
|
||||
handlerState.addPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the game.
|
||||
*/
|
||||
void startGame() {
|
||||
//TODO implement
|
||||
handlerState.startGame();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transitions the game state to GAME_OVER.
|
||||
*/
|
||||
void finishGame() {
|
||||
//TODO implement
|
||||
// handlerState.finishGame();
|
||||
gameState = GameState.GAME_OVER;
|
||||
handlerState = new Finished(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transitions the game state to GAME_CANCELED.
|
||||
*/
|
||||
void cancelGame() {
|
||||
//TODO implement
|
||||
handlerState.cancelGame();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +75,7 @@ class ActionHandler {
|
||||
* @param c The card chosen by the player.
|
||||
*/
|
||||
void chooseCard(Card c) {
|
||||
//TODO implement
|
||||
handlerState.chooseCard(c);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,21 +84,21 @@ class ActionHandler {
|
||||
* @param suit The suit chosen by the player.
|
||||
*/
|
||||
void chooseSuit(Suit suit) {
|
||||
//TODO implement
|
||||
handlerState.chooseSuit(suit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets the player skip a round.
|
||||
**/
|
||||
void skip() {
|
||||
//TODO implement
|
||||
handlerState.skip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the player saying "no 7" in the current state.
|
||||
*/
|
||||
void no7() {
|
||||
//TODO implement
|
||||
handlerState.no7();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,8 +155,7 @@ class ActionHandler {
|
||||
* Returns the current state of the game.
|
||||
*/
|
||||
GameState getGameState() {
|
||||
//TODO implement
|
||||
return null;
|
||||
return gameState;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,8 +164,27 @@ class ActionHandler {
|
||||
* @param c The card being played.
|
||||
* @return True if the card can be played, false otherwise.
|
||||
*/
|
||||
boolean canPlay(Card c) {
|
||||
//TODO implement
|
||||
return false;
|
||||
public boolean canPlay(Card c) {
|
||||
if (ctr7 == 0 || c.rank() == Rank.SEVEN) {
|
||||
|
||||
if (chosenSuit == null) {
|
||||
if (c.rank() == Rank.JACK) {
|
||||
return true;
|
||||
} else if (c.rank() == game.getCardHandler().getDiscardPile().getFirst().rank()) {
|
||||
return true;
|
||||
} else if (c.suit() == game.getCardHandler().getDiscardPile().getFirst().suit()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (c.suit() == chosenSuit) {
|
||||
return true;
|
||||
}
|
||||
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
21
src/cards/maumau/model/Canceled.java
Normal file
21
src/cards/maumau/model/Canceled.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Suit;
|
||||
|
||||
public class Canceled implements HandlerState {
|
||||
|
||||
private final ActionHandler handler;
|
||||
|
||||
Canceled(ActionHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void addPlayer(Player player){}
|
||||
public void startGame(){}
|
||||
public void cancelGame(){}
|
||||
public void chooseCard(Card c){}
|
||||
public void chooseSuit(Suit suit){}
|
||||
public void skip(){}
|
||||
public void no7(){}
|
||||
}
|
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
/**
|
||||
* Manages the draw pile and discard pile in a MauMau game.
|
||||
*/
|
||||
class CardHandler {
|
||||
public class CardHandler {
|
||||
private final MauMau game;
|
||||
private final int numCardsPerPlayer;
|
||||
private final List<Card> drawPile = new LinkedList<>();
|
||||
@@ -73,7 +73,7 @@ class CardHandler {
|
||||
* Deals cards to all players.
|
||||
* @throws Exception when there are not enough cards to satisfy starting conditions
|
||||
*/
|
||||
void dealCards() throws Exception {
|
||||
public void dealCards() throws Exception {
|
||||
|
||||
// get List of players
|
||||
List<Player> players = game.getPlayers();
|
||||
@@ -119,7 +119,7 @@ class CardHandler {
|
||||
*
|
||||
* @return The top card of the discard pile.
|
||||
*/
|
||||
Card top() {
|
||||
public Card top() {
|
||||
return discardPile.getFirst();
|
||||
}
|
||||
}
|
||||
|
20
src/cards/maumau/model/Finished.java
Normal file
20
src/cards/maumau/model/Finished.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Suit;
|
||||
|
||||
public class Finished implements HandlerState{
|
||||
private final ActionHandler handler;
|
||||
|
||||
Finished(ActionHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void addPlayer(Player player){}
|
||||
public void startGame(){}
|
||||
public void cancelGame(){}
|
||||
public void chooseCard(Card c){}
|
||||
public void chooseSuit(Suit suit){}
|
||||
public void skip(){}
|
||||
public void no7(){}
|
||||
}
|
29
src/cards/maumau/model/GameState.java
Normal file
29
src/cards/maumau/model/GameState.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package cards.maumau.model;
|
||||
|
||||
/**
|
||||
* Represents the state of the Mau-Mau game.
|
||||
*/
|
||||
public enum GameState {
|
||||
/**
|
||||
* The game has been initialized, but has not yet started.
|
||||
*/
|
||||
GAME_INITIALIZED,
|
||||
/**
|
||||
* The game is over. The final ranking of players can be
|
||||
* obtained using {@link MauMau#getRanking()}.
|
||||
*/
|
||||
GAME_OVER,
|
||||
/**
|
||||
* The game has been canceled due to insufficient cards.
|
||||
*/
|
||||
GAME_CANCELED,
|
||||
/**
|
||||
* The game is currently in progress with players taking turns.
|
||||
*/
|
||||
PLAY,
|
||||
/**
|
||||
* The game is in progress and the current player has played
|
||||
* a Jack, and is required to choose a suit.
|
||||
*/
|
||||
CHOOSE_SUIT
|
||||
}
|
16
src/cards/maumau/model/HandlerState.java
Normal file
16
src/cards/maumau/model/HandlerState.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Suit;
|
||||
|
||||
public interface HandlerState {
|
||||
|
||||
void addPlayer(Player player);
|
||||
void startGame();
|
||||
void cancelGame();
|
||||
void chooseCard(Card c);
|
||||
void chooseSuit(Suit suit);
|
||||
void skip();
|
||||
void no7();
|
||||
|
||||
}
|
36
src/cards/maumau/model/Initialized.java
Normal file
36
src/cards/maumau/model/Initialized.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Suit;
|
||||
|
||||
public class Initialized implements HandlerState {
|
||||
|
||||
private final ActionHandler handler;
|
||||
|
||||
Initialized(ActionHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
handler.getGame().getPlayerHandler().addPlayer(player);
|
||||
}
|
||||
|
||||
|
||||
public void startGame() {
|
||||
try {
|
||||
handler.getGame().getCardHandler().dealCards();
|
||||
handler.setGameState(GameState.PLAY);
|
||||
handler.setHandlerState(new Normal(handler));
|
||||
} catch (Exception e) {
|
||||
System.err.println("Not enough Cards!");
|
||||
handler.setGameState(GameState.GAME_CANCELED);
|
||||
handler.setHandlerState(new Canceled(handler));
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelGame(){}
|
||||
public void chooseCard(Card c){}
|
||||
public void chooseSuit(Suit suit){}
|
||||
public void skip(){}
|
||||
public void no7(){}
|
||||
}
|
28
src/cards/maumau/model/JackChosen.java
Normal file
28
src/cards/maumau/model/JackChosen.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Suit;
|
||||
|
||||
public class JackChosen implements HandlerState{
|
||||
private final ActionHandler handler;
|
||||
|
||||
JackChosen(ActionHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void chooseSuit(Suit suit){
|
||||
handler.setChosenSuit(suit);
|
||||
handler.getGame().getPlayerHandler().nextTurn(1);
|
||||
handler.setGameState(GameState.PLAY);
|
||||
handler.setHandlerState(new SuitChosen(handler));
|
||||
}
|
||||
|
||||
public void startGame(){}
|
||||
public void addPlayer(Player player){}
|
||||
public void cancelGame(){}
|
||||
public void chooseCard(Card c){}
|
||||
public void skip(){}
|
||||
public void no7(){}
|
||||
}
|
@@ -2,7 +2,6 @@ package cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.gamestate.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -61,7 +60,7 @@ public class MauMau {
|
||||
*
|
||||
* @return The player handler.
|
||||
*/
|
||||
PlayerHandler getPlayerHandler() {
|
||||
public PlayerHandler getPlayerHandler() {
|
||||
return playerHandler;
|
||||
}
|
||||
|
||||
@@ -70,7 +69,7 @@ public class MauMau {
|
||||
*
|
||||
* @return The card handler.
|
||||
*/
|
||||
CardHandler getCardHandler() {
|
||||
public CardHandler getCardHandler() {
|
||||
return cardHandler;
|
||||
}
|
||||
|
||||
@@ -79,7 +78,7 @@ public class MauMau {
|
||||
*
|
||||
* @return The action handler.
|
||||
*/
|
||||
ActionHandler getActionHandler() {
|
||||
public ActionHandler getActionHandler() {
|
||||
return actionHandler;
|
||||
}
|
||||
|
||||
|
42
src/cards/maumau/model/Normal.java
Normal file
42
src/cards/maumau/model/Normal.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
|
||||
public class Normal implements HandlerState {
|
||||
private final ActionHandler handler;
|
||||
|
||||
Normal(ActionHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void addPlayer(Player player){}
|
||||
public void startGame(){}
|
||||
public void cancelGame(){}
|
||||
|
||||
public void chooseCard(Card c){
|
||||
if (handler.canPlay(c)) {
|
||||
handler.getGame().getPlayerHandler().getCurrentPlayer().playCard(c);
|
||||
if (c.rank() == Rank.SEVEN) {
|
||||
handler.increment7Counter();
|
||||
handler.getGame().getPlayerHandler().nextTurn(1);
|
||||
handler.setHandlerState(new SevenChosen(handler));
|
||||
} else if (c.rank() == Rank.JACK) {
|
||||
handler.setGameState(GameState.CHOOSE_SUIT);
|
||||
handler.setHandlerState(new JackChosen(handler));
|
||||
} else if (c.rank() == Rank.EIGHT) {
|
||||
handler.getGame().getPlayerHandler().nextTurn(2);
|
||||
} else {
|
||||
handler.getGame().getPlayerHandler().nextTurn(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void chooseSuit(Suit suit){}
|
||||
public void skip(){
|
||||
handler.getGame().getPlayerHandler().getCurrentPlayer().drawCards(1);
|
||||
handler.getGame().getPlayerHandler().nextTurn(1);
|
||||
}
|
||||
public void no7(){}
|
||||
}
|
@@ -56,12 +56,13 @@ public class PlayerHandler {
|
||||
|
||||
public void localNextTurn(int n) {
|
||||
for(int i = 0; i < n; i++){
|
||||
players.addLast(players.getFirst());
|
||||
players.addLast(players.removeFirst());
|
||||
// players.removeFirst();
|
||||
}
|
||||
}
|
||||
|
||||
public void finishPlayer(Player p) {
|
||||
ranking.addLast(players.removeFirst());
|
||||
ranking.addLast(players.removeLast());
|
||||
}
|
||||
|
||||
public Player getCurrentPlayer() {
|
||||
@@ -97,6 +98,6 @@ public class PlayerHandler {
|
||||
}
|
||||
|
||||
public void finishGame() {
|
||||
finishPlayer(players.getFirst());
|
||||
game.getActionHandler().finishGame();
|
||||
}
|
||||
}
|
||||
|
39
src/cards/maumau/model/SevenChosen.java
Normal file
39
src/cards/maumau/model/SevenChosen.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Suit;
|
||||
|
||||
public class SevenChosen implements HandlerState{
|
||||
private final ActionHandler handler;
|
||||
|
||||
SevenChosen(ActionHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void addPlayer(Player player){}
|
||||
public void startGame(){}
|
||||
public void cancelGame(){}
|
||||
|
||||
public void chooseCard(Card c){
|
||||
if (handler.canPlay(c)) {
|
||||
handler.getGame().getPlayerHandler().getCurrentPlayer().playCard(c);
|
||||
handler.increment7Counter();
|
||||
handler.getGame().getPlayerHandler().nextTurn(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void chooseSuit(Suit suit){}
|
||||
public void skip(){}
|
||||
|
||||
public void no7(){
|
||||
if (handler.get7Counter() * 2 > handler.getGame().getCardHandler().getDrawPile().size()) {
|
||||
handler.setGameState(GameState.GAME_CANCELED);
|
||||
handler.setHandlerState(new Canceled(handler));
|
||||
} else {
|
||||
handler.getGame().getPlayerHandler().getCurrentPlayer().drawCards(2 * handler.get7Counter());
|
||||
handler.reset7Counter();
|
||||
handler.setHandlerState(new Normal(handler));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
46
src/cards/maumau/model/SuitChosen.java
Normal file
46
src/cards/maumau/model/SuitChosen.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Suit;
|
||||
import cards.Rank;
|
||||
|
||||
public class SuitChosen implements HandlerState{
|
||||
private final ActionHandler handler;
|
||||
|
||||
SuitChosen(ActionHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void addPlayer(Player player){}
|
||||
public void startGame(){}
|
||||
public void cancelGame(){}
|
||||
|
||||
public void chooseCard(Card c){
|
||||
if (handler.canPlay(c)) {
|
||||
handler.setChosenSuit(null);
|
||||
handler.getGame().getPlayerHandler().getCurrentPlayer().playCard(c);
|
||||
|
||||
if(c.rank() == Rank.SEVEN) {
|
||||
handler.increment7Counter();
|
||||
handler.getGame().getPlayerHandler().nextTurn(1);
|
||||
handler.setHandlerState(new SevenChosen(handler));
|
||||
} else if (c.rank() == Rank.EIGHT) {
|
||||
handler.getGame().getPlayerHandler().nextTurn(2);
|
||||
handler.setHandlerState(new Normal(handler));
|
||||
} else {
|
||||
handler.getGame().getPlayerHandler().nextTurn(1);
|
||||
handler.setHandlerState(new Normal(handler));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void chooseSuit(Suit suit){}
|
||||
|
||||
public void skip(){
|
||||
handler.getGame().getPlayerHandler().getCurrentPlayer().drawCards(1);
|
||||
handler.getGame().getPlayerHandler().nextTurn(1);
|
||||
}
|
||||
|
||||
public void no7(){}
|
||||
}
|
@@ -10,9 +10,19 @@ public class WaitForMauMauState implements PlayerState {
|
||||
@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());
|
||||
handler.getRemember().drawCards(1);
|
||||
if (handler.getCurrentPlayer().getCards().isEmpty()) {
|
||||
handler.setRemember(handler.getCurrentPlayer());
|
||||
handler.localNextTurn(n);
|
||||
handler.setCurrentState(handler.getWaitForMauMauState());
|
||||
} else if (handler.getCurrentPlayer().getCards().size() == 1) {
|
||||
handler.setRemember(handler.getCurrentPlayer());
|
||||
handler.localNextTurn(n);
|
||||
handler.setCurrentState(handler.getWaitForMauState());
|
||||
} else {
|
||||
handler.localNextTurn(n);
|
||||
handler.setCurrentState(handler.getWaitForNextTurnState());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -23,13 +33,20 @@ public class WaitForMauMauState implements PlayerState {
|
||||
@Override
|
||||
public void maumau(Player p) {
|
||||
if (p == handler.getRemember()) {
|
||||
|
||||
|
||||
handler.finishPlayer(p);
|
||||
|
||||
|
||||
if (handler.getPlayers().size() == 1) {
|
||||
handler.finishPlayer(handler.getCurrentPlayer());
|
||||
handler.finishGame();
|
||||
handler.setCurrentState(handler.getFinishedState());
|
||||
} else {
|
||||
handler.setCurrentState(handler.getWaitForNextTurnState());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,15 +10,25 @@ public class WaitForMauState implements PlayerState {
|
||||
@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());
|
||||
handler.getRemember().drawCards(1);
|
||||
if (handler.getCurrentPlayer().getCards().isEmpty()) {
|
||||
handler.setRemember(handler.getCurrentPlayer());
|
||||
handler.localNextTurn(n);
|
||||
handler.setCurrentState(handler.getWaitForMauMauState());
|
||||
} else if (handler.getCurrentPlayer().getCards().size() == 1) {
|
||||
handler.setRemember(handler.getCurrentPlayer());
|
||||
handler.localNextTurn(n);
|
||||
handler.setCurrentState(handler.getWaitForMauState());
|
||||
} else {
|
||||
handler.localNextTurn(n);
|
||||
handler.setCurrentState(handler.getWaitForNextTurnState());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mau(Player p) {
|
||||
if (p == handler.getRemember()) {
|
||||
handler.setCurrentState(handler.getWaitForMauMauState());
|
||||
handler.setCurrentState(handler.getWaitForNextTurnState());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -14,9 +14,13 @@ public class WaitForNextTurnState implements PlayerState {
|
||||
handler.setRemember(handler.getCurrentPlayer());
|
||||
handler.localNextTurn(n);
|
||||
handler.setCurrentState(handler.getWaitForMauMauState());
|
||||
} else {
|
||||
} else if (handler.getCurrentPlayer().getCards().size() == 1) {
|
||||
handler.setRemember(handler.getCurrentPlayer());
|
||||
handler.localNextTurn(n);
|
||||
handler.setCurrentState(handler.getWaitForMauState());
|
||||
} else {
|
||||
handler.localNextTurn(n);
|
||||
handler.setCurrentState(handler.getWaitForNextTurnState());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +0,0 @@
|
||||
package cards.maumau.model.gamestate;
|
||||
|
||||
public class Canceled implements GameState{
|
||||
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
package cards.maumau.model.gamestate;
|
||||
|
||||
public class Finished implements GameState{
|
||||
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
package cards.maumau.model.gamestate;
|
||||
|
||||
public interface GameState {
|
||||
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
package cards.maumau.model.gamestate;
|
||||
|
||||
|
||||
public class Initialized implements GameState {
|
||||
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
package cards.maumau.model.gamestate;
|
||||
|
||||
public class JackChosen implements GameState{
|
||||
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
package cards.maumau.model.gamestate;
|
||||
|
||||
public class Normal implements GameState{
|
||||
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
package cards.maumau.model.gamestate;
|
||||
|
||||
public class SevenChosen implements GameState{
|
||||
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
package cards.maumau.model.gamestate;
|
||||
|
||||
public class SuitChosen implements GameState{
|
||||
|
||||
}
|
@@ -1,7 +1,11 @@
|
||||
package cards;
|
||||
package test.cards;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
|
||||
import static cards.Rank.THREE;
|
||||
import static cards.Rank.TWO;
|
||||
import static cards.Suit.HEARTS;
|
@@ -1,4 +1,4 @@
|
||||
package cards;
|
||||
package test.cards;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package cards;
|
||||
package test.cards;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package cards.maumau;
|
||||
package test.cards.maumau;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.MauMauDeck;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
@@ -1,8 +1,11 @@
|
||||
package cards.maumau.model;
|
||||
package test.cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.MauMau;
|
||||
import cards.maumau.model.Player;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
@@ -35,7 +38,12 @@ public class CardHandlerTest {
|
||||
final Player chantal = game.addPlayer("Chantal");
|
||||
assertTrue(jacqueline.getCards().isEmpty());
|
||||
assertTrue(chantal.getCards().isEmpty());
|
||||
game.getCardHandler().dealCards();
|
||||
try {
|
||||
game.getCardHandler().dealCards();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
assertEquals("[J♦︎, Q♦︎, A♠︎, A♦︎, 8♦︎]", jacqueline.getCards().toString());
|
||||
assertEquals("[7♣︎, 9♣︎, 9♠︎, 8♣︎, K♥︎]", chantal.getCards().toString());
|
||||
assertEquals(c(ACE, HEARTS), game.getCardHandler().top());
|
@@ -1,8 +1,13 @@
|
||||
package cards.maumau.model;
|
||||
package test.cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.MauMau;
|
||||
import cards.maumau.model.Normal;
|
||||
import cards.maumau.model.Player;
|
||||
import cards.maumau.model.SevenChosen;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
@@ -147,8 +152,10 @@ public class MauMau1Test {
|
||||
assertNull(game.getChosenSuit());
|
||||
assertEquals(0, game.get7Counter());
|
||||
|
||||
assertEquals(Normal.class, game.getActionHandler().getHandlerState().getClass());
|
||||
chantal.skip();
|
||||
assertEquals(PLAY, game.getGameState());
|
||||
assertEquals(Normal.class, game.getActionHandler().getHandlerState().getClass());
|
||||
assertEquals(List.of(jacqueline, chantal), game.getPlayers());
|
||||
assertEquals(List.of(), game.getRanking());
|
||||
assertEquals("[A♦︎]", jacqueline.getCards().toString());
|
@@ -1,8 +1,11 @@
|
||||
package cards.maumau.model;
|
||||
package test.cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.MauMau;
|
||||
import cards.maumau.model.Normal;
|
||||
import cards.maumau.model.Player;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
@@ -24,6 +27,7 @@ import static cards.maumau.model.GameState.GAME_OVER;
|
||||
import static cards.maumau.model.GameState.PLAY;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MauMau2Test {
|
||||
private static Card c(Rank r, Suit s) {
|
||||
@@ -184,17 +188,22 @@ public class MauMau2Test {
|
||||
assertEquals(List.of(jacqueline, chantal), game.getPlayers());
|
||||
assertEquals(List.of(), game.getRanking());
|
||||
assertEquals("[Q♠︎, Q♣︎]", jacqueline.getCards().toString());
|
||||
// assertEquals("[Q♣︎]", jacqueline.getCards().toString());
|
||||
assertEquals("[8♥︎]", chantal.getCards().toString());
|
||||
assertEquals("[9♥︎, K♣︎, 7♣︎, J♦︎, 9♦︎, A♣︎, 8♠︎, 10♦︎, J♠︎, J♥︎, J♣︎, 10♥︎, K♥︎, Q♥︎, 7♥︎, 7♦︎, 8♣︎, 9♣︎, 9♠︎]", game.getDrawPile().toString());
|
||||
assertEquals("[Q♦︎, K♦︎, 8♦︎, A♦︎, A♥︎, A♠︎, K♠︎, 7♠︎, 10♠︎, 10♣︎]", game.getDiscardPile().toString());
|
||||
assertNull(game.getChosenSuit());
|
||||
assertEquals(0, game.get7Counter());
|
||||
// assertEquals("[Q♣︎]", jacqueline.getCards().toString());
|
||||
|
||||
// assertEquals(Normal.class, game.getActionHandler().getHandlerState().getClass());
|
||||
assertTrue(game.getActionHandler().canPlay(c(QUEEN, SPADES)));
|
||||
jacqueline.chooseCard(c(QUEEN, SPADES));
|
||||
assertEquals(PLAY, game.getGameState());
|
||||
assertEquals(List.of(chantal, jacqueline), game.getPlayers());
|
||||
assertEquals(List.of(), game.getRanking());
|
||||
assertEquals("[8♥︎]", chantal.getCards().toString());
|
||||
// assertEquals(Normal.class, game.getActionHandler().getHandlerState().getClass());
|
||||
assertEquals("[Q♣︎]", jacqueline.getCards().toString());
|
||||
assertEquals("[9♥︎, K♣︎, 7♣︎, J♦︎, 9♦︎, A♣︎, 8♠︎, 10♦︎, J♠︎, J♥︎, J♣︎, 10♥︎, K♥︎, Q♥︎, 7♥︎, 7♦︎, 8♣︎, 9♣︎, 9♠︎]", game.getDrawPile().toString());
|
||||
assertEquals("[Q♠︎, Q♦︎, K♦︎, 8♦︎, A♦︎, A♥︎, A♠︎, K♠︎, 7♠︎, 10♠︎, 10♣︎]", game.getDiscardPile().toString());
|
@@ -1,8 +1,10 @@
|
||||
package cards.maumau.model;
|
||||
package test.cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.MauMau;
|
||||
import cards.maumau.model.Player;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
@@ -1,8 +1,10 @@
|
||||
package cards.maumau.model;
|
||||
package test.cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.MauMau;
|
||||
import cards.maumau.model.Player;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
@@ -24,7 +26,9 @@ import static cards.maumau.model.GameState.GAME_INITIALIZED;
|
||||
import static cards.maumau.model.GameState.GAME_OVER;
|
||||
import static cards.maumau.model.GameState.PLAY;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MauMau4Test {
|
||||
private static Card c(Rank r, Suit s) {
|
||||
@@ -126,6 +130,7 @@ public class MauMau4Test {
|
||||
assertEquals(0, game.get7Counter());
|
||||
|
||||
chantal.chooseCard(c(JACK, SPADES));
|
||||
assertFalse(game.getActionHandler().canPlay(c(JACK, SPADES)));
|
||||
assertEquals(PLAY, game.getGameState());
|
||||
assertEquals(List.of(chantal, jacqueline), game.getPlayers());
|
||||
assertEquals(List.of(), game.getRanking());
|
@@ -1,8 +1,10 @@
|
||||
package cards.maumau.model;
|
||||
package test.cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.MauMau;
|
||||
import cards.maumau.model.Player;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
@@ -1,8 +1,10 @@
|
||||
package cards.maumau.model;
|
||||
package test.cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.MauMau;
|
||||
import cards.maumau.model.Player;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
@@ -1,8 +1,10 @@
|
||||
package cards.maumau.model;
|
||||
package test.cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.MauMau;
|
||||
import cards.maumau.model.Player;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
@@ -1,8 +1,10 @@
|
||||
package cards.maumau.model;
|
||||
package test.cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.MauMau;
|
||||
import cards.maumau.model.Player;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
@@ -1,8 +1,10 @@
|
||||
package cards.maumau.model;
|
||||
package test.cards.maumau.model;
|
||||
|
||||
import cards.Card;
|
||||
import cards.Rank;
|
||||
import cards.Suit;
|
||||
import cards.maumau.model.MauMau;
|
||||
import cards.maumau.model.Player;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
Reference in New Issue
Block a user