Package scotlandyard.engine.spec

Examples of scotlandyard.engine.spec.IGame


      if(parameters.get("game")!=null){
        gameId  = parameters.get("game");
      }
      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();
      final StringBuffer sb4 = new StringBuffer();
      //3, 8, 13 and 18  are the times where MrX is exposed
      final int round = game.getRound();
      final boolean exposeMRX = game.isRoundExposingMrX(round);
      for(final IPlayer player:game.getPlayers()){
        if(player.equals(thisPlayer)||(!player.isMrx() || exposeMRX)){
          sb1.append(",\""+player.getName()+"\"");
          sb2.append(",\""+player.getPosition()+"\"");
          sb3.append(",\""+player.getIcon()+"\"");
          sb4.append(",\""+player.getName()+"\"");
        }
      }
      sb1.append(" ");sb2.append(" ");sb3.append(" ");
      final String players_list   = sb1.toString().substring(1);
      final String positions_list = sb2.toString().substring(1);
      final String icons_list     = sb3.toString().substring(1);
      final String players_names  = sb4.toString().substring(1);
     
      sb.append("{");
      sb.append("  \"players\"      : ["+players_list+"],");
      sb.append("  \"positions\"    : ["+positions_list+"],");
      sb.append("  \"icons\"        : ["+icons_list+"],");
      sb.append("  \"round\"        :  "+round+"," );
      sb.append("  \"gameStatus\"   :  \""+game.getStatus()+"\"," );
      sb.append("  \"msg\"          :  \"OK\"," );
      sb.append("  \"mrxFace\"      :  \""+(game.getStatus()=='F'?game.getMrX().getIcon():"-")+"\", ");
      sb.append("  \"mrxName\"      :  \""+(game.getStatus()=='F'?game.getMrX().getName():"")+"\", ");
      sb.append("  \"playersNames\" :  ["+players_names+"]," );
      sb.append("  \"whosTurn\"     :  \""+game.getPlayers().get(game.getCurrentTurn()).getName()+"\"" );
      sb.append("}");

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


      if(request.getParameter("selected_game")!=null){
        gameId  = request.getParameter("selected_game");
      }
      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){
View Full Code Here

    if(parameters.get("selected_game")!=null){
      this.selected_game=parameters.get("selected_game");
    }
    try{

      final IGame game = Engine.instance().games.get(this.selected_game);
      if(game==null){
        throw new Exception("Game is not known");
      }
     
      sb.append("<div><div id='map_canvas' style='width: 100%; height: 850px'></div>");
      sb.append("<div id='turn' style='position: absolute'  class='ui-widget-content'></div>");

      sb.append("<script>");
      sb.append("    $(document).ready(function(){");
      sb.append("        set_current_map('" + this.getServerBaseUrl()+game.getMapPath() +"');");
      sb.append("    });");
      sb.append("</script></div>");

    }catch(Exception e){
      sb.setLength(0);
View Full Code Here

          if(request.getParameter("selected_game")!=null){
            game_id  = request.getParameter("selected_game");
          }
          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");}
         
          out.print("{\"msg\" :  "+ game.getCurrentTurn() +"}");
         
    }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("Unknown Game");
      }

      game.addPlayer(user,mrx);
      out.print("{\"msg\" : \"OK\"}");

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

          if(parameters.get("selected_game")!=null){
            game_id  = parameters.get("selected_game");
          }
          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");}
         
          if(game.getStatus()==Game.NEW){
            sb.append("<h3 style='color:darkgreen;background-color:lightgreen' class='whosTurn_text'> The Game Has Not Been Started </h3>");
          }
          else
          {
            if(game.getStatus()==Game.FINISHED){
                sb.append("<h3 style='color:Yellow;background-color:Red' class='whosTurn_text'>" + game.getWhoWon() + "</h3>");
            }
            else
            {
              String firstName = Engine.firstWord(game.getPlayer(Engine.md5(game.getWhosTurn())).getName());
              if(game.getPlayers().get(game.getCurrentTurn()).getEmail().equals(Engine.instance().users.get(xhash).email)){
                firstName="<h3 class='whosTurn_text'>Your turn</h3>";
                //sb.append("");
              }else{
                firstName = "<h3 class='whosTurn_text' style='color:#1100FF;background-color:#66CCFF'>"+ firstName +"'s Turn</h3>";
              }
             
              sb.append(firstName);
              sb.append(new player_tickets(xhash, game.getId()).processRequest(parameters,sid));
            }
          }
         
    }catch(Exception e){
      sb.setLength(0);
View Full Code Here

        selected_game  = request.getParameter("selected_game");
      }
     
      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

        gameId = reqGameId;
      }
      if(gameId==null || "".equals(gameId)){
        throw new Exception("Game ID is not known");
      }
      final IGame game = Engine.instance().games.get(gameId);

      if(game==null){
        throw new Exception("Game is not known");
      }
     
      if(reqSelected!=null){
        selected = Boolean.valueOf(reqSelected);
      }
      if(reqxHash!=null){
        xhash=reqxHash;
      }

      if(xhash==null){
        throw new Exception("HASH is not known");
      }
     
      sb.append("<div id='"+Engine.md5(gameId)+"'><div class='game_header"+(selected?" selectedGameTag":"")+"'>Game : ");

      sb.append("&nbsp;["+Game.getStatusDefinition(game.getStatus())+"]</div>");
      sb.append("<div class='gamecontainer"+(selected?" selectedGamePanel":"")+"'>");
     
      if(!selected){
        sb.append("<button onclick='open_game(this.title)' title='"+game.getId()+"'>Open : ");
        sb.append(game.getId()+"</button><br/>");
      }else if(game.getStatus()=='N'){
          sb.append("<button onclick='start_game()'>Start game</button><br/>");
      }
      sb.append("<ul class='gameplayers'>");
      for(IPlayer p:game.getPlayers()){
       

        sb.append("<li class='gamePlayerTag"+(p.isMrx()?"X":"")+"'>");
        sb.append("<div>");
        sb.append("<img class='PlayerSmallIcon' src='images/icons/"+p.getIcon()+"'/>");
        sb.append("</div>");
        sb.append("<div>");

        if(p.isMrx()){
          sb.append("<strong>"+p.getName()+"</strong>");
        }else{
          sb.append(p.getName());
        }

        sb.append("  </div>");
        sb.append("</li>");
      }
      sb.append("</ul>");
      final IUser user = Engine.instance().getUser(xhash);
      if(game.getStatus()==Game.NEW && (user!=null && (game.getPlayers().size()==0 || (game.getPlayers().size()<6 && !game.hasPlayer(user))))){
        sb.append("<div id='game_buttons_"+game.getId()+"' align='right'>");
        sb.append("<table><tr>");
        if(game.getMrX()==null){
          sb.append("<td><button onclick='join_game(\""+game.getId()+"\",true)'>");
          sb.append("Be MrX</button></td>");

        }
        sb.append("<td><button onclick='join_game(\""+game.getId()+"\",false)'>");
        sb.append("Be Detective </button></td>");

        sb.append("</tr></table>");
        sb.append("</div>");
      }
View Full Code Here

      if(request.getParameter("selected_game")!=null){
        gameId  = request.getParameter("selected_game");
      }
      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){
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("Unknown Game");
      }

        final IUser user = Engine.instance().getUser(hash);

        if(user==null){
          throw new Exception("Unknown USER");
        }
        if(game.getStatus()!=IGame.NEW){
          throw new Exception("the game has already started.");
        }
        game.removePlayer("{\"msg\" : \""+user.getEmail()+"\"}");
       
      }catch(Exception e){
        out.print("{\"msg\" : \"EXCEPTION : "+(e.getMessage()+"").replace("\"", "'")+"\", \"className\" : \""+getClass().getName()+"\"}");
      }
  }
View Full Code Here

TOP

Related Classes of scotlandyard.engine.spec.IGame

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.