コード例 #1
0
ファイル: GameMatch.java プロジェクト: VuDinh/SA
  public void startPlayingGame() {
    // set initial position for each player and create Hero
    HeroFactory hF = new HeroFactory();
    for (Iterator it = team2.iterator(); it.hasNext(); ) {
      Player player = (Player) it.next();
      System.out.println("slot Index:" + player.getSlotIndex());
      System.out.println("dao:" + dao);
      Cell c = dao.getHeroBeginPosition(player.getSlotIndex());
      player.setPosition(c);
      System.out.println("hero Index:" + player.getHeroIndex());
      player.setHero(hF.createHero(player.getHeroIndex()));
    }
    for (Iterator it = team1.iterator(); it.hasNext(); ) {
      Player player = (Player) it.next();
      Cell c = dao.getHeroBeginPosition(player.getSlotIndex());
      player.setPosition(c);
      System.out.println("hero Index:" + player.getHeroIndex());
      player.setHero(hF.createHero(player.getHeroIndex()));
    }
    PlayingGameRequest request = new PlayingGameRequest();
    request.setGame(this);

    // send Game request
    for (Iterator it = team2.iterator(); it.hasNext(); ) {
      Player player = (Player) it.next();
      player.getCom().write(new GameMatch(this));
    }
    for (Iterator it = team1.iterator(); it.hasNext(); ) {
      Player player = (Player) it.next();
      player.getCom().write(new GameMatch(this));
    }
  }
コード例 #2
0
ファイル: GameMatch.java プロジェクト: VuDinh/SA
 public void createMonsters() {
   MonsterFactory mF = new MonsterFactory();
   ArrayList<Cell> t = new ArrayList<Cell>(dao.getAllMonsterPositions());
   int index = 1;
   for (Iterator it = t.iterator(); it.hasNext(); ) {
     Monster monster = mF.createMonster(index);
     index++;
     if (index > 3) index = 1;
     Cell cell = (Cell) it.next();
     monster.setRow(cell.getRowPos());
     monster.setCol(cell.getColPos());
     monster.setX(cell.getColPos() * Utilizer.TILE_SIZE);
     monster.setY(cell.getRowPos() * Utilizer.TILE_SIZE);
     monsters.add(monster);
   }
 }
コード例 #3
0
ファイル: GameMatch.java プロジェクト: VuDinh/SA
 public void handleHeroRespawnRequest(HeroRespawnRequest request) {
   Cell cell = dao.getHeroBeginPosition(request.getHeroSlot());
   cell.setX(cell.getColPos() * Utilizer.TILE_SIZE);
   cell.setY(cell.getRowPos() * Utilizer.TILE_SIZE);
   try {
     request.setRespawnPos(cell.clone());
     for (Iterator it = team2.iterator(); it.hasNext(); ) {
       Player player = (Player) it.next();
       player.getCom().write(request);
     }
     for (Iterator it = team1.iterator(); it.hasNext(); ) {
       Player player = (Player) it.next();
       // if(player.getSlotIndex()!=request.getSlotIndex())
       player.getCom().write(request);
     }
   } catch (CloneNotSupportedException e) {
     e
         .printStackTrace(); // To change body of catch statement use File | Settings | File
                             // Templates.
   }
 }