Package de.creepsmash.server.game

Examples of de.creepsmash.server.game.Game


          + "' but a game with the same name exists already");
      sender.send(new CreateGameResponseMessage(ResponseType.failed));
      return null;
    }

    Game game =
      new Game(this.nextGameId++, gameName, mapId, maxPlayers, sender, Passwort, MaxEloPoints, MinEloPoints);
    logger.info("new game: " + game);
    this.games.add(game);
    game.addObserver(this);
    sender.send(new CreateGameResponseMessage(ResponseType.ok));

    this.clients.remove(sender);
    game.newClient(sender);

    sendAll(playersMessage());
    return game;
  }
View Full Code Here


  public synchronized Game joinGame(Client sender, int gameId, String Passwort) {
    if (sender == null) {
      throw new IllegalArgumentException("'client' was null");
    }

    Game game = findGame(gameId);
    if (game == null) {
      sender.send(new JoinGameResponseMessage(ResponseType.failed));
      return null;
    }

    synchronized (game) {
     
      int clientElopoints = AuthenticationService.getPlayer(
          sender.getUserName()).getElopoints() - 500;
     
      if ((clientElopoints < game.getMinEloPoints() && game.getMinEloPoints() != 0)
          || (clientElopoints > game.getMaxEloPoints() && game.getMaxEloPoints() != 0)) {
        sender.send(new JoinGameResponseMessage(ResponseType.failed));
        return null;
      }
      if (game.getPasswort().length() > 0) {
        if (!game.getPasswort().equals(Passwort)) {

          sender
              .send(new JoinGameResponseMessage(
                  ResponseType.failed));
          return null;
        }
      }
      if ((game.canClientJoin()) && (game.check4Multi(sender.getIPAddress(), sender.getMACAddress()))) {
        sender.send(new JoinGameResponseMessage(ResponseType.ok));
        this.clients.remove(sender);
        game.newClient(sender);
      } else {
        sender.send(new JoinGameResponseMessage(ResponseType.failed));
        return null;
      }
    }
View Full Code Here

      HighscoreRequestMessage requestMessage = (HighscoreRequestMessage) message;
      this.getClient().send(new HighscoreService().
          getHighscoreMessage(requestMessage.getStart()));
      return this;
    } else if (message instanceof CreateGameMessage) {
      Game game = this.lobby.createGame(this.getClient(),
          ((CreateGameMessage) message).getGameName(),
          ((CreateGameMessage) message).getMapId(),
          ((CreateGameMessage) message).getMaxPlayers(),
          ((CreateGameMessage) message).getPasswort(),
          ((CreateGameMessage) message).getMaxEloPoints(),
          ((CreateGameMessage) message).getMinEloPoints());
     
      if (game == null) {
        authenticatedStateLogger.error("failed to create game "
            + ((CreateGameMessage) message).getGameName());
        return this;
      } else {
        return new InGameState(this.getOutQueue(), this.getClient(),
            game.getQueue(), this, this.getAuthenticationService());
      }
    } else if (message instanceof JoinGameRequestMessage) {
     
           
      Game game = this.lobby.joinGame(this.getClient(),
          ((JoinGameRequestMessage) message).getGameId(),((JoinGameRequestMessage) message).getPasswort());
     
      if (game != null) {
 
        InGameState inGame = new InGameState(this.getOutQueue(), this
            .getClient(), game.getQueue(), this,
            this.getAuthenticationService());
        authenticatedStateLogger.info("client "
            + this.getClient().getUserName() + " joined game "
            + game.getGameName() + " with gameid "
            + game.getGameId());
       
        return inGame;
      } else {
        authenticatedStateLogger.error("failed to join game "
            + ((JoinGameRequestMessage) message).getGameId());
View Full Code Here

TOP

Related Classes of de.creepsmash.server.game.Game

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.