aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl/xblast/server/painter/ExplosionPainter.java
blob: 63181e9dae1887892c0eff3bf3b97a3f70ee07f0 (plain)
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
package ch.epfl.xblast.server.painter;

import ch.epfl.xblast.server.*;

/**
 * @author Timothée FLOURE (257420)
 */
public final class ExplosionPainter {
    private static final byte BLACK_BOMB_IMAGE = 20;
    private static final byte WHITE_BOMB_IMAGE = 21;

    private static final byte NORTH_EXPLOSION = 0b1000;
    private static final byte EAST_EXPLOSION = 0b0100;
    private static final byte SOUTH_EXPLOSION = 0b0010;
    private static final byte WEST_EXPLOSION = 0b0001;

    /**
     * Return the image corresponding to a bomb depending on its fuse length.
     *
     * @param bomb given bomb
     * @return the byte related to the image of the bomb (black or white)
     */
    public static byte byteForBomb(Bomb bomb)
    {
        if (Integer.bitCount(bomb.fuseLength()) == 1 ) {
            return WHITE_BOMB_IMAGE;
        } else {
            return BLACK_BOMB_IMAGE;
        }
    }

    /**
     * Return the image corresponding to the explosion on a cell given the explosions of its neighbors.
     *
     * @param north is an explosion on the north cell
     * @param east is an explosion on the east cell
     * @param south is an explosion on the south cell
     * @param west is an explosion on the west cell
     * @return the byte corresponding to the related image
     */
    public static byte byteForBlast(boolean north, boolean east, boolean south, boolean west) {
        byte correspondingByte = 0b0;

        if (north)
            correspondingByte += NORTH_EXPLOSION;
        if (east)
            correspondingByte += EAST_EXPLOSION;
        if (south)
            correspondingByte += SOUTH_EXPLOSION;
        if (west)
            correspondingByte += WEST_EXPLOSION;

        return correspondingByte;
    }
}