Пример #1
0
 public String getPlayerInfo(Player player) {
   return (player.getPlayerID()
       + ";"
       + player.getScore()
       + ";"
       + player.getRacket().getPositionX()
       + ";"
       + player.getRacket().getPositionY());
 }
Пример #2
0
  public void protocolPlayer() {
    String[] curPlayer = tab[1].split(";");
    PlayerID playerID = PlayerID.valueOf(curPlayer[0]);
    int positionRacketX = Integer.parseInt(curPlayer[2]);
    int positionRacketY = Integer.parseInt(curPlayer[3]);

    /* On met à jour la position du joueur */
    Iterator<Player> it = pong.setPlayers.iterator();
    while (it.hasNext()) {
      Player player = it.next();
      if (player.getPlayerID() == playerID) {
        Racket racket = player.getRacket();

        /* Anti-cheat */
        if ((positionRacketX > (racket.getPositionX() + racket.getSpeed()) && racket.getSpeed() > 0)
            || (positionRacketX < (racket.getPositionX() + racket.getSpeed())
                && racket.getSpeed() < 0)
            || (positionRacketY > (racket.getPositionY() + racket.getSpeed())
                && racket.getSpeed() > 0)
            || (positionRacketY < (racket.getPositionY() + racket.getSpeed())
                && racket.getSpeed() < 0)) {
          errorCheat("Raquette avec coordonnées invalides (cheat)");
        }

        racket.setPosition(new Point(positionRacketX, positionRacketY));
        player.setRacket(racket);
      }
    }
  }