made everything use inheritance instead of whatever we were doing before.

This commit is contained in:
Vikram
2019-03-19 17:14:42 -06:00
parent 0f9ef34f54
commit 2bc96e5d07
11 changed files with 459 additions and 585 deletions

View File

@@ -10,39 +10,28 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class LoanSharkGUI {
private Player player;
/**
* setter method that takes in a Player object as an argument.
*
* @param player object of the class Player
*/
public void setPlayer(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/**
* getter method for obtaining a player object.
*
* @return returns player object
*/
public Player getPlayer() {
Player playerDummy = new Player(player);
return playerDummy;
}
public class LoanSharkGUI extends Player {
/**
* Class Constructor that takes in a type player as a parameter
* <p>
* //* @param player object of the class Player
*
* @param player object of the class Player
*/
public LoanSharkGUI(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
setPlayer(playerDummy);
}
/**
* This methods purpose is to loan the player the funds it wants
* or pay its outstanding debts. The method prompts the user if they
* would like to borrow money or repay. depending on what the player chooses
* the corresponding loop is evoked. The player can only be loaned 2 times the
* money they have minus the debt if their debt exceeds the cash balance, the loan
* cannot be given.
*
* @param primaryStage the stage upon which the GUI will be imposed
*/
public Stage initializeLoanShark(Stage primaryStage) {
primaryStage.setTitle("Loan Shark");
@@ -53,9 +42,9 @@ public class LoanSharkGUI {
VBox vbx1 = new VBox(10);
//Declaring all Variables
Label l1 = new Label("Player: " + player.getName());
Label l2 = new Label("Current Debt " + player.getDebt());
Label l4 = new Label("Current cash: " + player.getMoney());
Label l1 = new Label("Player: " + getName());
Label l2 = new Label("Current Debt " + getDebt());
Label l4 = new Label("Current cash: " + getMoney());
Label l3 = new Label("Enter Amount: ");
Label l5 = new Label(" ");
@@ -96,10 +85,10 @@ public class LoanSharkGUI {
try {
int loanAsk = Integer.parseInt(txtField1.getText());
if (loanAsk <= 2 * (player.getMoney() - player.getDebt()) && loanAsk >= 0) {
player.setDebt(player.getDebt() + loanAsk);
player.setMoney(player.getMoney() + loanAsk);
l4.setText("Current cash: " + player.getMoney());
if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) {
setDebt(getDebt() + loanAsk);
setMoney(getMoney() + loanAsk);
l4.setText("Current cash: " + getMoney());
} else if (loanAsk < 0) {
l5.setText("Sorry you cannot enter negative numbers");
}
@@ -108,7 +97,7 @@ public class LoanSharkGUI {
}
l2.setText("Debt: " + player.getDebt());
l2.setText("Debt: " + getDebt());
} catch (Exception e) {
l5.setText("Please enter a valid value");
}
@@ -121,26 +110,26 @@ public class LoanSharkGUI {
// Set the event handler when the withdraw button is clicked
b2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
public void handle(ActionEvent event) {
try {
int returnAsk = Integer.parseInt(txtField1.getText());
if (returnAsk > player.getDebt()) {
if (returnAsk > getDebt()) {
l5.setText("You dont need to return that much");
}
else if (returnAsk <= player.getDebt() && returnAsk >= 0 && player.getMoney() >= returnAsk) {
player.setDebt(player.getDebt() - returnAsk);
player.setMoney(player.getMoney() - returnAsk);
l4.setText("Current cash: " + player.getMoney());
else if (returnAsk <= getDebt() && returnAsk >= 0 && getMoney() >= returnAsk) {
setDebt(getDebt() - returnAsk);
setMoney(getMoney() - returnAsk);
l4.setText("Current cash: " + getMoney());
}
else if(player.getMoney() < returnAsk) {
l5.setText("Look " + player.getName() + ", you are being cheap!");
else if(getMoney() < returnAsk) {
l5.setText("Look " + getName() + ", you are being cheap!");
}
else {
l5.setText("Sorry you cannot return a negative amount");
}
l2.setText("Debt: " + player.getDebt());
l2.setText("Debt: " + getDebt());
}
catch (Exception e) {
l5.setText("Please enter a valid value");
@@ -152,7 +141,7 @@ public class LoanSharkGUI {
b3.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
TaipanShopGUI shopGUI = new TaipanShopGUI(player);
TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer());
shopGUI.initializeShop(primaryStage);
primaryStage.show();
}
@@ -169,20 +158,10 @@ public class LoanSharkGUI {
public void start(Stage primaryStage) {
LoanSharkGUI loan = new LoanSharkGUI(player);
LoanSharkGUI loan = new LoanSharkGUI(getPlayer());
loan.initializeLoanShark(primaryStage);
primaryStage.show();
}
/**
* This methods purpose is to loan the player the funds it wants
* or pay its outstanding debts. The method prompts the user if they
* would like to borrow money or repay. depending on what the player chooses
* the corresponding loop is evoked. The player can only be loaned 2 times the
* money they have minus the debt id their debt exceeds the cash balance, the loan
* cannot be given.
*/
}