Hier läuft so einiges falsch!
Warum sollte der Updater von Main ableiten? Du brauchst eher die Referenz von Main im Updater:
[code=java]public class Main extends Application {
private Button geldButton;
private Text event;
private Button kaufButton1;
private Game game;
private Text moneyText;
private VBox layout1;
private boolean kaufButtons[] = new boolean[1];
private static boolean ingame;
@Override
public void start(Stage window) {
game = new Game();
event = new Text();
window.setTitle("Mini Game by SoT Burst");
layout1 = new VBox(20);
setMoneyText(new Text());
getMoneyText().autosize();
getMoneyText().setX(230);
getMoneyText().setText("" + game.getMoney());
geldButton = new Button();
geldButton.setText("GELD");
geldButton.setOnAction(e -> {
game.addMoney(game.getMoneyPerClick());
});
kaufButton1 = new Button();
kaufButton1.setText("Klickupgrade");
kaufButton1.setOnAction(e -> {
game.buy(0);
getMoneyText().setText("Geld: " + game.getMoney() + " Euro");
});
getLayout1().getChildren().add(getMoneyText());
getLayout1().getChildren().add(event);
getLayout1().getChildren().add(geldButton);
Updater updater = new Updater(this);
Thread u = new Thread(updater);
Scene home = new Scene(getLayout1(), 1280, 720);
home.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
window.setScene(home);
window.show();
u.start();
}
public static void main(String[] args) {
ingame = true;
launch(args);
ingame = false;
}
public Button getKaufButton(int i) {
if (i == 1) {
return kaufButton1;
}
return null;
}
public boolean getIngame() {
return ingame;
}
public Button getGeldButton() {
return geldButton;
}
public boolean getButtonStatus(int i) {
return kaufButtons[i];
}
public void setButtonStatus(int i, boolean b) {
kaufButtons[i] = b;
}
public Game getGame() {
return game;
}
public VBox getLayout1() {
return layout1;
}
public Text getMoneyText() {
return moneyText;
}
public void setMoneyText(Text moneyText) {
this.moneyText = moneyText;
}
}
class Game {
private BigInteger money;
private BigInteger moneyPerSecond;
private BigInteger moneyMultiplier;
private BigInteger moneyClickMultiplier;
private BigInteger moneyPerClick;
private static int length = 1;
private static BigInteger[] startingCosts = new BigInteger[length];
private BigInteger[] costs = startingCosts;
private BigInteger[] levels = new BigInteger[length];
public Game() {
levels[0] = BigInteger.ZERO;
startingCosts[0] = new BigInteger("25");
money = BigInteger.ZERO;
moneyPerSecond = BigInteger.ZERO;
moneyMultiplier = BigInteger.ONE;
moneyPerClick = BigInteger.ONE;
moneyClickMultiplier = BigInteger.ONE;
}
public void buy(int i) {
if (getMoney().compareTo(getCosts(i)) >= 0) {
setMoney(getMoney().subtract(getCosts(i)));
costs[i] = costs[i].multiply(new BigInteger("12")).divide(BigInteger.TEN);
levels[i] = levels[i].add(BigInteger.ONE);
moneyPerClick = moneyPerClick.add(BigInteger.ONE);
}
}
public BigInteger getMoney() {
return money;
}
public void setMoney(BigInteger money) {
this.money = money;
}
public void addMoney(BigInteger money) {
this.money = this.money.add(money);
}
private void setMoneyPerSecond(BigInteger moneyPerSecond) {
this.moneyPerSecond = moneyPerSecond;
}
public BigInteger getMoneyPerSecond() {
return moneyPerSecond;
}
public void setMoneyPerClick(BigInteger moneyPerClick) {
this.moneyPerClick = moneyPerClick;
}
public BigInteger getMoneyPerClick() {
return moneyPerClick;
}
public BigInteger getMoneyMultiplier() {
return moneyMultiplier;
}
public void setMoneyMultiplier(BigInteger moneyMultiplier) {
this.moneyMultiplier = moneyMultiplier;
}
public BigInteger getCosts(int i) {
return costs[i];
}
public static int getUpgradeNumber() {
return length;
}
public String getLevel(int i) {
return "" + levels[i];
}
}
class Updater implements Runnable {
long timer;
boolean ingame;
Main main;
public Updater(Main main) {
this.main = main;
}
@Override
public void run() {
while (main.getIngame()) {
updater();
}
}
private void updater() {
timer = System.currentTimeMillis();
if (main.getGame().getMoney().compareTo(main.getGame().getCosts(0)) < 0) {
main.getLayout1().getChildren().remove(main.getKaufButton(1));
main.setButtonStatus(0, false);
}
main.getMoneyText().setText("Geld: " + main.getGame().getMoney() + " Euro");
if (main.getGame().getMoney().compareTo(main.getGame().getCosts(0)) >= 0 && !main.getButtonStatus(1)) {
main.getLayout1().getChildren().add(main.getKaufButton(1));
main.setButtonStatus(1, true);
}
while (timer + 100 > System.currentTimeMillis()) {
}
}
}[/code]
Du solltest nochmal mit Grundlagen beginnen! Ein paar Tutorials ansehen.
Tipps:
- Arbeite mit fxml und Controller
- Nimm Timelines oder Tasks als Thread (JavaFX-Threads müssen anders behandelt werden)
- Schau dir nochmal static/non-static an
- Schau dir nochmal die Verarbeitung von Arrays an
- Schau dir Bindings und Properties in JavaFX an
- ...
Erst die Punkte abarbeiten, dann nochmal an dem Spiel versuchen.