Compare commits

..

No commits in common. "87bc479f12af22ce342a71281a20e70e065e5444" and "49d958652a91c06ea1dc5298cd81b2a18410d2cd" have entirely different histories.

38 changed files with 56 additions and 178 deletions

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.

View File

@ -2,6 +2,7 @@ package cards.maumau.model;
import cards.Card; import cards.Card;
import cards.Suit; import cards.Suit;
import cards.maumau.model.gamestate.*;
/** /**
* Manages the actions and state transitions within a MauMau game. * Manages the actions and state transitions within a MauMau game.
@ -20,7 +21,7 @@ class ActionHandler {
*/ */
ActionHandler(MauMau game) { ActionHandler(MauMau game) {
this.game = game; this.game = game;
gameState = new Initialized(this); gameState = new Initialized();
} }
/** /**
@ -29,28 +30,28 @@ class ActionHandler {
* @param player The player to be added to the game. * @param player The player to be added to the game.
*/ */
void addPlayer(Player player) { void addPlayer(Player player) {
gameState.addPlayer(player); //TODO implement
} }
/** /**
* Starts the game. * Starts the game.
*/ */
void startGame() { void startGame() {
gameState.startGame(); //TODO implement
} }
/** /**
* Transitions the game state to GAME_OVER. * Transitions the game state to GAME_OVER.
*/ */
void finishGame() { void finishGame() {
gameState.finishGame(); //TODO implement
} }
/** /**
* Transitions the game state to GAME_CANCELED. * Transitions the game state to GAME_CANCELED.
*/ */
void cancelGame() { void cancelGame() {
gameState.cancelGame(); //TODO implement
} }
/** /**
@ -59,7 +60,7 @@ class ActionHandler {
* @param c The card chosen by the player. * @param c The card chosen by the player.
*/ */
void chooseCard(Card c) { void chooseCard(Card c) {
gameState.chooseCard(c); //TODO implement
} }
/** /**
@ -68,21 +69,21 @@ class ActionHandler {
* @param suit The suit chosen by the player. * @param suit The suit chosen by the player.
*/ */
void chooseSuit(Suit suit) { void chooseSuit(Suit suit) {
gameState.chooseSuit(suit); //TODO implement
} }
/** /**
* Lets the player skip a round. * Lets the player skip a round.
**/ **/
void skip() { void skip() {
gameState.skip(); //TODO implement
} }
/** /**
* Handles the player saying "no 7" in the current state. * Handles the player saying "no 7" in the current state.
*/ */
void no7() { void no7() {
gameState.no7(); //TODO implement
} }
/** /**
@ -139,11 +140,8 @@ class ActionHandler {
* Returns the current state of the game. * Returns the current state of the game.
*/ */
GameState getGameState() { GameState getGameState() {
return gameState; //TODO implement
} return null;
void setGameState(GameState gameState) {
this.gameState = gameState;
} }
/** /**

View File

@ -1,10 +0,0 @@
package cards.maumau.model;
public class Canceled implements GameState{
private final ActionHandler handler;
Canceled(ActionHandler handler) {
this.handler = handler;
}
}

View File

@ -1,9 +0,0 @@
package cards.maumau.model;
public class Finished implements GameState{
private final ActionHandler handler;
Finished(ActionHandler handler) {
this.handler = handler;
}
}

View File

@ -1,17 +0,0 @@
package cards.maumau.model;
import cards.Card;
import cards.Suit;
interface GameState {
void addPlayer(Player player);
void startGame();
void finishGame();
void cancelGame();
void chooseCard(Card c);
void chooseSuit(Suit suit);
void skip();
void no7();
// boolean canPlay(Card c);
}

View File

@ -1,34 +0,0 @@
package cards.maumau.model;
import cards.Card;
import cards.Suit;
public class Initialized implements GameState {
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(new Normal(handler));
} catch (Exception e) {
handler.setGameState(new Canceled(handler));
}
}
public void finishGame(){}
public void cancelGame(){}
public void chooseCard(Card c){}
public void chooseSuit(Suit suit){}
public void skip(){}
public void no7(){}
}

View File

@ -1,27 +0,0 @@
package cards.maumau.model;
import cards.Card;
import cards.Suit;
public class JackChosen implements GameState{
private final ActionHandler handler;
JackChosen(ActionHandler handler) {
this.handler = handler;
}
public void chooseSuit(Suit suit){
handler.setChosenSuit(suit);
handler.setGameState(new SuitChosen(handler));
}
public void startGame(){}
public void addPlayer(Player player){}
public void finishGame(){}
public void cancelGame(){}
public void chooseCard(Card c){}
public void skip(){}
public void no7(){}
}

View File

@ -2,6 +2,7 @@ package cards.maumau.model;
import cards.Card; import cards.Card;
import cards.Suit; import cards.Suit;
import cards.maumau.model.gamestate.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -60,7 +61,7 @@ public class MauMau {
* *
* @return The player handler. * @return The player handler.
*/ */
public PlayerHandler getPlayerHandler() { PlayerHandler getPlayerHandler() {
return playerHandler; return playerHandler;
} }
@ -69,7 +70,7 @@ public class MauMau {
* *
* @return The card handler. * @return The card handler.
*/ */
public CardHandler getCardHandler() { CardHandler getCardHandler() {
return cardHandler; return cardHandler;
} }

View File

@ -1,9 +0,0 @@
package cards.maumau.model;
public class Normal implements GameState{
private final ActionHandler handler;
Normal(ActionHandler handler) {
this.handler = handler;
}
}

View File

@ -1,9 +0,0 @@
package cards.maumau.model;
public class SevenChosen implements GameState{
private final ActionHandler handler;
SevenChosen(ActionHandler handler) {
this.handler = handler;
}
}

View File

@ -1,47 +0,0 @@
package cards.maumau.model;
import cards.Card;
import cards.Suit;
import cards.Rank;
public class SuitChosen implements GameState{
private final ActionHandler handler;
SuitChosen(ActionHandler handler) {
this.handler = handler;
}
public void addPlayer(Player player){}
public void startGame(){}
public void finishGame(){}
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.setGameState(new SevenChosen(handler));
} else if (c.rank() == Rank.EIGHT) {
handler.getGame().getPlayerHandler().nextTurn(2);
handler.setGameState(new Normal(handler));
} else {
handler.getGame().getPlayerHandler().nextTurn(1);
handler.setGameState(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(){}
}

View File

@ -0,0 +1,5 @@
package cards.maumau.model.gamestate;
public class Canceled implements GameState{
}

View File

@ -0,0 +1,5 @@
package cards.maumau.model.gamestate;
public class Finished implements GameState{
}

View File

@ -0,0 +1,5 @@
package cards.maumau.model.gamestate;
public interface GameState {
}

View File

@ -0,0 +1,6 @@
package cards.maumau.model.gamestate;
public class Initialized implements GameState {
}

View File

@ -0,0 +1,5 @@
package cards.maumau.model.gamestate;
public class JackChosen implements GameState{
}

View File

@ -0,0 +1,5 @@
package cards.maumau.model.gamestate;
public class Normal implements GameState{
}

View File

@ -0,0 +1,5 @@
package cards.maumau.model.gamestate;
public class SevenChosen implements GameState{
}

View File

@ -0,0 +1,5 @@
package cards.maumau.model.gamestate;
public class SuitChosen implements GameState{
}