diff options
| author | Marco de Wild <mdwild@sogyo.nl> | 2021-01-14 14:32:49 +0100 |
|---|---|---|
| committer | Marco de Wild <mdwild@sogyo.nl> | 2021-01-19 15:11:08 +0100 |
| commit | a15537ec310d8fe6ba458971caa3ec31fe80412e (patch) | |
| tree | f258be6b145b3f09de344ec4b969fb233cd51930 | |
| parent | 6f89051b1f3d2ff2e6e4e4a574276cc06ecedbb7 (diff) | |
Added files for interfacing with the domain
| -rw-r--r-- | domain/src/main/java/mancala/domain/Mancala.java | 55 | ||||
| -rw-r--r-- | domain/src/main/java/mancala/domain/MancalaException.java | 7 | ||||
| -rw-r--r-- | domain/src/main/java/mancala/domain/MancalaImpl.java | 34 |
3 files changed, 96 insertions, 0 deletions
diff --git a/domain/src/main/java/mancala/domain/Mancala.java b/domain/src/main/java/mancala/domain/Mancala.java new file mode 100644 index 0000000..b8b8b7b --- /dev/null +++ b/domain/src/main/java/mancala/domain/Mancala.java @@ -0,0 +1,55 @@ +package mancala.domain; + +public interface Mancala { + public static final int NO_PLAYERS = 0; + public static final int PLAYER_ONE = 1; + public static final int PLAYER_TWO = 1; + public static final int BOTH_PLAYERS = 3; + + /** + * Method indicating if the first player has the next turn or not. + * If player 1 is not in turn, then player 2 is in turn. + * @param The player which you want to know the turn for. + * @return True if the first player has the next turn, false if it's the turn of the other player. + */ + boolean isPlayersTurn(int player); + + /** + * Method for playing the specified recess. Index is as specified below: + * + * 12 11 10 9 8 7 + * 13 6 + * 0 1 2 3 4 5 + * + * @param index Index of the recess to be played. + * @return 15 item long Array with the current state of the game. The 15th item indicates which player has the next turn (possible values are 1 or 2). + */ + void playPit(int index) throws MancalaException; + + /** + * Method for returning the amount of stones in de specified pit. Index is as specified below: + * + * 12 11 10 9 8 7 + * 13 6 + * 0 1 2 3 4 5 + * + * @param index Index of the pit. + * @return Amount of stone. + */ + int getStonesForPit(int index); + + /** + * Method for retrieving whether the game has ended or not. + * + * @return True is the game has ended otherwise False. + */ + boolean isEndOfGame(); + + /** + * Method for retrieving the player that has won the game. + * + * @return Integer value representing which player(s) (if any) won the game. + */ + int getWinner(); + +}
\ No newline at end of file diff --git a/domain/src/main/java/mancala/domain/MancalaException.java b/domain/src/main/java/mancala/domain/MancalaException.java new file mode 100644 index 0000000..783b229 --- /dev/null +++ b/domain/src/main/java/mancala/domain/MancalaException.java @@ -0,0 +1,7 @@ +package mancala.domain; + +public class MancalaException extends Exception { + public MancalaException(String message) { + super(message); + } +}
\ No newline at end of file diff --git a/domain/src/main/java/mancala/domain/MancalaImpl.java b/domain/src/main/java/mancala/domain/MancalaImpl.java new file mode 100644 index 0000000..de04c8f --- /dev/null +++ b/domain/src/main/java/mancala/domain/MancalaImpl.java @@ -0,0 +1,34 @@ +package mancala.domain; + +public class MancalaImpl implements Mancala { + public MancalaImpl() { + // Initialize the game here. + } + + @Override + public boolean isPlayersTurn(int player) { + return true; + } + + @Override + public void playPit(int index) throws MancalaException { + // Implement playing a pit. + } + + @Override + public int getStonesForPit(int index) { + // Make a sane implementation. + if((index + 1 % 7) == 0) return 0; + return 4; + } + + @Override + public boolean isEndOfGame() { + return false; + } + + @Override + public int getWinner() { + return Mancala.NO_PLAYERS; + } +}
\ No newline at end of file |
