Exemple #1
0
 @Override
 public void payRent(Player player) {
   if (player.getBalance() > getRent()) {
     player.addToBalance(-getRent());
     owner.addToBalance(getRent());
     GUI.showMessage(Texts.getText("husleje") + owner.getName());
     GUI.setBalance(player.getName(), player.getBalance());
     GUI.setBalance(owner.getName(), owner.getBalance());
   } else {
     owner.addToBalance(player.getBalance());
     player.bankrupt();
     GUI.removeAllCars(player.getName());
   }
 }
Exemple #2
0
 @Override
 public void landOnField(Player player) {
   if (super.isOwned() == false) {
     buyField(player);
     GUI.setBalance(player.getName(), player.getBalance());
   } else if (owner.isAlive() == true) {
     if (owner != player) {
       payRent(player);
     }
   }
 }
Exemple #3
0
  public static void spilloop(
      Spiller player, Terning tern, Felt felt, Konto konto, Tur tur, Strings string) {
    if (GUI.getUserButtonPressed(
            player.getNavn() + string.getButtonPress(), string.getButtonPressAnswer())
        .equals(string.getButtonPressAnswer())) {
      GUI.removeAllCars(player.getNavn());
      GUI.setCar(tern.kast() - 1, player.getNavn());
      GUI.showMessage("" + string.getFeltDesc((tern.getVærdi() - 2)));
      int feltværdi = felt.getFeltVærdi((tern.getVærdi() - 2), string);
      if (feltværdi > 0) {
        konto.deposit(feltværdi);
        GUI.setBalance(player.getNavn(), konto.getBeholdning());
        if (konto.getBeholdning() >= 3000) {
          GUI.showMessage(player.getNavn() + string.getWinText());
          if (GUI.getUserButtonPressed(
                  string.getNewGameText(),
                  string.getNewGameTextPositive(),
                  string.getNewGameTextNegative())
              .equals(string.getNewGameTextPositive())) {
            GUI.showMessage(string.getExitMessage());
            System.exit(0);
          } else {
            System.exit(0);
          }
        }
      } else if (feltværdi < 0) {
        if (feltværdi < konto.getBeholdning()) {
          konto.withdraw(-feltværdi);
          GUI.setBalance(player.getNavn(), konto.getBeholdning());
        } else {
          konto.withdraw(konto.getBeholdning());
        }
      }

      if (tern.getVærdi() - 2 != 8) tur.skift();
    }
  }
Exemple #4
0
  public void run() {

    // Set up the game board
    gameboard.setupGuiFields();
    // createCars();

    // Determines the number of players in the game
    numOfPlayers = GUI.getUserInteger(Text.howManyPlayers, 2, 6);
    activePlayers = numOfPlayers;

    // This loop adds the determined number of players to the game
    for (int i = 0; i < numOfPlayers; i++) {
      name[i] = GUI.getUserString(Text.enterName[i]);

      while ((name[i].equals("")) || name[i].equals(" ")) {
        GUI.showMessage(Text.nameInvalid);
        name[i] = GUI.getUserString(Text.enterName[i]);
      }
      for (int j = 1; j <= i; j++) {
        while (name[i].equals(name[i - j])) {
          GUI.showMessage(Text.nameTaken);
          name[i] = GUI.getUserString(Text.enterName[i]);
        }
      }
      player[i] =
          new Player(30000, name[i]); // Player gets a balance and the name chosen by the user
      GUI.addPlayer(
          player[i].getName(),
          player[i].getAccount().getBalance(),
          gameboard.getCar()[i]); // Player is added to board
      GUI.setCar(1, player[i].getName()); // Players car is added to board
    }

    // This loop gives all active players a turn, until only one player is left
    while (activePlayers > 1) {
      for (int i = 0; i < numOfPlayers; i++) {
        playerTurn(player[i]);
        for (int j = 0; j < numOfPlayers; j++)
          GUI.setBalance(
              player[j].getName(),
              player[j].getAccount().getBalance()); // Updates everybody's balance after every turn
        if (activePlayers == 1) break; // Breaks out of the loop, if only one active player is left
      }
      for (int i = 0; i < numOfPlayers; i++) {
        setWinner(player[i]); // Checks if only one player is left, then sets the player as winner
      }
    }
  }
Exemple #5
0
 // Method for the player turn - The player can only use the turn if their balance is not 0
 private void playerTurn(Player player) {
   if (player.getAccount().getBalance() != 0) {
     GUI.showMessage(player.getName() + Text.roll); // The player is asked to roll the dice						
     GUI.removeCar(
         player.getPosition(), player.getName()); // car is removed from previous position
     player.addPosition(dicecup.roll()); // Dice is rolled, and the players position is saved
     GUI.setDice(
         dicecup.getDie1().getLastRoll(),
         dicecup.getDie2().getLastRoll()); // Dice is shown on screen
     GUI.setCar(player.getPosition(), player.getName()); // Car is moved to field
     landedOnField(player); // Runs the operation for the field the player landed on
     GUI.setBalance(
         player.getName(),
         player.getAccount().getBalance()); // Shows current player balance on GUI game board
     if (player.getAccount().getBalance() == 0)
       bankRupt(
           player); // Player is removed from the game if their balance is 0, after their turn.
   }
 }