Example #1
0
  @Override
  public Move getMove(Gameboard gameboard, Opponent opponent, Player player)
      throws NoItemException, MapOutOfBoundsException {
    // System.out.format("Turn NUm:%d\n", gameboard.getCurrentTurnNumber());
    // Turret t = gameboard.getTurrets().get(2);
    // System.out.format("Turret: cool:%d fire:%d
    // isFiringNextTurn:%b\n",t.getCooldownTime(),t.getFireTime(),t.isFiringNextTurn());
    buildBoardValue(gameboard, player, opponent);
    int maxVal = highestValueTile(gameboard);
    // System.out.format("maxVal:%d\n", maxVal);
    Move myMove =
        bfs(
            gameboard,
            player,
            opponent,
            player.getX(),
            player.getY(),
            player.getDirection(),
            maxVal);
    return myMove;
    // }

    // System.out.println("x:"+player.getX()+" y:"+player.getY()+" safe:
    // "+bulletSafe(gameboard,player.getX(),player.getY()));

  }
Example #2
0
 private int getPlayersMinScore() {
   int result = 0;
   for (Player player : players) {
     result = Math.min(player.getScore(), result);
   }
   return result;
 }
Example #3
0
	public void addPlayer( Player p )
	{
		if (fPlayers.contains(p))
			return; // already joined this team
			
		fPlayers.addElement( p );

		// make sure we find out if the team member disconnects
		p.addPlayerStateListener(this);

		// act as a damage filter for this member
		p.addDamageListener(this);

		// assign new skin
		assignSkinTo( p );
		Object[] args = {p.getName(), fTeamIndex};
		Game.localecast("q2java.ctf.CTFMessages", "join_team", args, Engine.PRINT_HIGH);	
		
		//update players stats that he joined this team (the yellow line around team-icon)
		int index1 = ( this == Team.TEAM1 ? STAT_CTF_JOINED_TEAM1_PIC : STAT_CTF_JOINED_TEAM2_PIC );
		int index2 = ( this == Team.TEAM1 ? STAT_CTF_JOINED_TEAM2_PIC : STAT_CTF_JOINED_TEAM1_PIC );
		int picnum = Engine.getImageIndex("i_ctfj");
		p.fEntity.setPlayerStat( index1, (short)picnum );
		p.fEntity.setPlayerStat( index2, (short)0      );
	}
Example #4
0
  public void giveItems(int itemId, long count, Element element, int power) {
    Player player = getPlayer();
    if (player == null) {
      return;
    }

    if (count <= 0) {
      count = 1;
    }

    // Get template of item
    ItemTemplate template = ItemHolder.getInstance().getTemplate(itemId);
    if (template == null) {
      return;
    }

    for (int i = 0; i < count; i++) {
      ItemInstance item = ItemFunctions.createItem(itemId);

      if (element != Element.NONE) {
        item.setAttributeElement(element, power);
      }

      // Add items to player's inventory
      player.getInventory().addItem(item);
    }

    player.sendPacket(SystemMessage2.obtainItems(template.getItemId(), count, 0));
    player.sendChanges();
  }
 public String[] getPropertyName() {
   String[] save = new String[x.getProperties().size()];
   for (int i = 0; i < x.getProperties().size(); i++) {
     save[i] = (Game.SlotsList[x.getProperties().get(i)]).getName();
   }
   return save;
 }
 private void displayCommand(Command c, Player p) {
   p.sendMessage("-------------Command Arguments---------------");
   p.sendMessage("--------------------------------------------");
   for (Argument arg : c.listArguments()) {
     p.sendMessage(arg.toString());
   }
 }
Example #7
0
 // checks to see who won the game
 public void whoWon(Player me, Player opp) {
   int myPieces = countPieces(me);
   int oppPieces = countPieces(opp);
   if (myPieces > oppPieces) {
     System.out.println("C " + me.getPlayerColor() + " has won the game with: " + myPieces);
   } else System.out.println("C " + opp.getPlayerColor() + " has won the game with: " + oppPieces);
 }
  public void summarizePlayer(int playerID) {
    Player p = players.get(playerID);
    Map<Integer, Playing> playersGames = p.games;
    Set<Integer> gamesKeys = playersGames.keySet();
    Integer[] gameIDs = gamesKeys.toArray(new Integer[gamesKeys.size()]);

    System.out.println("Player: " + p);
    System.out.println("Total Gamerscore: " + p.getGamerScore());
    System.out.printf(
        "%4s %-20s %-16s %-16s %-16s \n", " ", "Game", "Achievements", "Gamerscore", "IGN");
    System.out.println(
        "--------------------------------------------------------------------------------");
    for (int i = 0; i < gameIDs.length; i++) {
      Game g = games.get(gameIDs[i]);
      Playing playerInfo = p.games.get(gameIDs[i]);
      int nPlayerAchieve = playerInfo.achievements.size();
      int nTotalAchieve = g.achievements.size();
      System.out.printf(
          "%4s %-20s %-16s %-16s %-16s \n",
          (i + 1 + "."),
          g,
          (nPlayerAchieve + "/" + nTotalAchieve),
          (playerInfo.getPoints() + " pts"),
          playerInfo.ign);
    }

    System.out.printf("\n%4s %-16s %-16s \n", " ", "Friend", "Gamerscore");
    System.out.println(
        "--------------------------------------------------------------------------------");
    printSortedPlayers(p.friends);
  }
 public void checkEnemyCollision() {
   for (Enemy e : enemyList) {
     if (e.getOnScreen()) { // can be removed later on
       // goes through all the enemies and checks if they collide
       if (e.checkCollision(e.getPics().get(e.getCounter()), player1)) {
         if (player1.getInvi() == false) {
           // If the player is not invisble then you get spiked.
           if (player1.getVelocity() > 0) { // if the player hits it from the bottom
             player1.setSpikeVelo();
             loseCoins();
           } else {
             player1.setVelo(
                 50); // if the player is on top instead the player bounces off the enemy
             if (musicOn) {
               bounce.play();
             }
           }
         }
         eRemove.add(e); // once we hit, we remove the enemy
       }
     } else {
       eRemove.add(e); // if the enemy goes of the screen, we remove
     }
   }
   for (Enemy e : eRemove) {
     poofList.add(new Poof(e.getX(), e.getY(), 1)); // removes all the enemies
     enemyList.remove(e);
   }
   eRemove = new ArrayList<Enemy>();
 }
Example #10
0
 /*
 public void updateCollision(Player b) {
  Point topLeft = new Point();
  topLeft.x = (int) b.getPosition().getX();
  topLeft.y = (int) b.getPosition().getY();
  Point topRight = new Point();
  topRight.x = (int) (b.getPosition().getX() + b.RADIUS * 2);
  topRight.y = (int) b.getPosition().getY();
  Point bottomLeft = new Point();
  bottomLeft.x = (int) b.getPosition().getX();
  bottomLeft.y = (int) (b.getPosition().getY() + b.RADIUS * 2);
  Point bottomRight = new Point();
  bottomRight.x = (int) (b.getPosition().getX() + b.RADIUS * 2);
  bottomRight.y = (int) (b.getPosition().getY() + b.RADIUS * 2);
  if (poly.contains(topLeft) || poly.contains(topRight) || poly.contains(bottomRight) || poly.contains(bottomLeft)) {
   reflect (b);
   System.out.println("TRIGGERED");
  }
 }
 */
 public void reflect(Player b) {
   double barrierSlope = ((double) (y1 - y2)) / ((double) (x1 - x2));
   if (barrierSlope == 1) {
     Point p = new Point();
     p.x = (int) b.getVel().getY();
     p.y = (int) b.getVel().getX();
   }
   if (Math.abs(barrierSlope) < 1) {
     System.out.print("shallow");
     double newX = (1 - barrierSlope) * b.getVel().getX();
     double newY = -1 * (b.VEL * 2) - newX;
     Point p = new Point();
     p.x = (int) newX;
     p.y = (int) newY;
     b.setVel(p);
   }
   if (Math.abs(barrierSlope) > 1) {
     System.out.println("steep");
     double newY = (1 - 1 / barrierSlope) * b.getVel().getY();
     double newX = -1 * (b.VEL * 2) - newY;
     Point p = new Point();
     p.x = (int) newX;
     p.y = (int) newY;
     b.setVel(p);
   }
 }
Example #11
0
  private void setupRound() // sets up each round right before game time
      {
    reset(); // resets and deals the card related variables
    skippedPlayers = 0; // resets the skipped players
    if (firstRound) // if this is the first round -- find the 3 of clubs holder
    {
      firstRound = false;
      currentPlayer = findThreeClubs();
    } else // if not -- trade the cards and set the first player as the president
    {
      trade(players.get(findPresident()), players.get(findScum()));
      trade(players.get(findPresident()), players.get(findScum()));
      trade(players.get(findVice()), players.get(findViceScum()));
      currentPlayer = findPresident();
      // System.out.println(players.get(currentPlayer));
    }

    /*
    for (Player p : players)
    {
        System.out.println(p);
        System.out.println();
    }
    */

    for (Player p : players) // reset the rank of each player
    {
      p.setRank(-10);
    }
  }
 public void scrollEnemies() {
   for (Enemy i : enemyList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
     i.setYPos(i.getYPos() + (int) (player1.getVelocity() * 0.3));
     i.setYMax(i.getYMax() + (int) (player1.getVelocity() * 0.3));
   }
 }
 public void scrollCoins() {
   for (Coin i : coinList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
     i.setYPos(i.getYPos() + (int) (player1.getVelocity() * 0.3));
     i.setYMax(i.getYMax() + (int) (player1.getVelocity() * 0.3));
   }
 }
 public void checkStarCollision() {
   for (Star s : starList) {
     if (s.getOnScreen()) { // if the star is on the screen we need to check if player collides
       if (s.checkCollision(
           s.getPics().get(s.getCounter()),
           player1)) { // if the player collides with the star we remove it then change the
         // velosity to the distance that the star provides
         sRemove.add(s); // remove star once you collide with it
         player1.setVelo(s.getDist()); // changes the velocity
         player1.setInvi(true); // sets the player invisble for a few seconds
         score += s.getPoints(); // points increase by the star type
         if (musicOn) {
           starSound.play(); // playthe star sound
         }
       }
     } else {
       sRemove.add(s); // remove the star if its not on the screen
     }
   }
   for (Star s : sRemove) {
     poofList.add(new Poof(s.getX(), s.getY(), s.getNum() + 3)); // make the poof effect
     starList.remove(s);
   }
   sRemove = new ArrayList<Star>();
 }
Example #15
0
 /** Используется для однодневных квестов */
 public void exitCurrentQuest(Quest quest) {
   Player player = getPlayer();
   exitCurrentQuest(true);
   quest.newQuestState(player, Quest.DELAYED);
   QuestState qs = player.getQuestState(quest.getClass());
   qs.setRestartTime();
 }
Example #16
0
  // generates all possible moves for player passed, gives them a rating, and sorts them
  public ArrayList<Move> generateMoves(Player player) {
    int playerNumber = player.getPlayerNumber();
    ArrayList<Move> moveList = new ArrayList<>();

    for (int i = 0; i < board.length; i++) {
      if (isValidMove(playerNumber, i)) {
        Move move = new Move(i);
        if (CORNERS.contains(move.getMove())) {
          move.setValue(500);
        } else if (AMOVES.contains(move.getMove())) {
          move.setValue(250);
        } else if (BMOVES.contains(move.getMove())) {
          move.setValue(100);
        } else if (CMOVES.contains(move.getMove())) {
          move.setValue(50);
        } else move.setValue(-5);

        moveList.add(move);
      }
    }

    // in case of no moves, add pass move
    if (moveList.size() > 0) {
      Collections.sort(moveList, new MoveComparator());
      Collections.reverse(moveList);
    } else {
      String pass = "" + player.getPlayerColor();
      Move move = new Move(pass);
      moveList.add(move);
    }

    player.assignPossibleMoves(moveList);
    return moveList;
  }
Example #17
0
 @SuppressWarnings("unchecked")
 @Override
 public int loop() {
   synchronized (lock) {
     try {
       if (!ui.isVisible()) handler.stopMod(getName());
       World world = minecraft.getWorld();
       JTable list = ui.getList();
       DefaultTableModel model = (DefaultTableModel) list.getModel();
       TableRowSorter<TableModel> sorter = (TableRowSorter<TableModel>) list.getRowSorter();
       if (world != null) {
         Player currentPlayer = minecraft.getPlayer();
         int playerX = (int) java.lang.Math.round(currentPlayer.getX());
         int playerY = (int) java.lang.Math.round(currentPlayer.getY());
         int playerZ = (int) java.lang.Math.round(currentPlayer.getZ());
         ArrayList<Block> blocks = new ArrayList<Block>();
         for (int x = playerX - radius; x < playerX + radius; x++)
           for (int y = playerY - radius; y < playerY + radius; y++)
             for (int z = playerZ - radius; z < playerZ + radius; z++)
               if (world.getBlockIDAt(x, y, z) == blockID) blocks.add(new Block(x, y, z));
         label:
         for (int row = 0; row < model.getRowCount(); row++) {
           int x = (Integer) model.getValueAt(row, 1);
           int y = (Integer) model.getValueAt(row, 2);
           int z = (Integer) model.getValueAt(row, 3);
           for (Block block : blocks) {
             if (x == block.getX() && y == block.getY() && z == block.getZ()) {
               model.setValueAt(getDistanceTo(x, y, z, currentPlayer), row, 0);
               continue label;
             }
           }
           model.removeRow(row);
         }
         label:
         for (Block block : blocks) {
           for (int row = 0; row < model.getRowCount(); row++) {
             int x = (Integer) model.getValueAt(row, 1);
             int y = (Integer) model.getValueAt(row, 2);
             int z = (Integer) model.getValueAt(row, 3);
             if (x == block.getX() && y == block.getY() && z == block.getZ()) continue label;
           }
           model.addRow(
               new Object[] {
                 getDistanceTo(block.getX(), block.getY(), block.getZ(), minecraft.getPlayer()),
                 block.getX(),
                 block.getY(),
                 block.getZ()
               });
         }
         sorter.sort();
         list.repaint();
       } else {
         for (int i = model.getRowCount() - 1; i >= 0; i--) model.removeRow(i);
       }
     } catch (Exception exception) {
     }
   }
   return 500;
 }
 public void keyReleased(KeyEvent evt) {
   keys[evt.getKeyCode()] = false;
   // reset the counters for for the sprite s
   player1.resetCounter();
   if (!player1.getPower().equals("Balloon")) {
     player1.resetPicCounter();
   }
 }
Example #19
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);
   }
 }
 public static boolean validateName(String name) { // to make sure nobody has the same name
   for (Player p : game.getPlayers()) {
     if (name.equals(p.getName())) { // muy mal
       return false;
     }
   }
   return true;
 }
 public boolean spawnSnailRider(Player player) {
   if (getSpawnCount("SnailRider") < 1) {
     registry.showMessage("Success", "Suddenly, a wild Snail Rider appears!");
     spawn("SnailRider", "Roaming", player.getMapX(), player.getMapY());
     return true;
   }
   return false;
 }
 public boolean spawnBossOrc(Player player) {
   if (getSpawnCount("BossOrc") < 1) {
     registry.showMessage("Success", "Beware, Melvin lurks nearby...");
     spawn("BossOrc", "Roaming", player.getMapX(), player.getMapY());
     return true;
   }
   return false;
 }
Example #23
0
 /** Rearranges the players in the player array based on the comparator. */
 public void arrangePlayers() {
   for (Player p : players) {
     p.refreshScore();
     p.setIsLast(false);
   }
   Arrays.sort(players, new playerComparator());
   players[players.length - 1].setIsLast(true);
 }
Example #24
0
 private Player getPlayer(String playerName) {
   for (Player player : players) {
     if (player.getName().equals(playerName)) {
       return player;
     }
   }
   return null;
 }
Example #25
0
 private void assignCards() {
   player.clearCards();
   dealer.clearCards();
   for (int i = 0; i < 3; ++i) {
     player.assignCard(genNewCard());
     dealer.assignCard(genNewCard());
   }
 }
Example #26
0
  @Override
  public void showGame(
      Game game, Set<Location<Integer>> blockedLocations, Map<Room, Weapon> weaponLocations) {
    Board board = game.board;

    char[][] buffer = new char[2 * (board.width + 1)][2 * (board.height + 1)];
    for (char[] line : buffer) {
      Arrays.fill(line, ' ');
    }

    for (int x = 0; x < board.width; x++) {
      for (int y = 0; y < board.height; y++) {
        // The actual tile is at buffer[2x + 1][2y + 1]
        // Walls: above is [2x + 1][2y], left is [2x][2y + 1]

        if (board.hasWallBetween(
            new Location<>(x, y), new Location<>(x, y - 1))) { // if there's a wall above the tile.
          buffer[2 * x + 1][2 * y] = '-';
        }
        if (board.hasWallBetween(
            new Location<>(x, y),
            new Location<>(x - 1, y))) { // if there's a wall to the left of the tile.
          buffer[2 * x][2 * y + 1] = '|';
        }
      }
    }
    for (int x = 0; x < board.width; x++) {
      buffer[2 * x + 1][2 * board.height] = '-';
    }
    for (int y = 0; y < board.height; y++) {
      buffer[2 * board.width][2 * y + 1] = '|';
    }

    for (Room room : Room.values()) {
      Location<Float> centre = board.centreLocationForRoom(room);
      String name = room.shortName();

      int startX = 2 * centre.x.intValue() + 1 - name.length() / 2;
      int y = 2 * centre.y.intValue() + 1;

      for (int i = 0; i < +name.length(); i++) {
        buffer[startX + i][y] = name.charAt(i);
      }
    }

    for (Player player : game.allPlayers) {
      CluedoCharacter character = player.character;
      Location<Integer> location = player.location();
      buffer[2 * location.x + 1][2 * location.y + 1] = this.asciiIconForCharacter(character);
    }

    for (int y = 0; y < 2 * (board.height + 1); y++) {
      for (int x = 0; x < 2 * (board.width + 1); x++) {
        this.out.print(buffer[x][y]);
      }
      this.out.print('\n');
    }
  }
Example #27
0
 private int getScoreForEndPosition(Player player) {
   int returnValue = -1;
   if (player.isInStaleMate() || itsBoard.isThirdOccuranceOfPosition()) returnValue = 500;
   else if (player.isInCheckMate()) {
     if (player == itsPlayer) returnValue = 0;
     else returnValue = 1000;
   }
   return returnValue;
 }
Example #28
0
 private double getDistanceTo(double x, double y, double z, Player player) {
   double x2 = player.getX();
   double y2 = player.getY();
   double z2 = player.getZ();
   double xResult = java.lang.Math.pow(java.lang.Math.max(x, x2) - java.lang.Math.min(x, x2), 2);
   double yResult = java.lang.Math.pow(java.lang.Math.max(y, y2) - java.lang.Math.min(y, y2), 2);
   double zResult = java.lang.Math.pow(java.lang.Math.max(z, z2) - java.lang.Math.min(z, z2), 2);
   return java.lang.Math.sqrt(xResult + yResult + zResult);
 }
Example #29
0
 public boolean isDone() // returns if the game is done
     {
   if (!done) // if the game is not done, check if it has ended
   for (Player p : players) // for each player
     if (!p.isDone()) // if the player is not done
       return done; // the game has not ended
   done = true; // else, the game is over
   return done;
 }
Example #30
0
 // Bharat's collision system
 public void bounce(Player b) {
   double trueAngle = Math.atan(b.getVel().getX() / b.getVel().getY());
   double incAngle = trueAngle + angle;
   double newAngle = incAngle + angle + Math.PI;
   Point p = new Point();
   p.x = (int) (b.VEL * Math.cos(newAngle));
   p.y = (int) (b.VEL * Math.sin(newAngle));
   b.setVel(p);
 }