Пример #1
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);
      }
    }
  }
Пример #2
0
  public void protocolBall() {
    /* On met à jour la position de la balle */
    int positionBallX = Integer.parseInt(tab[1]);
    int positionBallY = Integer.parseInt(tab[2]);

    Ball ball = pong.getBall();

    /* Anti-cheat */
    if ((positionBallX > (ball.getPositionX() + ball.getSpeedX()) && ball.getSpeedX() > 0)
        || (positionBallX < (ball.getPositionX() + ball.getSpeedX()) && ball.getSpeedX() < 0)
        || (positionBallY > (ball.getPositionY() + ball.getSpeedY()) && ball.getSpeedY() > 0)
        || (positionBallY < (ball.getPositionY() + ball.getSpeedY()) && ball.getSpeedY() < 0)) {
      errorCheat("Balle avec coordonnées invalides (cheat)");
    }

    ball.setPosition(new Point(positionBallX, positionBallY));
    pong.setBall(ball);

    /* On met à jour les scores */
    for (int i = 3; i < tab.length; i++) {
      String[] curPlayer = tab[i].split(";");
      PlayerID playerID = PlayerID.valueOf(curPlayer[0]);
      int score = Integer.parseInt(curPlayer[1]);

      Iterator<Player> it = pong.setPlayers.iterator();
      while (it.hasNext()) {
        Player player = it.next();
        if (player.getPlayerID() == playerID) {
          player.setScore(score);
        }
      }
    }
  }
Пример #3
0
 public String getPlayerInfo(Player player) {
   return (player.getPlayerID()
       + ";"
       + player.getScore()
       + ";"
       + player.getRacket().getPositionX()
       + ";"
       + player.getRacket().getPositionY());
 }