Beispiel #1
0
  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));
    }
  }
Beispiel #2
0
 public void handleMatchResultRequest(MatchResultRequest request) {
   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);
   }
 }
Beispiel #3
0
 public void announceFingdingMatchRequest() {
   MatchMakingRequest m = new MatchMakingRequest(counter);
   for (Iterator it = team1.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     player.getCom().write(m);
   }
   for (Iterator it = team2.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     player.getCom().write(m);
   }
 }
Beispiel #4
0
 public void sendMessageToAll(Message mes) {
   for (Iterator it = team2.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     // if(player.getSlotIndex()!=request.getSlotIndex())
     if (player.getSlotIndex() != mes.getSlotIndex()) player.getCom().write(mes);
   }
   for (Iterator it = team1.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     // if(player.getSlotIndex()!=request.getSlotIndex())
     if (player.getSlotIndex() != mes.getSlotIndex()) player.getCom().write(mes);
   }
 }
Beispiel #5
0
 public void sendMessageToPlayer(Message mes) {
   for (Iterator it = team2.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     if (player.getCom().getAccount().getUsername().equals(mes.getReceiver().getUsername()))
       player.getCom().write(mes);
   }
   for (Iterator it = team1.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     // if(player.getSlotIndex()!=request.getSlotIndex())
     if (player.getCom().getAccount().getUsername().equals(mes.getReceiver().getUsername()))
       player.getCom().write(mes);
   }
 }
Beispiel #6
0
 public void handleHeroAttackRequest(HeroAttackRequest request) {
   int slot = request.getSlotIndex();
   for (Iterator it = team2.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     // if(player.getSlotIndex()!=request.getSlotIndex())
     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);
   }
 }
Beispiel #7
0
 public void nextTurn() {
   if (turnIndex < Utilizer.MAXPLAYER - 1) turnIndex++;
   else turnIndex = 0;
   TurnControlRequest request = new TurnControlRequest(turnIndex, gameIndex);
   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);
   }
 }
Beispiel #8
0
 public void chooseHero(Communicator com, int heroSlot, int heroIndex) {
   // announce to the others about the other hero picked
   HeroPickedRequest request = new HeroPickedRequest(heroIndex, heroSlot);
   Player temp = getPlayer(heroSlot);
   temp.setPicked(true);
   temp.setHeroIndex(heroIndex);
   request.setPlayerName(com.getAccount().getUsername());
   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();
     player.getCom().write(request);
   }
 }
Beispiel #9
0
 public void announceHeroChoosingRequest() {
   for (Iterator it = team1.iterator(); it.hasNext(); ) {
     HeroChoosingRequest m = new HeroChoosingRequest();
     Player player = (Player) it.next();
     m.setMatchIndex(gameIndex);
     m.setHeroSlotIndex(player.getSlotIndex());
     player.getCom().write(m);
   }
   for (Iterator it = team2.iterator(); it.hasNext(); ) {
     HeroChoosingRequest m = new HeroChoosingRequest();
     Player player = (Player) it.next();
     m.setMatchIndex(gameIndex);
     m.setHeroSlotIndex(player.getSlotIndex());
     player.getCom().write(m);
   }
 }
Beispiel #10
0
 public void handleHeroMoveRequest(HeroMoveRequest request) {
   int slot = request.getSlotIndex();
   // set Hero new position
   getPlayer(slot).getHero().setRow(request.getSelectedCell().getRowPos());
   getPlayer(slot).getHero().setCol(request.getSelectedCell().getColPos());
   getPlayer(slot).getHero().setX(request.getSelectedCell().getColPos() * Utilizer.TILE_SIZE);
   getPlayer(slot).getHero().setY(request.getSelectedCell().getRowPos() * Utilizer.TILE_SIZE);
   // send move request to other player
   for (Iterator it = team2.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     // if(player.getSlotIndex()!=request.getSlotIndex())
     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);
   }
 }
Beispiel #11
0
 public void sendMessageToTeam(Message mes) {
   Player p = getPlayer(mes.getSlotIndex());
   ArrayList<Player> team;
   if (p.getTeam().equals(Team.team1)) team = team1;
   else team = team2;
   for (Iterator it = team.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     // if(player.getSlotIndex()!=request.getSlotIndex())
     if (player.getSlotIndex() != mes.getSlotIndex()) player.getCom().write(mes);
   }
 }
Beispiel #12
0
 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.
   }
 }
Beispiel #13
0
 public void handleQuitRequest(QuitRequest request) {
   Player p = getPlayer(request.getHeroSlot());
   p.getCom().close();
   for (Iterator it = team2.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     if (!player.getCom().isClosed()) {
       player.getCom().write(request);
       System.out.println("announce quit to:" + player.getCom().getAccount().getUsername());
     }
   }
   for (Iterator it = team1.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     if (!player.getCom().isClosed()) {
       player.getCom().write(request);
       System.out.println("announce quit to:" + player.getCom().getAccount().getUsername());
     }
   }
   // getPlayer(request.getHeroSlot()).getCom().close();
   quitNum++;
 }