Exemplo n.º 1
0
 @Override
 public Area getAreaAt(Enum<Areas> area, Coord c) {
   for (Area aarea : areaMap.get(area)) {
     if (aarea.getCoords().contains(c)) {
       return aarea;
     }
   }
   return null;
 }
Exemplo n.º 2
0
  private void setup(int[] setup) {
    areaMap = new LinkedHashMap<Enum<Areas>, List<Area>>();

    List<Area> boxes = new LinkedList<Area>();
    List<Area> hlists = new LinkedList<Area>();
    List<Area> vlists = new LinkedList<Area>();
    List<Area> board = new LinkedList<Area>();
    List<Area> zero = new LinkedList<Area>();

    int side_boxcount = (DIMENSION / TILES_PER_BOX); // 3 when DIMENSION =
    // 9;
    int total_boxcount = side_boxcount * side_boxcount; // 9 when DIMENSION
    // = 9;
    tiles = new Tile[DIMENSION][DIMENSION];

    /*
     * instanciate and add all needed Areas to lists
     */
    for (int i = 0; i < total_boxcount; i++) {
      boxes.add(new StandardArea());
    }
    for (int i = 1; i <= DIMENSION; i++) {
      hlists.add(new StandardArea());
      vlists.add(new StandardArea());
    }
    int h = 0;
    int v = 0;
    for (Integer value : setup) {
      /*
       * prepare the double array with Tiles and hlist, vlist and boxes
       * with Coord objects
       */
      Coord currentCoord = new Coord(v, h);
      tiles[v][h] = new StandardTile(currentCoord, value);
      hlists.get(h).addCoord(currentCoord);
      vlists.get(v).addCoord(currentCoord);

      // the index to the box this iteration has reached
      int currentboxnumber = (h / TILES_PER_BOX * side_boxcount + (v / TILES_PER_BOX + 1));
      int currentboxindex = currentboxnumber - 1;
      boxes.get(currentboxindex).addCoord(new Coord(v, h));

      // update coords
      v++;
      if (v == DIMENSION) {
        v = 0;
        h++;
      }
    }
    Area boardArea = new StandardArea();
    for (Tile[] tilearray : tiles) {
      for (Tile tile : tilearray) {
        boardArea.addCoord(tile.getCoordinate());
      }
    }
    board.add(boardArea);

    Area zeroarea = new StandardArea();
    zeroarea.addCoord(new Coord(0, 0));
    zero.add(zeroarea);

    areaMap.put(Areas.BOX, boxes);
    areaMap.put(Areas.ROW, hlists);
    areaMap.put(Areas.COL, vlists);
    areaMap.put(Areas.BOARD, board);
    areaMap.put(Areas.ZERO, zero);
  }