aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl/xblast/server/painter/ExplosionPainter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/xblast/server/painter/ExplosionPainter.java')
-rw-r--r--src/ch/epfl/xblast/server/painter/ExplosionPainter.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/ch/epfl/xblast/server/painter/ExplosionPainter.java b/src/ch/epfl/xblast/server/painter/ExplosionPainter.java
new file mode 100644
index 0000000..63181e9
--- /dev/null
+++ b/src/ch/epfl/xblast/server/painter/ExplosionPainter.java
@@ -0,0 +1,55 @@
1package ch.epfl.xblast.server.painter;
2
3import ch.epfl.xblast.server.*;
4
5/**
6 * @author Timothée FLOURE (257420)
7 */
8public final class ExplosionPainter {
9 private static final byte BLACK_BOMB_IMAGE = 20;
10 private static final byte WHITE_BOMB_IMAGE = 21;
11
12 private static final byte NORTH_EXPLOSION = 0b1000;
13 private static final byte EAST_EXPLOSION = 0b0100;
14 private static final byte SOUTH_EXPLOSION = 0b0010;
15 private static final byte WEST_EXPLOSION = 0b0001;
16
17 /**
18 * Return the image corresponding to a bomb depending on its fuse length.
19 *
20 * @param bomb given bomb
21 * @return the byte related to the image of the bomb (black or white)
22 */
23 public static byte byteForBomb(Bomb bomb)
24 {
25 if (Integer.bitCount(bomb.fuseLength()) == 1 ) {
26 return WHITE_BOMB_IMAGE;
27 } else {
28 return BLACK_BOMB_IMAGE;
29 }
30 }
31
32 /**
33 * Return the image corresponding to the explosion on a cell given the explosions of its neighbors.
34 *
35 * @param north is an explosion on the north cell
36 * @param east is an explosion on the east cell
37 * @param south is an explosion on the south cell
38 * @param west is an explosion on the west cell
39 * @return the byte corresponding to the related image
40 */
41 public static byte byteForBlast(boolean north, boolean east, boolean south, boolean west) {
42 byte correspondingByte = 0b0;
43
44 if (north)
45 correspondingByte += NORTH_EXPLOSION;
46 if (east)
47 correspondingByte += EAST_EXPLOSION;
48 if (south)
49 correspondingByte += SOUTH_EXPLOSION;
50 if (west)
51 correspondingByte += WEST_EXPLOSION;
52
53 return correspondingByte;
54 }
55}