mirror of
https://github.com/Noratrieb/ClickerGameSwing.git
synced 2026-01-14 15:45:04 +01:00
better (formatter still broken)
This commit is contained in:
parent
94a169b421
commit
7924f2aa7c
3 changed files with 25 additions and 10 deletions
|
|
@ -5,7 +5,7 @@ public class ClickerPresenter {
|
|||
|
||||
public static final int TARGET_FPS = 30;
|
||||
|
||||
public static final int MAX_UPGRADE_FACTOR = 100000;
|
||||
public static final int MAX_UPGRADE_FACTOR = 1000;
|
||||
|
||||
private final ClickerView clickerView;
|
||||
private final ClickerModel clickerModel;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class LargeFormatter {
|
||||
|
||||
|
|
@ -57,14 +58,14 @@ public class LargeFormatter {
|
|||
}
|
||||
|
||||
suffixSize++;
|
||||
number = number.divide(THOUSAND);
|
||||
number = number.divide(THOUSAND, 0 , RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
if (scientific) {
|
||||
int exp = 3 * suffixSize;
|
||||
while (number.compareTo(TEN) >= 0) {
|
||||
exp++;
|
||||
number = number.divide(TEN);
|
||||
number = number.divide(TEN, 0 , RoundingMode.HALF_UP);
|
||||
}
|
||||
return String.format("%.2fE%d", number, exp);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
import org.w3c.dom.ls.LSOutput;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class UpgradePanel extends JPanel {
|
||||
|
||||
|
|
@ -26,7 +30,7 @@ public class UpgradePanel extends JPanel {
|
|||
private final ClickerPresenter presenter;
|
||||
private final LargeFormatter lf = new LargeFormatter();
|
||||
|
||||
private String upgradeButtonText = "";
|
||||
private BigDecimal upgradeCost = BigDecimal.ZERO;
|
||||
|
||||
public UpgradePanel(String name, double baseCost, double costMultiplier, double baseGain, ClickerPresenter presenter) {
|
||||
add(mainPanel);
|
||||
|
|
@ -54,7 +58,8 @@ public class UpgradePanel extends JPanel {
|
|||
}
|
||||
|
||||
public void refresh() {
|
||||
upgradeButton.setEnabled(presenter.getNicolas().compareTo(calculateExp(cost, costMultiplier, presenter.getUpgradeFactor())) >= 0);
|
||||
|
||||
upgradeButton.setEnabled(presenter.getNicolas().compareTo(upgradeCost) >= 0);
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (gain.compareTo(BigDecimal.ZERO) > 0) {
|
||||
|
|
@ -70,9 +75,7 @@ public class UpgradePanel extends JPanel {
|
|||
|
||||
if (gain.compareTo(inverseFrameDeltaTime) > 0) {
|
||||
//normal: dt/tpn inverse: gain/idt
|
||||
System.out.println(inverseFrameDeltaTime + " " + gain);
|
||||
BigDecimal missedNicolas = gain.divide(inverseFrameDeltaTime, 0, RoundingMode.HALF_UP); /*frameDeltaTime / timePerNicolas*/
|
||||
System.out.println(missedNicolas);
|
||||
presenter.addNicolas(missedNicolas);
|
||||
} else {
|
||||
presenter.addNicolas(1);
|
||||
|
|
@ -85,7 +88,10 @@ public class UpgradePanel extends JPanel {
|
|||
levelLabel.setText("Level: " + level);
|
||||
gainLabel.setText(lf.formatBigNumber(gain) + " Nicolas");
|
||||
|
||||
upgradeButton.setText(upgradeButtonText);
|
||||
upgradeButton.setText(String.format("%,dx Upgrade: %s Nicolas",
|
||||
presenter.getUpgradeFactor(), lf.formatBigNumber(upgradeCost)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
private BigDecimal calculateExp(BigDecimal c, BigDecimal fac, long amount) {
|
||||
|
|
@ -105,7 +111,15 @@ public class UpgradePanel extends JPanel {
|
|||
}
|
||||
|
||||
public void recalculateUpgradeButtonText() {
|
||||
upgradeButtonText = String.format("%,dx Upgrade: %s Nicolas",
|
||||
presenter.getUpgradeFactor(), lf.formatBigNumber(calculateExp(cost, costMultiplier, presenter.getUpgradeFactor())));
|
||||
Thread t = new Thread(() -> {
|
||||
setUpgradeCost(calculateExp(cost, costMultiplier, presenter.getUpgradeFactor()));
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void setUpgradeCost(BigDecimal cost) {
|
||||
synchronized (this) {
|
||||
upgradeCost = cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue