Package scotlandyard.engine.spec

Examples of scotlandyard.engine.spec.IPlayer


      if(gameId==null || "".equals(gameId)){throw new Exception("Game Id is unknown");}

          final IGame game = Engine.instance().games.get(gameId);
          if(game==null){throw new Exception("Game is unknown");}

          final IPlayer player = game.getPlayer(xhash);
          if(player==null){throw new Exception("player is unknown");}

          out.print("{\"msg\" : \""+player.getPosition()+"\"}");

      }catch(Exception e){
          out.print("{\"msg\" : \"EXCEPTION : "+(e.getMessage()+"").replace("\"", "'")+"\", \"className\" : \""+getClass().getName()+"\"}");
      }
  }
View Full Code Here


    if (!getWhosTurn().equals(email) || this.getStatus() == FINISHED) {
      return new Integer[] {};
    }

    int p = getPlayerIndex(email);
    final IPlayer player = this.players.get(p);
    int[] result = map.getPossibleMoves(player.getPosition());
    final Integer[] copy = new Integer[result.length];

    // used for bitwise comparison, as tickets are encoded in binary
    // BUS : 0001
    // player has : 0110
    // result : 0000
    final boolean no_bus = player.getTickets(IBMap.BUS) < 1;
    final boolean no_taxi = player.getTickets(IBMap.TAXI) < 1;
    final boolean no_water = player.getTickets(IBMap.WATER) < 1;
    final boolean no_ug = player.getTickets(IBMap.UG) < 1;
    final boolean no_double = player.getTickets(IBMap.DOUBLE) < 1;

    // first get all possible moves
    // then filter them according to the number of tickets remaining
    for (int i = 0; i < result.length; i++) {
      // if the position is empty, or occupied by Mr X, then its OK
      copy[i] = 0;
      if (map.positions[i] == null
          || this.getMrX().getEmail().equals(map.positions[i])) {
        copy[i] = result[i];
        int temp = copy[i]; // need temp variable to stop transport
                  // types matching incorrectly

        // double
        if (temp >= 16) { // this condition is not required
          temp -= 16;
          if (no_double) {
            copy[i] -= 16;// but maybe used later, so will leave it
                    // now
          }
        }

        // UG
        if (temp >= 8) {
          temp -= 8;
          if (no_ug) {
            copy[i] -= 8;
          }
        }

        // water
        if (temp >= 4) {
          temp -= 4;
          if (no_water) {
            copy[i] -= 4;
          }
        }

        // taxi
        if (temp >= 2) {
          temp -= 2;
          if (no_taxi) {
            copy[i] -= 2;
          }
        }

        // bus
        if (temp >= 1) {
          temp -= 1;
          if (no_bus) {
            copy[i] -= 1;
          }
        }
      }
    }
    if (player.isMrx() && !no_double) {
      for (int i = 0; i < result.length; i++) {
        if (result[i] != 0) // meaning that there is a connection
        {
          int[] resultTwo = map.getPossibleMoves(i);
          for (int j = 0; j < resultTwo.length; j++) {
View Full Code Here

    if (!curTurn.equals(email)) {
      throw new Exception("It is " + curTurn + " turn now");
    }

    final int p = getPlayerIndex(email);
    final IPlayer player = this.players.get(p);
    final int current = player.getPosition();

    if (!this.getMrX().getEmail().equals(email) && this.getMrX().getEmail().equals(this.map.positions[newPosition])) {
      this.setWhoWon(player.getName() + " Has Caught Mrx ");
      this.status = FINISHED;
    }else{

      if (this.map.positions[newPosition] != null) {
        throw new Exception("This position is already occupied by ["
            + map.positions[newPosition] + "]");
      }


      if (this.getLegalMoves(email)[newPosition] == 0) {
        throw new Exception("node " + current + " and " + newPosition
            + " are not connected");
      }

      if (player.getTickets(transport) < 1) {
        throw new Exception("not enough tickets to move from " + current
            + " to " + newPosition);
      }
    }


    // update player last activity
    player.updateLastActivity();

    // decrement player's tickets
    player.consumeTicket(transport);

    // make player place empty
    map.positions[player.getPosition()] = null;

    // move to new position
    player.setPosition(newPosition);

    // make player new place on the map
    map.positions[player.getPosition()] = player.getEmail();

    // if the player is not mrx then increment mrx's tokens
    if (!player.isMrx()) {
      this.getMrX().setTickets(transport,
          (this.getMrX().getTickets(transport) + 1));
    }

    // increment the round when MrX plays
View Full Code Here

          if(gameId==null || "".equals(gameId)){throw new Exception("Game Id is unknown");}

          final Game game = Engine.instance().games.get(gameId);
          if(game==null){throw new Exception("Game is unknown");}

          final IPlayer player = game.getPlayer(xhash);
          if(player==null){throw new Exception("player is unknown");}

          game.start(player);

          out.print("{\"msg\" : \""+Game.getStatusDefinition(game.getStatus())+"\"}");
View Full Code Here

      if(selected_game==null || "".equals(selected_game)){throw new Exception("Game id is missing");}

      final IGame game = Engine.instance().games.get(selected_game);
      if(game==null){throw new Exception("GAME is unknow");}

      final IPlayer player = game.getPlayer(xhash);
      if(player==null){throw new Exception("UNKNOWN Player");}
     
      final Integer[]legalMoves = game.getLegalMoves(player.getEmail());
     
      int transports = legalMoves[node];
      out.println("<div class='transport_options'>");
      transports = showTransportButton(out,transports,16);
      transports = showTransportButton(out,transports,8);
View Full Code Here

      if(gameId==null || "".equals(gameId)){throw new Exception("Game Id is unknown");}

      final IGame game = Engine.instance().games.get(gameId);
      if(game==null){throw new Exception("Game is unknown");}

      final IPlayer player = game.getPlayer(xhash);
      if(player==null){throw new Exception("player is unknown");}

      final String moves = Arrays.toString(game.getLegalMoves(player.getEmail())).replace("{", "[").replace("}", "]").replace("null", "0");
      final IPlayer mrx = game.getMrX();
      if(mrx==null){
        throw new Exception("MR X Is not there");
      }
      String position = "-1";
      if(game.isRoundExposingMrX(game.getRound())){
        position = mrx.getPosition()+"";
      }
      out.print("{\"msg\" : "+ moves +", \"mrx\" : { \"position\" : "+ position +", \"face\" : \""+ mrx.getIcon() +"\", \"name\" : \""+mrx.getName()+"\"} }");

    }catch(Exception e){
     
      out.print("{\"msg\" : \"EXCEPTION : "+(e.getMessage()+"").replace("\"", "'")+"\", \"className\" : \""+getClass().getName()+"\"}");
    }
View Full Code Here

          if(game_id==null || "".equals(game_id)){throw new Exception("Game id is missing");}

          final IGame game = Engine.instance().games.get(game_id);
          if(game==null){throw new Exception("GAME is unknow");}

          final IPlayer player = game.getPlayer(xhash);
          if(player==null){throw new Exception("UNKNOWN Player");}

          sb.append("<div class='player_tickets'><table cellpadding='2' class='tokens'>");
          final StringBuffer sb1 = new StringBuffer();
          final StringBuffer sb2 = new StringBuffer();
          for(int i=0;i<5;i++){
              final String tr = BMap.convTransport(i);
              final String url = "http://scotlandyard.comule.com/get_icon.php?icon=";
              sb1.append("<td><img src='"+url+pow2(i)+"' alt='"+tr+"' title='"+tr+"' id='transport_"+i+"'/></td>");
              sb2.append("<th>"+player.getTickets(i)+"</th>");
          }
          sb.append("<tr>"+sb1.toString()+"</tr>");
          sb.append("<tr>"+sb2.toString()+"</tr>");
          sb.append("</table>");
      }catch(Exception e){
View Full Code Here

TOP

Related Classes of scotlandyard.engine.spec.IPlayer

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.