Example #1
1
  /**
   * m├ęthode qui place automatiquement les pions du joueurs.
   *
   * @param joueur
   * @param isAnIA
   */
  public void dude(boolean joueur, boolean isAnIA) {
    ArrayList<Pion> listPion = initializePions(joueur, isAnIA);

    if (joueur) {
      reverse(map.getMap());
    }

    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 10; j++) {
        removePion(i, j);
      }
    }

    setDrapeau(listPion);
    setEclaireur(listPion);
    setBombe(listPion);
    setEspionAndMarechal(listPion);
    setDemineur(listPion);
    setSergent(listPion);
    setLieutenant(listPion);
    setOthersPions(listPion);

    if (joueur) {
      reverse(map.getMap());
    }
  }
Example #2
1
 private static boolean legalPush(Position newBoxPos, Map map) {
   boolean deadLock = DeadLock.getDL(newBoxPos);
   boolean obstacle = !isAvailiable(map.getMap(), newBoxPos);
   boolean boxDeadLock = createsDeadlock(map.getMap(), newBoxPos);
   if (!deadLock && !obstacle && !boxDeadLock) {
     return true;
   }
   return false;
 }
  private void printMapPath(Stack<int[]> path, boolean showChecked) {

    for (int i = 0; i < map.getMapSize(); i++) {
      for (int j = 0; j < map.getMapSize(); j++) {
        if (inPath(path, new int[] {j, i}) && j == end[0] && i == end[1]) {
          System.out.print('*');
        } else if (inPath(path, new int[] {j, i})) {
          System.out.print('P');
        } else if (j == end[0] && i == end[1]) {
          System.out.print('#');
        } else {
          char l = map.getMap(j, i);
          if (l == 'g') {
            System.out.print(' ');
          } else if (checkedMap[j][i] && showChecked) {
            System.out.print('C');
          } else {
            System.out.print(l);
          }
        }
      }
      System.out.println();
    }
    System.out.println();

    try {
      Thread.sleep(200);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Example #4
1
 boolean oneCount(Map map) {
   int count = 0;
   for (int[] a : map.getMap()) {
     for (int x : a) {
       if (x == 1) {
         count++;
       }
     }
   }
   // System.out.println((count/((x-2)*(y-2)) ));
   // 0.3 -0.2
   if (((double) count / (((double) x - 2) * ((double) y - 2))) < 0.3
       && ((double) count / (((double) x - 2) * ((double) y - 2))) > 0.2) {
     return true;
   } else {
     return false;
   }
 }
  private boolean checkMap(Stack<int[]> path, int[] pos2Check) {

    if (!isAlive) {
      return false;
    }

    if (pos2Check[0] <= map.getMapSize() - 1
        && pos2Check[0] >= 0
        && pos2Check[1] <= map.getMapSize() - 1
        && pos2Check[1] >= 0
        && map.getMap(pos2Check[0], pos2Check[1]) == moveable
        && !inPath(path, pos2Check)
        && !checkedMap[pos2Check[0]][pos2Check[1]]) {

      return true;
    }

    return false;
  }
Example #6
1
 private static void saveState(Map map, Robot r) {
   char[][] amap = map.getMap().clone();
   char[][] submap = new char[amap.length][amap[0].length];
   for (int i = 0; i < amap.length; ++i) {
     for (int j = 0; j < amap[i].length; ++j) {
       char c = amap[i][j];
       submap[i][j] = c;
     }
   }
   // State s = new State(submap, r.posX, r.posY, r.getDiamonds());
   System.out.println("ANTES DE IRES PARA A PEGA DA STACK!!");
   for (int i = submap.length - 1; i >= 0; --i) {
     String line = "";
     for (int j = 0; j < submap[i].length; ++j) {
       line += submap[i][j];
     }
     System.out.println(line);
   }
   past.push(submap);
   submap = null;
   // s = null;
 }
Example #7
1
 private static boolean[] search(Position playerPos, Box box, Map map) {
   char[][] board = map.getMap();
   // Directions[0-4] = west, east, north, south!
   boolean[] directions = new boolean[4];
   for (int i = 0; i < 4; i++) {
     directions[i] = false;
   }
   Position boxPos = box.getPosition();
   Position west = new Position(boxPos.getRow(), boxPos.getCol() - 1);
   Position east = new Position(boxPos.getRow(), boxPos.getCol() + 1);
   Position north = new Position(boxPos.getRow() - 1, boxPos.getCol());
   Position south = new Position(boxPos.getRow() + 1, boxPos.getCol());
   boolean[][] visited = new boolean[map.getRows()][map.getCols()];
   // Initialize visited to false
   for (int row = 0; row < map.getRows(); row++) {
     for (int col = 0; col < map.getCols(); col++) {
       visited[row][col] = false;
     }
   }
   Queue<Position> q = new LinkedList<Position>();
   q.add(playerPos);
   visited[playerPos.getRow()][playerPos.getCol()] = true;
   while (!q.isEmpty()) {
     Position currPos = q.remove();
     // may reach left position of the box
     if (currPos.isEqualTo(west)) {
       directions[0] = true;
     }
     // may reach right position of the box
     if (currPos.isEqualTo(east)) {
       directions[1] = true;
     }
     // may reach peter north position of the box
     if (currPos.isEqualTo(north)) {
       directions[2] = true;
     }
     // may reach south position of the box
     if (currPos.isEqualTo(south)) {
       directions[3] = true;
     }
     for (int direction = 0; direction < 4; direction++) {
       if (direction == WEST) {
         Position newPos = new Position(currPos.getRow(), currPos.getCol() - 1);
         if (!visited[newPos.getRow()][newPos.getCol()] && isAvailiable(board, newPos)) {
           visited[newPos.getRow()][newPos.getCol()] = true;
           q.add(newPos);
         }
       } else if (direction == EAST) {
         Position newPos = new Position(currPos.getRow(), currPos.getCol() + 1);
         if (!visited[newPos.getRow()][newPos.getCol()] && isAvailiable(board, newPos)) {
           visited[newPos.getRow()][newPos.getCol()] = true;
           q.add(newPos);
         }
       } else if (direction == NORTH) {
         Position newPos = new Position(currPos.getRow() - 1, currPos.getCol());
         if (!visited[newPos.getRow()][newPos.getCol()] && isAvailiable(board, newPos)) {
           visited[newPos.getRow()][newPos.getCol()] = true;
           q.add(newPos);
         }
       } else if (direction == SOUTH) {
         Position newPos = new Position(currPos.getRow() + 1, currPos.getCol());
         if (!visited[newPos.getRow()][newPos.getCol()] && isAvailiable(board, newPos)) {
           visited[currPos.getRow()][currPos.getCol()] = true;
           q.add(newPos);
         }
       }
     }
   }
   return directions;
 }
Example #8
1
 /** Checks the timers and start actions according to it */
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == buttonTimer) {
     // From the Btns class
     if (Btns.startB) {
       unPause();
       this.requestFocus();
     }
     if (Btns.pauseB) {
       pause();
       this.requestFocus();
     }
   }
   if (e.getSource() == fallTime) {
     shapes.get(0).fall(map, character);
     repaint();
     if (shapes.get(0).hitGround()) {
       map.addShape(shapes.get(0));
       map.clearLines();
       shapes.remove(0);
       addShape();
     }
   }
   if (e.getSource() == aiMove) {
     if (aiCommand.size() > 0) {
       shapes.get(0).aiCommand(map, aiCommand.get(0), shapeTrack);
       if (aiCommand.get(0) != 0) {
         shapeTrack.add(aiCommand.get(0));
       }
       aiCommand.remove(0);
       repaint();
     }
   }
   if (e.getSource() == moveTime) {
     character.checkUnderWater(water.getY());
     character.checkDeath(shapes.get(0).getShape());
     character.move(map, shapes.get(0));
     if (character.checkExit() == true) {
       MyFrame.screen = "gameover";
       pause();
       character.setDeath(false);
     }
     if (character.getDeath() == true) {
       pause();
       MyFrame.screen = "gameover";
       character.setDeath(false);
     }
   }
   if (e.getSource() == bulletMoveTime) {
     for (int i = 0; i < weaponList.size(); i++) {
       weaponList.get(i).move((int) character.getX(), (int) character.getY());
       if (!weaponList.get(i).getWeapon().equalsIgnoreCase("laser")) {
         int[] col = weaponList.get(i).collide(shapes.get(0), map);
         if (col[2] == 0) {
           map.change(
               weaponList
                   .get(i)
                   .damage(
                       map.getMap(),
                       col[1] / Square.SIZE,
                       col[0] / Square.SIZE,
                       THA.HEIGHT / Square.SIZE,
                       THA.WIDTH / Square.SIZE));
         } else if (col[2] == 1) {
           shapes
               .get(0)
               .change(
                   weaponList
                       .get(i)
                       .damage(
                           shapes.get(0).getShape(),
                           shapes.get(0).getIndex(col[0], col[1])[0],
                           shapes.get(0).getIndex(col[0], col[1])[1],
                           4,
                           4));
         }
         i = removeBullet(i);
         if (shapes.get(0).shapeGone()) {
           shapes.remove(0);
           addShape();
         }
       } else {
         map.change(
             weaponList
                 .get(i)
                 .damage(
                     map.getMap(),
                     (int) (character.getX() / Square.SIZE),
                     (int) (character.getY() / Square.SIZE),
                     THA.HEIGHT / Square.SIZE,
                     THA.WIDTH / Square.SIZE));
       }
       if (weaponList.get(i).getRemove() == true) {
         weaponList.remove(i);
       }
     }
   }
   if (System.currentTimeMillis() - startWater > 100 * 500 && startWater != 0) {
     if (e.getSource() == waterTime) {
       water.move();
     }
   }
   // delays for weapons
   if (e.getSource() == bulletTime) {
     bshoot = true;
   }
   if (e.getSource() == grenadeTime) {
     gshoot = true;
   }
   if (e.getSource() == laserTime) {
     lshoot = true;
   }
   if (e.getSource() == shotgunTime) {
     sgshoot = true;
   }
   repaint();
 }