Пример #1
0
 private int getPlayersMinScore() {
   int result = 0;
   for (Player player : players) {
     result = Math.min(player.getScore(), result);
   }
   return result;
 }
Пример #2
0
 /** funkcja dodająca wyniki do listy najlepszych */
 public static void addBest() {
   Record rec = new Record(Player.getPlayerName(), Player.getScore());
   if (best.size() < MAX) best.add(rec);
   else if (returnMin() < rec.getScore()) {
     best.remove(MAX - 1);
     best.add(rec);
   }
 }
Пример #3
0
  @Override
  public void nextStepForAllGames() {
    lock.writeLock().lock();
    try {
      for (Game game : games) {
        if (game.isGameOver()) {
          game.newGame();
        }
        game.tick();
      }

      HashMap<Player, PlayerData> map = new HashMap<Player, PlayerData>();
      for (int i = 0; i < games.size(); i++) {
        Game game = games.get(i);

        Player player = players.get(i);

        map.put(
            player,
            new PlayerData(
                gameType.getBoardSize(),
                decoder.encode(game.getBoardAsString()),
                player.getScore(),
                game.getMaxScore(),
                game.getCurrentScore(),
                player.getCurrentLevel() + 1,
                player.getMessage()));
      }

      screenSender.sendUpdates(map);

      for (int index = 0; index < players.size(); index++) {
        Player player = players.get(index);
        Game game = games.get(index);
        try {
          String board = game.getBoardAsString().replace("\n", "");

          if (logger.isDebugEnabled()) {
            logger.debug(String.format("Sent for player '%s' board \n%s", player, board));
          }

          controllers.get(index).requestControl(player, board);
        } catch (IOException e) {
          logger.error(
              "Unable to send control request to player "
                  + player.getName()
                  + " URL: "
                  + player.getCallbackUrl(),
              e);
        }
      }
    } catch (Error e) {
      e.printStackTrace();
      logger.error("nextStepForAllGames throws", e);
    } finally {
      lock.writeLock().unlock();
    }
  }
Пример #4
0
	public String getDeathmatchScoreboardMessage( GameObject victim, GameObject killer, boolean inIntermission ) 
	{
		int xOffset, statHeader, statCaps, headerIndex;
		String s;
		Team otherTeam;
		
		otherTeam   = ( this == TEAM1 ? TEAM2 : TEAM1 );
		xOffset     = ( this == TEAM1 ? 0 : 160 );
		statHeader  = ( this == TEAM1 ? STAT_CTF_TEAM1_HEADER          : STAT_CTF_TEAM2_HEADER          );
		headerIndex = ( this == TEAM1 ? Engine.getImageIndex("ctfsb1") : Engine.getImageIndex("ctfsb2") );
		statCaps    = ( this == TEAM1 ? STAT_CTF_TEAM1_CAPS            : STAT_CTF_TEAM2_CAPS            );

		// display our teamheader
		victim.fEntity.setPlayerStat( statHeader, (short)headerIndex );	

/*		// if during intermission, we must blink our header if we're the winning team (or tie)
		if ( inIntermission && ((int)Game.getGameTime()%2 == 0 ) )	// blink every second
		{
			if ( this.getCaptures() > otherTeam.getCaptures() )
				victim.fEntity.setPlayerStat( statHeader, (short)0 );	
			// Capture tie, check total frags
			else if ( this.getScore() >= otherTeam.getScore() )
				victim.fEntity.setPlayerStat( statHeader, (short)0 );	
		}
*/
		s = "if " + statHeader + " xv " + (8+xOffset) + " yv 8 pic " + statHeader + " endif " +
			"xv " + (40+xOffset) + " yv 28 string \"" + getScore() + "/" + fCaptures + "\" " +
			"xv " + (98+xOffset) + " yv 12 num 2 " + statCaps + " ";

		// TODO: sort players by score
		Player[] players = getPlayers();
	/*	int begin = 0;
		int i     = begin;
		while ( i < players.length-1 )
		{
			if ( players[i].getScore() < players[i+1].getScore() )
			{
				Player dummy = players[i];
				players[i]   = players[i+1];
				players[i+1] = dummy;
			}
			if ( i == players.length-2 )
				i = ++begin;
		}
*/
		for ( int i=0; i<8 && i<players.length; i++ )
		{
			Player p    = players[i];
			int    ping = Math.min( p.fEntity.getPlayerPing(), 999 );

			s += "ctf " + xOffset + " " + (42+i*8) + " " + p.fEntity.getPlayerNum() + " " +
			     p.getScore() + " " +
				 ping + " ";

			GenericFlag flag = (GenericFlag)p.getInventory( "flag" );

			if ( flag != null )	// flag IS other teams flag...
			{
				s += "xv " + (56+xOffset) + " picn " + flag.getSmallIconName() + " ";
			}
		}

		if ( players.length > 8 )
		{
			s += "xv " + (8+xOffset) + " yv " + (42+8*8) + " string \"...and " + (players.length-8) + " more\" ";
		}

		return s;
		
	}
Пример #5
0
 public int compare(Player p1, Player p2) {
   if (p1.getScore() > p2.getScore()) return +1;
   else if (p1.getScore() == p2.getScore() && p1.getName().equalsIgnoreCase(p2.getName()))
     return 0;
   else return -1;
 }
Пример #6
0
 @Override
 public int compare(Player p1, Player p2) {
   return p1.getScore() - p2.getScore();
 }