Example #1
0
 @Override
 public HashMap<String, Integer> getInfo(GameObjectID id) throws BozorgExceptionBase {
   HashMap<String, Integer> ret = new HashMap<String, Integer>();
   if (objects.get(id.getNumber()).getClass().equals(Fan.class)) {
     Fan f = (Fan) objects.get(id.getNumber());
     ret.put(JudgeAbstract.ROW, f.x);
     ret.put(JudgeAbstract.COL, f.y);
     ret.put(JudgeAbstract.OWNER, f.owner.getName());
     if (f.isAlive) ret.put(JudgeAbstract.IS_ALIVE, JudgeAbstract.ALIVE);
     else ret.put(JudgeAbstract.IS_ALIVE, JudgeAbstract.DEAD);
   }
   if (objects.get(id.getNumber()).getClass().equals(Player.class)) {
     Player p = (Player) objects.get(id.getNumber());
     ret.put(JudgeAbstract.ROW, p.x);
     ret.put(JudgeAbstract.COL, p.y);
     ret.put(JudgeAbstract.SPEED, p.getSpeed());
     ret.put(JudgeAbstract.NAME, p.getName());
     if (Judge.winner == 4) ret.put(JudgeAbstract.IS_WINNER, JudgeAbstract.NOT_FINISHED);
     else if (Judge.winner == p.getName()) ret.put(JudgeAbstract.IS_WINNER, JudgeAbstract.WINS);
     else ret.put(JudgeAbstract.IS_WINNER, JudgeAbstract.LOST);
     ret.put(JudgeAbstract.POWER, p.getPower());
     ret.put(JudgeAbstract.VISION, p.getVision());
     ret.put(JudgeAbstract.FANS, p.getFans());
     if (p.getHp() > 0) ret.put(JudgeAbstract.IS_ALIVE, JudgeAbstract.ALIVE);
     else ret.put(JudgeAbstract.IS_ALIVE, JudgeAbstract.DEAD);
     ret.put(JudgeAbstract.HEALTH, Math.max(p.getHp(), 0));
   }
   return ret;
 }
Example #2
0
 @Override
 public void updateInfo(GameObjectID id, String infoKey, Integer infoValue)
     throws BozorgExceptionBase {
   if (objects.get(id.getNumber()).getClass().equals(Fan.class)) {
     Fan f = (Fan) objects.get(id.getNumber());
     if (infoKey.equals(JudgeAbstract.ROW)) f.x = infoValue;
     if (infoKey.equals(JudgeAbstract.COL)) f.y = infoValue;
     if (infoKey.equals(JudgeAbstract.OWNER))
       for (Player p : players) if (p.getName() == infoValue) f.owner = p;
     if (infoKey.equals(JudgeAbstract.IS_ALIVE))
       if (infoValue == JudgeAbstract.ALIVE) f.isAlive = true;
       else f.isAlive = false;
   }
   if (objects.get(id.getNumber()).getClass().equals(Player.class)) {
     Player p = (Player) objects.get(id.getNumber());
     if (infoKey.equals(JudgeAbstract.ROW)) p.x = infoValue;
     if (infoKey.equals(JudgeAbstract.COL)) p.y = infoValue;
     if (infoKey.equals(JudgeAbstract.IS_ALIVE))
       if (infoValue == JudgeAbstract.ALIVE) if (p.getHp() == 0) p.setHp(100);
     if (infoKey.equals(JudgeAbstract.SPEED)) p.setSpeed(infoValue);
     if (infoKey.equals(JudgeAbstract.NAME)) p.setName(infoValue);
     if (infoKey.equals(JudgeAbstract.POWER)) p.setPower(infoValue);
     if (infoKey.equals(JudgeAbstract.VISION)) p.setVision(infoValue);
     if (infoKey.equals(JudgeAbstract.FANS)) p.setFans(infoValue);
   }
 }
Example #3
0
 @Override
 public ArrayList<String> getVision(GameObjectID player) throws BozorgExceptionBase {
   if (!player.getClass().equals(Player.class)) throw new BozorgExceptionBase();
   if (((Player) (objects.get(player.getNumber()))).getHp() == 0) throw new BozorgExceptionBase();
   if (((Player) objects.get(player.getNumber())).getVision() > 0) {
     ArrayList<String> ret = new ArrayList<String>();
     for (int i = 0; i < map.getWidth(); i++)
       for (int j = 0; j < map.getHeight(); j++) ret.add(i + "," + j);
     return ret;
   }
   TreeSet<String> set = new TreeSet<String>();
   Player p = (Player) objects.get(player.getNumber());
   for (Object o : objects) {
     if (o.getClass().equals(Fan.class))
       if (((Fan) o).owner.equals((Player) objects.get(player.getNumber())) && ((Fan) o).isAlive)
         set.add(((Fan) o).x + "," + ((Fan) o).y);
   }
   for (int i = Math.max(0, p.x - p.getVision());
       i < Math.min(map.getWidth(), p.x + p.getVision() + 1);
       i++)
     for (int j = Math.max(0, p.y - p.getVision());
         j < Math.min(map.getHeight(), p.y + p.getVision() + 1);
         j++) set.add(i + "," + j);
   ArrayList<String> ret = new ArrayList<String>();
   for (String s : set) ret.add(s);
   return ret;
 }
Example #4
0
 @Override
 public GameObjectID throwFan(GameObjectID player) throws BozorgExceptionBase {
   Player p = (Player) objects.get(player.getNumber());
   if (p.getHp() == 0) throw new BozorgExceptionBase();
   if (p.getFans() == 0) throw new BozorgExceptionBase();
   Fan f = new Fan(p.x, p.y, (Player) objects.get(player.getNumber()));
   objects.add(f);
   GameObjectID g = GameObjectID.create(f.getClass());
   f.id = g;
   objectsId.add(g);
   p.setFans(p.getFans() - 1);
   return g;
 }
Example #5
0
 @Override
 public void getGift(GameObjectID player) throws BozorgExceptionBase {
   Player p = (Player) objects.get(player.getNumber());
   if (p.getHp() == 0) throw new BozorgExceptionBase();
   if (getMapCellType(p.x, p.y, player) != BONUS_CELL) throw new BozorgExceptionBase();
   for (Player x : Judge.players) {
     if (x.equals(p)) continue;
     if (x.x == p.x && x.y == p.y) throw new BozorgExceptionBase();
   }
   int t = map.getMap()[p.x][p.y].getType();
   if (t == JUMP_CELL) {
     p.setJump(p.getJump() + 2000);
   }
   if (t == SPEEDUP_CELL) {
     p.setSpeed(p.getSpeed() + 5000);
   }
   if (t == STONE_CELL) {
     p.setStun(p.getStun() + 3000);
   }
   if (t == FAN_CELL) {
     p.setFans(p.getFans() + 3);
   }
   if (t == RADAR_CELL) {
     p.setVision(p.getVision() + 3000);
   }
   if (t == HOSPITAL_CELL) {
     p.setHp(Math.min(p.getHp() + 20, 100));
   }
   map.getMap()[p.x][p.y].setType(0);
 }
Example #6
0
 @Override
 public ArrayList<GameObjectID> getFans(GameObjectID player) throws BozorgExceptionBase {
   ArrayList<GameObjectID> ret = new ArrayList<GameObjectID>();
   for (Object o : objects) {
     if (o.getClass().equals(Fan.class))
       if (((Fan) o).owner.equals((Player) objects.get(player.getNumber())) && ((Fan) o).isAlive)
         ret.add(((Fan) o).id);
   }
   return ret;
 }
Example #7
0
 @Override
 public void attack(GameObjectID attacker, int direction) throws BozorgExceptionBase {
   Player p = (Player) objects.get(attacker.getNumber());
   int w = map.getMap()[p.x][p.y].getWalls();
   if (p.getHp() == 0) throw new BozorgExceptionBase();
   if (direction < 0 || direction > 4) throw new BozorgExceptionBase();
   if ((w >> direction) % 2 == 1) throw new BozorgExceptionBase();
   if (p.getAttackTime() > 0) throw new BozorgExceptionBase();
   p.setAttackTime(p.getSpeed() + p.getAttackTime());
   p.setAttackDir(direction);
 }
Example #8
0
 @Override
 public ArrayList<GameObjectID> loadMap(int[][] cellsType, int[][] wallsType, int[] players) {
   Player[] p = new Player[players.length];
   ArrayList<GameObjectID> ret = new ArrayList<GameObjectID>();
   for (int i = 0; i < p.length; i++) {
     p[i] = new Player(players[i]);
     ret.add(GameObjectID.create(p[i].getClass()));
     p[i].id = ret.get(i);
     objects.add(p[i]);
     objectsId.add(ret.get(i));
     this.players.add(p[i]);
   }
   map = new Map(cellsType, wallsType, p);
   return ret;
 }