Compare commits
2 Commits
49d958652a
...
87bc479f12
Author | SHA1 | Date | |
---|---|---|---|
87bc479f12 | |||
1178730173 |
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.
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/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.
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.
@ -2,7 +2,6 @@ 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.
|
||||||
@ -21,7 +20,7 @@ class ActionHandler {
|
|||||||
*/
|
*/
|
||||||
ActionHandler(MauMau game) {
|
ActionHandler(MauMau game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
gameState = new Initialized();
|
gameState = new Initialized(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,28 +29,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) {
|
||||||
//TODO implement
|
gameState.addPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the game.
|
* Starts the game.
|
||||||
*/
|
*/
|
||||||
void startGame() {
|
void startGame() {
|
||||||
//TODO implement
|
gameState.startGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transitions the game state to GAME_OVER.
|
* Transitions the game state to GAME_OVER.
|
||||||
*/
|
*/
|
||||||
void finishGame() {
|
void finishGame() {
|
||||||
//TODO implement
|
gameState.finishGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transitions the game state to GAME_CANCELED.
|
* Transitions the game state to GAME_CANCELED.
|
||||||
*/
|
*/
|
||||||
void cancelGame() {
|
void cancelGame() {
|
||||||
//TODO implement
|
gameState.cancelGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,7 +59,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) {
|
||||||
//TODO implement
|
gameState.chooseCard(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,21 +68,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) {
|
||||||
//TODO implement
|
gameState.chooseSuit(suit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lets the player skip a round.
|
* Lets the player skip a round.
|
||||||
**/
|
**/
|
||||||
void skip() {
|
void skip() {
|
||||||
//TODO implement
|
gameState.skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the player saying "no 7" in the current state.
|
* Handles the player saying "no 7" in the current state.
|
||||||
*/
|
*/
|
||||||
void no7() {
|
void no7() {
|
||||||
//TODO implement
|
gameState.no7();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,8 +139,11 @@ class ActionHandler {
|
|||||||
* Returns the current state of the game.
|
* Returns the current state of the game.
|
||||||
*/
|
*/
|
||||||
GameState getGameState() {
|
GameState getGameState() {
|
||||||
//TODO implement
|
return gameState;
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
void setGameState(GameState gameState) {
|
||||||
|
this.gameState = gameState;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
10
src/cards/maumau/model/Canceled.java
Normal file
10
src/cards/maumau/model/Canceled.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package cards.maumau.model;
|
||||||
|
|
||||||
|
public class Canceled implements GameState{
|
||||||
|
|
||||||
|
private final ActionHandler handler;
|
||||||
|
|
||||||
|
Canceled(ActionHandler handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
}
|
9
src/cards/maumau/model/Finished.java
Normal file
9
src/cards/maumau/model/Finished.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package cards.maumau.model;
|
||||||
|
|
||||||
|
public class Finished implements GameState{
|
||||||
|
private final ActionHandler handler;
|
||||||
|
|
||||||
|
Finished(ActionHandler handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
}
|
17
src/cards/maumau/model/GameState.java
Normal file
17
src/cards/maumau/model/GameState.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
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);
|
||||||
|
}
|
34
src/cards/maumau/model/Initialized.java
Normal file
34
src/cards/maumau/model/Initialized.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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(){}
|
||||||
|
}
|
27
src/cards/maumau/model/JackChosen.java
Normal file
27
src/cards/maumau/model/JackChosen.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
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(){}
|
||||||
|
}
|
@ -2,7 +2,6 @@ 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;
|
||||||
@ -61,7 +60,7 @@ public class MauMau {
|
|||||||
*
|
*
|
||||||
* @return The player handler.
|
* @return The player handler.
|
||||||
*/
|
*/
|
||||||
PlayerHandler getPlayerHandler() {
|
public PlayerHandler getPlayerHandler() {
|
||||||
return playerHandler;
|
return playerHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ public class MauMau {
|
|||||||
*
|
*
|
||||||
* @return The card handler.
|
* @return The card handler.
|
||||||
*/
|
*/
|
||||||
CardHandler getCardHandler() {
|
public CardHandler getCardHandler() {
|
||||||
return cardHandler;
|
return cardHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
src/cards/maumau/model/Normal.java
Normal file
9
src/cards/maumau/model/Normal.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package cards.maumau.model;
|
||||||
|
|
||||||
|
public class Normal implements GameState{
|
||||||
|
private final ActionHandler handler;
|
||||||
|
|
||||||
|
Normal(ActionHandler handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
}
|
9
src/cards/maumau/model/SevenChosen.java
Normal file
9
src/cards/maumau/model/SevenChosen.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package cards.maumau.model;
|
||||||
|
|
||||||
|
public class SevenChosen implements GameState{
|
||||||
|
private final ActionHandler handler;
|
||||||
|
|
||||||
|
SevenChosen(ActionHandler handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
}
|
47
src/cards/maumau/model/SuitChosen.java
Normal file
47
src/cards/maumau/model/SuitChosen.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
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(){}
|
||||||
|
}
|
@ -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{
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user