aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/fr/umlv/java/wallj/block/BlockFactory.java
blob: 411696db7462da7296fb70aa51900f2443543fea (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
package fr.umlv.java.wallj.block;

import fr.umlv.java.wallj.board.TileVec2;
import org.jbox2d.common.Vec2;

/**
 * A block factory.
 *
 * @author Pacien TRAN-GIRARD
 */
public final class BlockFactory {
  private BlockFactory() {
    // static class
  }

  private static Block forType(BlockType t, Vec2 pos) {
    switch (t) {
      case WALL:
        return new WallBlock(pos);
      case TRASH:
        return new TrashBlock(pos);
      case GARBAGE:
        return new GarbageBlock(pos);
      case ROBOT:
        return new RobotBlock(pos);
      case BOMB:
        return new BombBlock(pos);
      case FREE:
      default:
        return null;
    }
  }

  /**
   * @param type the type of the block to build
   * @param pos  the initial position of the block
   * @return the built block
   */
  public static Block build(BlockType type, TileVec2 pos) {
    return forType(type, pos.toVec2());
  }
}