package Core;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* This class holds every information about the current state of the game
*/
public class Playboard {
/**
* Instance variables
*/
private Field[][] board;
private Set<Player> players = new HashSet<>();
private Set<Bomb> bombs = new HashSet<>();;
private int stepsLeft;
private int explosionRadius;
private int bombCounter;
private final Set<Integer> POSSIBLE_ACTIONS = new HashSet<>(Arrays.asList(new Integer[]{ 0, 1, 2, 3, 4, 5 }));
/**
* Constructor
* @param board The board of the game
* @param stepsLeft Steps that are left till the game is over
* @param explosionRadius Count of fields a bomb causes to explode in every direction
* @param bombCounter Maximum amout of iteration till the game ends in a draw
*/
public Playboard(Field[][] board, int stepsLeft, int explosionRadius, int bombCounter) {
this.explosionRadius = explosionRadius;
this.bombCounter = bombCounter;
this.board = board;
this.stepsLeft = stepsLeft;
}
/**
* Constructor for cloning
* @param playboard
*/
private Playboard(Playboard playboard) {
this.board = playboard.board.clone();
this.stepsLeft = playboard.stepsLeft;
for (Bomb bomb : playboard.bombs) {
this.bombs.add(bomb.clone());
}
for (Player player : playboard.players) {
this.players.add(player.clone());
}
}
/**
* Returns an exact copy of the object
*/
public Playboard clone() {
return new Playboard(this);
}
/******* Getter *******/
/**
* Returns the count of fields a bomb causes to explode in every direction
* @return
*/
public int getExplosionRadius() {
return explosionRadius;
}
/**
* Returns the maximum amout of iteration till the game ends in a draw
* @return bombCounter
*/
public int getBombCounter() {
return bombCounter;
}
/**
* Returns all action ids that a user can make
* @return POSSIBLE_ACTIONS
*/
public Set<Integer> getPossibleActions() {
return POSSIBLE_ACTIONS;
}
/**
* Returns the board of the game
* @return board
*/
public Field[][] getBoard() {
return board;
}
/**
* Returns all players currently in the game
* @return players
*/
public Set<Player> getPlayers() {
return players;
}
/**
* Returns alls bombs currenty on the playboard
* @return
*/
public Set<Bomb> getBombs() {
return bombs;
}
/**
* Returns the amount of steps that are left till the game is over
* @return stepsLeft
*/
public int getStepsLeft() {
return stepsLeft;
}
/******* Setter *******/
/**
* Sets the current players
* @param players
*/
public void setPlayers(Set<Player> players) {
this.players = players;
}
/**
* Sets the bombs currenty on the board
* @param bombs
*/
public void setBombs(Set<Bomb> bombs) {
this.bombs = bombs;
}
/******* Methods *******/
/**
* Decreases the steps left by one
*/
public void decreaseStepsLeft() {
stepsLeft--;
}
/**
* Adds a bomb to the playboard
* @param bombCounter Maximum amout of iteration till the game ends in a draw
* @param x x-coordinate
* @param y y-coordinate
* @param explosionRadius Count of fields a bomb causes to explode in every direction
* @param playerId Id of the player who planted the bomb
*/
public void addBomb(int bombCounter, int x, int y, int explosionRadius, int playerId) {
Field field = board[x][y];
field.setPassable(false);
Bomb newBomb = new Bomb(bombCounter, field, explosionRadius, playerId);
if (!bombs.contains(newBomb)) {
bombs.add(newBomb);
}
}
}
最近下载更多
adap12345 LV5
2023年6月8日
hkxyyz LV6
2023年3月2日
总有人间一两风 LV8
2022年12月12日
liangge2115 LV27
2022年11月7日
微信网友_6004879537377280 LV3
2022年6月22日
jytjyt LV1
2021年12月16日
ssssqweq LV1
2021年11月1日
此次东方 LV1
2021年10月20日
qliu0130 LV1
2021年10月10日
zpy123 LV1
2021年7月18日
最近浏览更多
chengjingjingjing
2025年6月19日
暂无贡献等级
微信网友_7556291372584960
2025年6月16日
暂无贡献等级
qqqww11 LV2
2024年6月26日
鬼屋报道 LV3
2024年6月4日
ClydeSon LV5
2023年12月27日
bangyiyang LV2
2023年12月21日
1112WHQ LV7
2023年11月3日
微信网友_6672184532766720 LV3
2023年10月6日
srrrrrr
2023年9月19日
暂无贡献等级
adap12345 LV5
2023年6月8日

