added init for mdga with all states and messages
This commit is contained in:
45
Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java
Normal file
45
Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class will be used to hold all Board relevant data.
|
||||
*/
|
||||
public class Board {
|
||||
private Map<Color, Player> playerData;
|
||||
private Node[] infield;
|
||||
|
||||
/**
|
||||
* This constructor is used to create a new board
|
||||
*/
|
||||
public Board() {
|
||||
infield = new Node[40];
|
||||
for (int i = 0; i < 40; i++) {
|
||||
if (i % 10 == 0) {
|
||||
infield[i] = new StartNode();
|
||||
} else if (i == 4 || i == 14 || i == 24 || i == 34) {
|
||||
infield[i] = new BonusNode();
|
||||
} else {
|
||||
infield[i] = new Node();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the playerData
|
||||
*
|
||||
* @return the playerData
|
||||
*/
|
||||
public Map<Color, Player> getPlayerData() {
|
||||
return playerData;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the infield
|
||||
*
|
||||
* @return the infield
|
||||
*/
|
||||
public Node[] getInfield() {
|
||||
return infield;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
public enum BonusCard {
|
||||
HIDDERN,
|
||||
SHIELD,
|
||||
TURBO,
|
||||
SWAP
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
public class BonusNode extends Node {
|
||||
|
||||
public BonusNode() {}
|
||||
|
||||
/**
|
||||
* This method is used to set a new Occupant
|
||||
*
|
||||
* @param occupant the new occupant of the node
|
||||
*/
|
||||
@Override
|
||||
public void setOccupant(Piece occupant) {
|
||||
if (occupant.isSuppressed()){
|
||||
occupant.setShield(ShieldState.NONE);
|
||||
}
|
||||
//Draw Card Event
|
||||
this.occupant = occupant;
|
||||
}
|
||||
}
|
||||
34
Projekte/mdga/model/src/main/java/pp.mdga/game/Card.java
Normal file
34
Projekte/mdga/model/src/main/java/pp.mdga/game/Card.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package pp.mdga.game;
|
||||
/**
|
||||
* This class is used to create a card
|
||||
*/
|
||||
public class Card {
|
||||
private BonusCard type;
|
||||
|
||||
/**
|
||||
* This constructor is used to create a new card
|
||||
*
|
||||
* @param type the type of the card
|
||||
*/
|
||||
public Card(BonusCard type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get the type of the card
|
||||
*
|
||||
* @return the type of the card
|
||||
*/
|
||||
public BonusCard getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to set the type of the card
|
||||
*
|
||||
* @param type the new type of the card
|
||||
*/
|
||||
public void setType(BonusCard type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
public enum Color {
|
||||
ARMY,
|
||||
NAVY,
|
||||
CYBER,
|
||||
AIRFORCE
|
||||
|
||||
}
|
||||
37
Projekte/mdga/model/src/main/java/pp.mdga/game/Game.java
Normal file
37
Projekte/mdga/model/src/main/java/pp.mdga/game/Game.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class will be used to handle the data stored in the model
|
||||
*/
|
||||
public class Game {
|
||||
private int diceModifier = 1;
|
||||
private int diceEyes;
|
||||
private Map <Color, Player> players;
|
||||
private Statistic gameStatistics;
|
||||
private ArrayList<Card> drawPile;
|
||||
private ArrayList<Card> discardPile = new ArrayList<>();
|
||||
private Board board;
|
||||
private Color activeColor;
|
||||
private LinkedList<Color> order;
|
||||
private Map<Color, Integer> playerConnectionID;
|
||||
|
||||
private static final int AMOUNT_OF_TURBO_CARDS = 16;
|
||||
private static final int AMOUNT_OF_SHIELD_AND_SWAP_CARDS = 12;
|
||||
|
||||
public Game(){
|
||||
gameStatistics = new Statistic();
|
||||
drawPile = new ArrayList<>();
|
||||
for (int i = 0; i < AMOUNT_OF_TURBO_CARDS; i++) {
|
||||
drawPile.add(new Card(BonusCard.TURBO));
|
||||
}
|
||||
for (int i = 0; i < AMOUNT_OF_SHIELD_AND_SWAP_CARDS; i++) {
|
||||
drawPile.add(new Card(BonusCard.SHIELD));
|
||||
drawPile.add(new Card(BonusCard.SWAP));
|
||||
}
|
||||
board = new Board();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
public class HomeNode extends Node {
|
||||
|
||||
public HomeNode() {}
|
||||
}
|
||||
47
Projekte/mdga/model/src/main/java/pp.mdga/game/Node.java
Normal file
47
Projekte/mdga/model/src/main/java/pp.mdga/game/Node.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
/**
|
||||
* This class will be used the represent a Node on which the pieces can travel along
|
||||
*/
|
||||
public class Node {
|
||||
protected Piece occupant;
|
||||
|
||||
public Node() {}
|
||||
|
||||
/**
|
||||
* This method is used to get an occupant of the Node.
|
||||
*
|
||||
* @return the current occupant of the node
|
||||
*/
|
||||
public Piece getOccupant() {
|
||||
return occupant;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to set a new Occupant
|
||||
*
|
||||
* @param occupant the new occupant of the node
|
||||
*/
|
||||
public void setOccupant(Piece occupant) {
|
||||
if (occupant.isSuppressed()){
|
||||
occupant.setShield(ShieldState.NONE);
|
||||
}
|
||||
this.occupant = occupant;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to clear the node of its occupant
|
||||
*/
|
||||
public void clearOccupant() {
|
||||
this.occupant = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to return a boolean value based on the occupation status
|
||||
*
|
||||
* @return the boolean value corresponding to the occupation status
|
||||
*/
|
||||
public boolean isOccupied() {
|
||||
return occupant != null;
|
||||
}
|
||||
}
|
||||
37
Projekte/mdga/model/src/main/java/pp.mdga/game/Piece.java
Normal file
37
Projekte/mdga/model/src/main/java/pp.mdga/game/Piece.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
public class Piece {
|
||||
private ShieldState shield;
|
||||
private PieceState state;
|
||||
private Color color;
|
||||
|
||||
public Piece(Color color, PieceState state) {
|
||||
this.color = color;
|
||||
this.state = state;
|
||||
shield = ShieldState.NONE;
|
||||
}
|
||||
|
||||
public void setShield(ShieldState shield) {
|
||||
this.shield = shield;
|
||||
}
|
||||
|
||||
public ShieldState getShield() {
|
||||
return shield;
|
||||
}
|
||||
|
||||
public void setState(PieceState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public PieceState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public boolean isShielded() {
|
||||
return shield == ShieldState.ACTIVE;
|
||||
}
|
||||
|
||||
public boolean isSuppressed() {
|
||||
return shield == ShieldState.SUPPRESSED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
public enum PieceState {
|
||||
ACTIVE,
|
||||
WAITING,
|
||||
HOME,
|
||||
HOMEFINISHED
|
||||
}
|
||||
82
Projekte/mdga/model/src/main/java/pp.mdga/game/Player.java
Normal file
82
Projekte/mdga/model/src/main/java/pp.mdga/game/Player.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* This class will be used to handle general PlayerData
|
||||
*/
|
||||
public class Player {
|
||||
|
||||
private String name;
|
||||
private Statistic playerStatistic;
|
||||
private ArrayList<Card> handCards;
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* This constructor constructs a new Player object
|
||||
*/
|
||||
public Player(int id) {
|
||||
this.id = id;
|
||||
playerStatistic = new Statistic();
|
||||
handCards = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the give name of the Player
|
||||
*
|
||||
* @return the name of the player as a String
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the name of the player
|
||||
*
|
||||
* @param name the new name of the player
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* This methode returns the statistics of the player
|
||||
*
|
||||
* @return the statistics of the player
|
||||
*/
|
||||
public Statistic getPlayerStatistic() {
|
||||
return playerStatistic;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the current handCards of the player
|
||||
*
|
||||
* @return the handCards of the player
|
||||
*/
|
||||
public ArrayList<Card> getHandCards() {
|
||||
return handCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds a new handCard to the player
|
||||
*
|
||||
* @param cards the card to be added to the players hand
|
||||
*/
|
||||
public void addHandCards(Card cards){
|
||||
handCards.add(cards);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a BonusCard to be removed from the players hand.
|
||||
*
|
||||
* @param card the cards type to be removed
|
||||
* @return the removed card or null if there is none of that card type
|
||||
*/
|
||||
public Card removeHandCard(Card card) {
|
||||
Card cardToRemove = handCards.stream().filter(card1 -> card1.getType().equals(card.getType())).findFirst().orElse(null);
|
||||
if (cardToRemove != null) {
|
||||
handCards.remove(cardToRemove);
|
||||
}
|
||||
return cardToRemove;
|
||||
}
|
||||
}
|
||||
101
Projekte/mdga/model/src/main/java/pp.mdga/game/PlayerData.java
Normal file
101
Projekte/mdga/model/src/main/java/pp.mdga/game/PlayerData.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
/**
|
||||
* This class is used to represent PlayerData related to the board
|
||||
*/
|
||||
public class PlayerData {
|
||||
private HomeNode[] homeNodes;
|
||||
private int startNodeIndex;
|
||||
private Piece[] waitingArea;
|
||||
private Piece[] pieces;
|
||||
|
||||
/**
|
||||
* This constructor is used to create a new PlayerData object
|
||||
*
|
||||
* @param color the color of the player
|
||||
*/
|
||||
public PlayerData(Color color) {
|
||||
homeNodes = new HomeNode[4];
|
||||
waitingArea = new Piece[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
homeNodes[i] = new HomeNode();
|
||||
pieces[i] = new Piece(color, PieceState.WAITING);
|
||||
waitingArea[i] = pieces[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an Array of HomeNodes
|
||||
*
|
||||
* @return the array of HomeNodes
|
||||
*/
|
||||
public Node[] getHomeNodes() {
|
||||
return homeNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the index of the StartNode
|
||||
*
|
||||
* @return the index of the StartNode
|
||||
*/
|
||||
public int getStartNodeIndex() {
|
||||
return startNodeIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the index of the startNode.
|
||||
*
|
||||
* @param startNodeIndex the integer index of the startNode
|
||||
*/
|
||||
public void setStartNodeIndex(int startNodeIndex) {
|
||||
this.startNodeIndex = startNodeIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an array pieces representing the waiting area.
|
||||
*
|
||||
* @return the waiting area
|
||||
*/
|
||||
public Piece[] getWaitingArea() {
|
||||
return waitingArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an array of pieces with all the players pieces
|
||||
*
|
||||
* @return the array of pieces
|
||||
*/
|
||||
public Piece[] getPieces() {
|
||||
return pieces;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds a piece to the waiting area
|
||||
*
|
||||
* @param piece the piece to be added to the waiting area
|
||||
*/
|
||||
public void addWaitingPiece(Piece piece) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (waitingArea[i] == null) {
|
||||
waitingArea[i] = piece;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method removes a piece from the waiting area
|
||||
*
|
||||
* @return the piece that was removed from the waiting area
|
||||
*/
|
||||
public Piece removePieceFromWaitingArea() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (waitingArea[i] != null) {
|
||||
Piece piece = waitingArea[i];
|
||||
waitingArea[i] = null;
|
||||
return piece;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
public enum ShieldState {
|
||||
NONE,
|
||||
ACTIVE,
|
||||
SUPPRESSED
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
public class StartNode extends Node {
|
||||
|
||||
public StartNode() {}
|
||||
|
||||
/**
|
||||
* This method is used to set a new Occupant
|
||||
*
|
||||
* @param occupant the new occupant of the node
|
||||
*/
|
||||
@Override
|
||||
public void setOccupant(Piece occupant) {
|
||||
if (occupant.isShielded()){
|
||||
occupant.setShield(ShieldState.SUPPRESSED);
|
||||
}
|
||||
this.occupant = occupant;
|
||||
}
|
||||
}
|
||||
172
Projekte/mdga/model/src/main/java/pp.mdga/game/Statistic.java
Normal file
172
Projekte/mdga/model/src/main/java/pp.mdga/game/Statistic.java
Normal file
@@ -0,0 +1,172 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
/**
|
||||
* This class will be used to store Statistics during the Game;
|
||||
*/
|
||||
public class Statistic {
|
||||
private int cardsPlayed;
|
||||
private int piecesThrown;
|
||||
private int piecesBeingThrown;
|
||||
private int diced6;
|
||||
private int traveledNodes;
|
||||
private int activatedBonusNodes;
|
||||
|
||||
public Statistic() {
|
||||
cardsPlayed = 0;
|
||||
piecesThrown = 0;
|
||||
piecesBeingThrown = 0;
|
||||
diced6 = 0;
|
||||
traveledNodes = 0;
|
||||
activatedBonusNodes = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the amount of CardsPlayed;
|
||||
*
|
||||
* @return the amount of cardsPlayed as an int
|
||||
*/
|
||||
public int getCardsPlayed() {
|
||||
return cardsPlayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the amounts of cardsPlayed
|
||||
*
|
||||
* @param cardsPlayed the new amount of cardsPlayed.
|
||||
*/
|
||||
public void setCardsPlayed(int cardsPlayed) {
|
||||
this.cardsPlayed = cardsPlayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the count of enemyPieces Thrown during the game.
|
||||
*
|
||||
* @return the count of enemyPieces thrown
|
||||
*/
|
||||
public int getPiecesThrown() {
|
||||
return piecesThrown;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the new count of enemyPieces Thrown
|
||||
*
|
||||
* @param piecesThrown the new count of pieces thrown.
|
||||
*/
|
||||
public void setPiecesThrown(int piecesThrown) {
|
||||
this.piecesThrown = piecesThrown;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the count of ownPieces Being thrown.
|
||||
*
|
||||
* @return the count of thrown own pieces
|
||||
*/
|
||||
public int getPiecesBeingThrown() {
|
||||
return piecesBeingThrown;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the new count of own pieces thrown.
|
||||
*
|
||||
* @param piecesBeingThrown the new count of thrown own pieces.
|
||||
*/
|
||||
public void setPiecesBeingThrown(int piecesBeingThrown) {
|
||||
this.piecesBeingThrown = piecesBeingThrown;
|
||||
}
|
||||
|
||||
/**
|
||||
* This methode returns the amount of 6s diced during the game.
|
||||
*
|
||||
* @return the amount of 6s diced
|
||||
*/
|
||||
public int getDiced6() {
|
||||
return diced6;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the new amount of 6s diced
|
||||
*
|
||||
* @param diced6 the new amount of 6s diced
|
||||
*/
|
||||
public void setDiced6(int diced6) {
|
||||
this.diced6 = diced6;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the amount of traveled Nodes
|
||||
*
|
||||
* @return the amount of traveled Nodes as int
|
||||
*/
|
||||
public int getTraveledNodes() {
|
||||
return traveledNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the new amount of traveled Nodes.
|
||||
*
|
||||
* @param traveledNodes the new amount of traveled Nodes
|
||||
*/
|
||||
public void setTraveledNodes(int traveledNodes) {
|
||||
this.traveledNodes = traveledNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the amount of activated BonusNodes.
|
||||
*
|
||||
* @return the amount of activated BonusNodes as int
|
||||
*/
|
||||
public int getActivatedBonusNodes() {
|
||||
return activatedBonusNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the new amount of activated BonusNodes
|
||||
*
|
||||
* @param activatedBonusNodes the new amount of activated BonusNodes
|
||||
*/
|
||||
public void setActivatedBonusNodes(int activatedBonusNodes) {
|
||||
this.activatedBonusNodes = activatedBonusNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method increases the value of cardsPlayed by 1.
|
||||
*/
|
||||
public void increaseCardsPlayed() {
|
||||
cardsPlayed++;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method increases the value of cardsPlayed by 1.
|
||||
*/
|
||||
public void increasePiecesThrown() {
|
||||
piecesThrown++;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method increases the value of cardsPlayed by 1.
|
||||
*/
|
||||
public void increasePiecesBeingThrown() {
|
||||
piecesBeingThrown++;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method increases the value of cardsPlayed by 1.
|
||||
*/
|
||||
public void increaseDiced6() {
|
||||
diced6++;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method increases the value of cardsPlayed by 1.
|
||||
*/
|
||||
public void increaseTraveledNodes() {
|
||||
traveledNodes++;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method increases the value of cardsPlayed by 1.
|
||||
*/
|
||||
public void increaseActivatedBonusNodes() {
|
||||
activatedBonusNodes++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user