1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
package ch.epfl.xblast.server;
import ch.epfl.xblast.*;
import ch.epfl.xblast.server.painter.*;
import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
/**
* @author Timothée FLOURE (257420)
*/
public final class Level {
/** Players' initial parameters **/
private static final int PLAYER_INITIAL_LIVES = 5;
private static final int PLAYER_INITIAL_BOMB_MAXIMUM = 5;
private static final int PLAYER_INITIAL_BOMB_RANGE = 5;
/** Players' initial positions (Ugly!) **/
private static final Cell PLAYER_1_INITIAL_POSITION = new Cell(1,1);
private static final Cell PLAYER_2_INITIAL_POSITION = new Cell(16,1);
private static final Cell PLAYER_3_INITIAL_POSITION = new Cell(16,14);
private static final Cell PLAYER_4_INITIAL_POSITION = new Cell(1,14);
/** Level values **/
private final BoardPainter painter;
private final GameState initialState;
/**
* Build the default board of the game.
*
* @return the default board
*/
private static BoardPainter buildDefaultBoardPainter() {
// Create the blocks map
HashMap<Block,BlockImage> blocksMap = new HashMap<>();
// Fill the blocks map
blocksMap.put(Block.FREE, BlockImage.IRON_FLOOR);
blocksMap.put(Block.DESTRUCTIBLE_WALL, BlockImage.EXTRA);
blocksMap.put(Block.CRUMBLING_WALL, BlockImage.EXTRA_O);
blocksMap.put(Block.INDESTRUCTIBLE_WALL, BlockImage.DARK_BLOCK);
blocksMap.put(Block.BONUS_BOMB, BlockImage.BONUS_BOMB);
blocksMap.put(Block.BONUS_RANGE, BlockImage.BONUS_RANGE);
// Create and return the board painter
return new BoardPainter(blocksMap, BlockImage.IRON_FLOOR_S);
}
/**
* Build the default game state of the game.
*
* @return the default game state
*/
private static GameState buildDefaultGameState() {
return new GameState(buildDefaultBoard(), buildDefaultPlayers());
}
/**
* Build the default board of the game.
*
* @return the default board.
*/
private static Board buildDefaultBoard() {
// Ugly!
Block __ = Block.FREE;
Block XX = Block.INDESTRUCTIBLE_WALL;
Block xx = Block.DESTRUCTIBLE_WALL;
return Board.ofQuadrantNWBlocksWalled(
Arrays.asList(
Arrays.asList(__, __, __, __, __, xx, __),
Arrays.asList(__, XX, xx, XX, xx, XX, xx),
Arrays.asList(__, xx, __, __, __, xx, __),
Arrays.asList(xx, XX, __, XX, XX, XX, XX),
Arrays.asList(__, xx, __, xx, __, __, __),
Arrays.asList(xx, XX, xx, XX, xx, XX, __)));
}
/**
* Build the default players of the games.
*
* @return a list of the 4 players built using the default parameters.
*/
private static List<Player> buildDefaultPlayers() {
// Ugly!
return Arrays.asList(
new Player(PlayerID.PLAYER_1, PLAYER_INITIAL_LIVES, PLAYER_1_INITIAL_POSITION,
PLAYER_INITIAL_BOMB_MAXIMUM, PLAYER_INITIAL_BOMB_RANGE),
new Player(PlayerID.PLAYER_2, PLAYER_INITIAL_LIVES, PLAYER_2_INITIAL_POSITION,
PLAYER_INITIAL_BOMB_MAXIMUM, PLAYER_INITIAL_BOMB_RANGE),
new Player(PlayerID.PLAYER_3, PLAYER_INITIAL_LIVES, PLAYER_3_INITIAL_POSITION,
PLAYER_INITIAL_BOMB_MAXIMUM, PLAYER_INITIAL_BOMB_RANGE),
new Player(PlayerID.PLAYER_4, PLAYER_INITIAL_LIVES, PLAYER_4_INITIAL_POSITION,
PLAYER_INITIAL_BOMB_MAXIMUM, PLAYER_INITIAL_BOMB_RANGE)
);
}
/**
* Level build with the default images and the default players/explosions/board parameters.
*/
public static final Level DEFAULT_LEVEL = new Level(buildDefaultBoardPainter(), buildDefaultGameState());
/**
* Instantiates a new level.
*
* @param painter painter related to the level
* @param initialState initial game state of the level
*/
public Level(BoardPainter painter, GameState initialState) {
this.painter = painter;
this.initialState = initialState;
}
/**
* Returns the painter related to the current level.
*
* @return the painter related to the current level
*/
public BoardPainter painter() {
return this.painter;
}
/**
* Returns the initial game state ot the level.
*
* @return the initial game state ot the level
*/
public GameState initialState() {
return this.initialState;
}
}
|