From Botched Cheetah, 6 Years ago, written in Plain Text.
Embed
  1. package run;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5.  
  6. import player.*;
  7. import selectionMenu.*;
  8. import square.*;
  9.  
  10. /**
  11.  * This class holds the "updatePlayerLocation" method, facilitating the player's movement around the Game Board
  12.  * @author Cormac
  13.  *
  14.  */
  15. public class PlayerLocationUpdater {
  16.        
  17.        
  18.         /**
  19.          * This method updates the player location variable, facilitating their changing position on the gameboard as it relates to the Gameboard Arraylist.
  20.          * @param player
  21.          * @param Gameboard
  22.          * @param players
  23.          */
  24.         public static void updatePlayerLocation(Player player, ArrayList<Square> Gameboard, ArrayList<Player> players) {
  25.                 //moving the player through the gameboard
  26.                 int counter = player.getCurrentLocation();
  27.                 int dice = Dice.rollDice();
  28.                 for (int count = 0; count < dice; count++) {
  29.                         counter++;
  30.                         player.setCurrentLocation(player.getCurrentLocation() + 1);
  31.                         if (counter>11) {
  32.                                 player.setCurrentLocation(0);  
  33.                                 Go.payday(player);
  34.                                 counter = 0;
  35.                         }
  36.                 }
  37.                 //Determining what occurs on the square the player has landed on
  38.                 Iterator<Square> determineSquare = Gameboard.iterator();
  39.                 while (determineSquare.hasNext()) {
  40.                         if (determineSquare.next().getName() == SquareNames.FREE_SESSION && Gameboard.get(counter).equals(player.getCurrentLocation())) {
  41.                                 //the player has landed on the Free Session space, and an appropriate message is displayed
  42.                                 determineSquare.next().displaySquare();
  43.                                
  44.                         } else if (determineSquare.next().getName() == SquareNames.GO && Gameboard.get(counter).equals(player.getCurrentLocation())) {
  45.                                 //nothing happens, as the player has already been paid for passing Go above
  46.                         } else { //the player has landed on a computer square, now we determine if the current player owns the square, if another player owns it or whether it is owned at all.
  47.                                 Computer computer = (Computer) determineSquare.next();
  48.                                 if (computer.getOwner().isEmpty()) {
  49.                                         //computer square is empty, current player is offered opportunity to buy the square
  50.                                         mhPackage.ComputerManager.buyComputer(player, computer, players);
  51.                                 } else if (computer.getOwner().equals(player.getPlayerName())) {
  52.                                         //as this is handled in the post selection menu, the player is simply moved there
  53.                                 } else {
  54.                                         //the player has landed on a computer square owned by another player
  55.                                         mhPackage.ComputerManager.paySessionPrice(player, players, Gameboard);
  56.                                         for (Player element : players) {
  57.                                                 if (element.getPlayerName() == computer.getOwner()) {
  58.                                                         player.setCurrentBalance(player.getCurrentBalance() - computer.getSessionPrice());
  59.                                                         element.setCurrentBalance(element.getCurrentBalance() + computer.getSessionPrice());
  60.                                                         if (player.getCurrentBalance() < 1) {
  61.                                                                 EndGame.gameEnder(player, players);
  62.                                                         }
  63.                                                 }
  64.                                         }
  65.                                 }
  66.                         }
  67.                
  68.                 }
  69.         }
  70.  
  71. }
  72.  
  73.