Examples of IPlayer


Examples of scotlandyard.engine.spec.IPlayer

    IUser detective = myEngine.login(detectiveEmail,detectiveName,"1");

    game.addPlayer(mrx,true);

    game.addPlayer(detective,false);
    IPlayer player = game.getPlayer(mrxHash);

    Assert.assertNotNull(player);

    game.start(player);
  }
View Full Code Here

Examples of scotlandyard.engine.spec.IPlayer

  }

  @Test
  public void testGetMoves(){
    Game game = Engine.instance().games.get(gameId);
    IPlayer player = game.getPlayer(mrxHash);
    player.setPosition(1);
    Integer[] moves = game.getLegalMoves(player.getEmail());
    Assert.assertTrue(contains(moves,16));
  }
View Full Code Here

Examples of scotlandyard.engine.spec.IPlayer

  }
 
  @Test
  public void testGetMovesWithMissingTicket(){
    Game game = Engine.instance().games.get(gameId);
    IPlayer player = game.getPlayer(mrxHash);
    player.setTickets(4, 0);
    player.setPosition(1);
    Integer[] moves = game.getLegalMoves(player.getEmail());
    Assert.assertTrue(!contains(moves,16));
    player.setTickets(0, 0);
    moves = game.getLegalMoves(player.getEmail());
    Assert.assertTrue(!contains(moves,1));
  }
View Full Code Here

Examples of scotlandyard.engine.spec.IPlayer

 
  @Test
  public void testincreaseMrxTokens()
  {
    Game game = Engine.instance().games.get(gameId);
    IPlayer mrXplayer = game.getPlayer(mrxHash);
    IPlayer detectivePlayer = game.getPlayer(detectiveHash);
                mrXplayer.setPosition(4);
                try
                {
                    game.movePlayer(mrXplayer.getEmail(), 5, 2);
                }
                catch (Exception e)
                {
                    Assert.assertTrue(false);
                }

    detectivePlayer.setPosition(2);
    try {
      int before = detectivePlayer.getTickets(1);
      game.movePlayer(detectiveEmail, 3, 1);
      int after = detectivePlayer.getTickets(1);
      if(after != (before - 1))
      {
        Assert.assertEquals("detective tickets havent ben decreased properly", 2, 3);
      }
    } catch (Exception e) {
View Full Code Here

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");}

          final Integer newPosition = Integer.parseInt(parameters.get("newPosition"));
          if(newPosition==null){throw new Exception("New position is unknown");}

          final Integer transport = Integer.parseInt(parameters.get("transport"));
          if(transport==null){throw new Exception("Transport is unknown");}

          game.movePlayer(player.getEmail(), newPosition, transport);
         
          if(player.isMrx()){
            String msg = "<img src='http://scotlandyard.comule.com/get_icon.php?icon="+((int)Math.pow(2,transport))+"' width='32' height='32' alt='"+ BMap.convTransport(transport)+"'/>["+BMap.convTransport(transport)+"] was used by Mr X";
            new send_chat("SYSTEM",msg).processRequest(sid);
          }
         
          return ("{\"msg\" : \"OK\"}");
View Full Code Here

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 thisPlayer = game.getPlayer(xhash);
      if(thisPlayer==null){throw new Exception("Player is unknown");}

      final StringBuffer sb1 = new StringBuffer();
      final StringBuffer sb2 = new StringBuffer();
      final StringBuffer sb3 = new StringBuffer();
View Full Code Here

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

Examples of scotlandyard.engine.spec.IPlayer

    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

Examples of scotlandyard.engine.spec.IPlayer

    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

Examples of scotlandyard.engine.spec.IPlayer

          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
TOP
Copyright © 2018 www.massapi.com. 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.