コード例 #1
0
  private void batteResult(NodeConnection remoteCon) {
    ApplicationMessage message = new ApplicationMessage();

    BattleDAO daoB = new BattleDAO();
    Vector<BattleData> vetB = daoB.buscarTodos();
    int indexB = (int) (vetB.size() * Math.random());
    BattleData battle = vetB.elementAt(indexB);
    int battleId = battle.getId();

    CharacterDAO daoC = new CharacterDAO();
    Vector<CharacterData> vetC = daoC.buscarTodos();
    int indexC = (int) (vetC.size() * Math.random());
    CharacterData charData = vetC.elementAt(indexC);
    int charId = charData.getId();

    ClanDAO daoClan = new ClanDAO();
    Vector<ClanData> vetClan = daoClan.buscarTodos();
    int indexClan = (int) (vetClan.size() * Math.random());
    ClanData clanData = vetClan.elementAt(indexClan);
    int clanId = clanData.getId();
    BattleResultRequest request = new BattleResultRequest(battleId, charId, clanId);

    message.setContentObject(request);

    try {
      remoteCon.sendMessage(message);
      Thread.sleep(5000);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (InterruptedException ex) {
      Thread.currentThread().interrupt();
    }
  }
コード例 #2
0
  private void aceitaLuta(NodeConnection remoteCon, Message message) {
    FightRequest request = (FightRequest) Serialization.fromJavaByteStream(message.getContent());
    BattleData battle = request.getBattle();
    CharacterData charData = request.getCharData();

    ClanDAO dao = new ClanDAO();
    Vector<ClanData> vet = dao.buscarTodos();
    int index = (int) (Math.random() * vet.size());
    ClanData clan = vet.elementAt(index);
    // Logando
    FightResponse response =
        new FightResponse(charData.getId(), battle.getId(), true, clan.getId());
    message.setContentObject(response);

    try {
      remoteCon.sendMessage(message);
      Thread.sleep(5000);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (InterruptedException ex) {
      Thread.currentThread().interrupt();
    }
  }