mirror of
https://github.com/Noratrieb/ClickerGameSwing.git
synced 2026-01-14 15:45:04 +01:00
bigger
This commit is contained in:
parent
5b021182c2
commit
31a219b3e2
6 changed files with 120 additions and 85 deletions
|
|
@ -1,8 +1,13 @@
|
|||
import java.util.ArrayList;
|
||||
|
||||
public class ClickerModel {
|
||||
|
||||
private double nicolas;
|
||||
private final ArrayList<UpgradePanel> upgradePanels;
|
||||
|
||||
|
||||
public ClickerModel() {
|
||||
upgradePanels = new ArrayList<>();
|
||||
}
|
||||
|
||||
public double getNicolas() {
|
||||
|
|
@ -12,4 +17,20 @@ public class ClickerModel {
|
|||
public void setNicolas(double nicolas) {
|
||||
this.nicolas = nicolas;
|
||||
}
|
||||
|
||||
public void addUpgrade(UpgradePanel panel) {
|
||||
upgradePanels.add(panel);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
upgradePanels.forEach(UpgradePanel::refresh);
|
||||
}
|
||||
|
||||
public double getNPS() {
|
||||
double nps = 0;
|
||||
for(UpgradePanel p : upgradePanels){
|
||||
nps += p.getNPS();
|
||||
}
|
||||
return nps;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ClickerPresenter {
|
||||
|
||||
|
|
@ -7,59 +6,44 @@ public class ClickerPresenter {
|
|||
|
||||
private final ClickerView clickerView;
|
||||
private final ClickerModel clickerModel;
|
||||
private final ArrayList<UpgradePanel> upgradePanels;
|
||||
|
||||
private double upgradeFactor = 1;
|
||||
|
||||
LargeFormatter formatter = new LargeFormatter();
|
||||
|
||||
private final Timer loop;
|
||||
|
||||
public ClickerPresenter(ClickerView clickerView) {
|
||||
this.clickerModel = new ClickerModel();
|
||||
this.clickerView = clickerView;
|
||||
this.clickerView.setClickerPresenter(this);
|
||||
|
||||
UpgradePanel illusion = new UpgradePanel("Illision", 10, 1.05, 0.1, this);
|
||||
UpgradePanel cloneMachine = new UpgradePanel("Klonmaschine", 100, 1.1, 1, this);
|
||||
UpgradePanel mysteriousCave = new UpgradePanel("Mysteriöse Höhle", 500, 1.1, 10, this);
|
||||
UpgradePanel factory = new UpgradePanel("Massenfertigungsanstalt", 3000, 1.1, 150, this);
|
||||
UpgradePanel herblingen = new UpgradePanel("Herblingen", 100000, 1.1, 6969, this);
|
||||
UpgradePanel sihlcity = new UpgradePanel("Sihlcity", 1000000, 1.1, 50000, this);
|
||||
addPanel(new UpgradePanel("Illision", 10, 1.05, 0.1, this));
|
||||
addPanel(new UpgradePanel("Klonmaschine", 100, 1.1, 1, this));
|
||||
addPanel(new UpgradePanel("Mysteriöse Höhle", 500, 1.1, 10, this));
|
||||
addPanel(new UpgradePanel("Massenfertigungsanstalt", 3000, 1.1, 150, this));
|
||||
addPanel(new UpgradePanel("Herblingen", 100000, 1.1, 6969, this));
|
||||
addPanel(new UpgradePanel("Sihlcity", 1000000, 1.1, 50000, this));
|
||||
|
||||
addPanel(new UpgradePanel("Debugger", 1, 1, 1000000000, this));
|
||||
|
||||
|
||||
UpgradePanel debugger = new UpgradePanel("Debugger", 1, 1, 1000000000, this);
|
||||
clickerView.addUpgrade(illusion);
|
||||
clickerView.addUpgrade(cloneMachine);
|
||||
clickerView.addUpgrade(mysteriousCave);
|
||||
clickerView.addUpgrade(factory);
|
||||
clickerView.addUpgrade(herblingen);
|
||||
clickerView.addUpgrade(sihlcity);
|
||||
clickerView.addUpgrade(debugger);
|
||||
|
||||
upgradePanels = new ArrayList<>();
|
||||
upgradePanels.add(illusion);
|
||||
upgradePanels.add(cloneMachine);
|
||||
upgradePanels.add(mysteriousCave);
|
||||
upgradePanels.add(factory);
|
||||
upgradePanels.add(herblingen);
|
||||
upgradePanels.add(sihlcity);
|
||||
upgradePanels.add(debugger);
|
||||
|
||||
clickerModel = new ClickerModel();
|
||||
|
||||
loop = new Timer(1000 / TARGET_FPS, e -> refresh());
|
||||
Timer loop = new Timer(1000 / TARGET_FPS, e -> refresh());
|
||||
loop.start();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ClickerPresenter(new ClickerView());
|
||||
private void addPanel(UpgradePanel panel) {
|
||||
clickerModel.addUpgrade(panel);
|
||||
clickerView.addUpgrade(panel);
|
||||
}
|
||||
|
||||
|
||||
public void nicolasButtonClick() {
|
||||
clickerModel.setNicolas(clickerModel.getNicolas() + 1);
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
clickerView.setNicolasAmount(formatter.formatBigNumber(clickerModel.getNicolas()) + " Nicolas");
|
||||
upgradePanels.forEach(UpgradePanel::refresh);
|
||||
clickerView.setNPSAmount(formatter.formatBigNumber(clickerModel.getNPS()) + " Nicolas per Second");
|
||||
clickerModel.refresh();
|
||||
}
|
||||
|
||||
public void removeNicolas(double amount) {
|
||||
|
|
@ -73,4 +57,20 @@ public class ClickerPresenter {
|
|||
public void addNicolas(double gain) {
|
||||
clickerModel.setNicolas(clickerModel.getNicolas() + gain);
|
||||
}
|
||||
|
||||
public String changeFactor() {
|
||||
upgradeFactor *= 10;
|
||||
if (upgradeFactor > 1000) {
|
||||
upgradeFactor = 1;
|
||||
}
|
||||
return String.format("%,.0fx", upgradeFactor);
|
||||
}
|
||||
|
||||
public double getUpgradeFactor() {
|
||||
return upgradeFactor;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ClickerPresenter(new ClickerView());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ClickerView">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
|
|
@ -22,17 +22,17 @@
|
|||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="61c38" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="61c38" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="126e2" class="javax.swing.JButton" binding="nicolasButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="7" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Nicolas"/>
|
||||
|
|
@ -43,19 +43,55 @@
|
|||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Label"/>
|
||||
<text value="3 Nicolas"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7484a" class="javax.swing.JLabel" binding="npsLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="NPS: 5"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="d38b7" binding="thingsPanel" layout-manager="CardLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="85f52" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="323d3" class="javax.swing.JButton" binding="factorUpgradeButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="x1"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="43a6d">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="bc167">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -1,22 +1,28 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class ClickerView extends JFrame {
|
||||
private JButton nicolasButton;
|
||||
private JPanel mainPanel;
|
||||
private JPanel thingsPanel;
|
||||
private JLabel nicolasLabels;
|
||||
private JButton factorUpgradeButton;
|
||||
private JLabel npsLabel;
|
||||
|
||||
private ClickerPresenter clickerPresenter;
|
||||
|
||||
public ClickerView() {
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setSize(700, 500);
|
||||
setSize(800, 600);
|
||||
setContentPane(mainPanel);
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
|
||||
thingsPanel.setLayout(new BoxLayout(thingsPanel, BoxLayout.Y_AXIS));
|
||||
nicolasButton.addActionListener(e -> clickerPresenter.nicolasButtonClick());
|
||||
|
||||
factorUpgradeButton.addActionListener(e -> factorUpgradeButton.setText(clickerPresenter.changeFactor()));
|
||||
}
|
||||
|
||||
public void setClickerPresenter(ClickerPresenter clickerPresenter) {
|
||||
|
|
@ -30,4 +36,7 @@ public class ClickerView extends JFrame {
|
|||
public void setNicolasAmount(String amount) {
|
||||
nicolasLabels.setText(amount);
|
||||
}
|
||||
public void setNPSAmount(String amount) {
|
||||
npsLabel.setText(amount);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="UpgradePanel">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="337" height="74"/>
|
||||
<xy x="20" y="20" width="223" height="74"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
<grid id="51553" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
|
|
@ -50,22 +50,6 @@
|
|||
<text value="Upgrade: 34805 Nicolas"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="30c13" class="javax.swing.JButton" binding="x10Button">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="x10"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c7089" class="javax.swing.JButton" binding="x100Button">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="x100"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ public class UpgradePanel extends JPanel {
|
|||
private JLabel nameLabel;
|
||||
private JLabel levelLabel;
|
||||
private JLabel gainLabel;
|
||||
private JButton x10Button;
|
||||
private JButton x100Button;
|
||||
|
||||
private String name;
|
||||
|
||||
|
|
@ -37,34 +35,20 @@ public class UpgradePanel extends JPanel {
|
|||
|
||||
this.nameLabel.setText(name);
|
||||
|
||||
upgradeButton.addActionListener(e -> upgrade(1));
|
||||
x10Button.addActionListener(e -> upgrade(10));
|
||||
x100Button.addActionListener(e -> upgrade(100));
|
||||
upgradeButton.addActionListener(e -> upgrade(presenter.getUpgradeFactor()));
|
||||
}
|
||||
|
||||
public void upgrade(int amount) {
|
||||
public void upgrade(double amount) {
|
||||
|
||||
presenter.removeNicolas(calculateExp(cost, costMultiplier, amount));
|
||||
gain += baseGain * amount;
|
||||
level += amount;
|
||||
|
||||
cost *= Math.pow(costMultiplier, amount);
|
||||
|
||||
System.err.println(calculateExp(cost, costMultiplier, amount));
|
||||
/*
|
||||
for (int i = 0; i < amount; i++) {
|
||||
presenter.removeNicolas(cost);
|
||||
gain += baseGain;
|
||||
|
||||
cost = cost * costMultiplier;
|
||||
level++;
|
||||
}*/
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
upgradeButton.setEnabled(presenter.getNicolas() >= cost);
|
||||
x10Button.setEnabled(presenter.getNicolas() >= calculateExp(cost, costMultiplier, 10));
|
||||
x100Button.setEnabled(presenter.getNicolas() >= calculateExp(cost, costMultiplier, 100));
|
||||
upgradeButton.setEnabled(presenter.getNicolas() >= calculateExp(cost, costMultiplier, presenter.getUpgradeFactor()));
|
||||
|
||||
//should nicolas be added?
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
|
@ -80,9 +64,8 @@ public class UpgradePanel extends JPanel {
|
|||
|
||||
|
||||
if (timePerNicolas < frameDeltaTime) {
|
||||
System.out.printf(" FN");
|
||||
double missedNicolas = frameDeltaTime / timePerNicolas;
|
||||
System.out.printf(" mn=%.2f gain=%.2f add=%.2f", missedNicolas, gain, missedNicolas);
|
||||
System.out.printf(" FN mn=%.2f gain=%.2f add=%.2f", missedNicolas, gain, missedNicolas);
|
||||
presenter.addNicolas(missedNicolas);
|
||||
} else {
|
||||
presenter.addNicolas(1);
|
||||
|
|
@ -95,10 +78,8 @@ public class UpgradePanel extends JPanel {
|
|||
levelLabel.setText("Level: " + level);
|
||||
gainLabel.setText(lf.formatBigNumber(gain) + " Nicolas");
|
||||
|
||||
upgradeButton.setText("Upgrade: " + lf.formatBigNumber(cost) + " Nicolas");
|
||||
x10Button.setText("x10: " + lf.formatBigNumber(calculateExp(cost, costMultiplier, 10)) + " Nicolas");
|
||||
x100Button.setText("x100: " + lf.formatBigNumber(calculateExp(cost, costMultiplier, 100)) + " Nicolas");
|
||||
|
||||
upgradeButton.setText(String.format("%,.0fx Upgrade: %s Nicolas",
|
||||
presenter.getUpgradeFactor(), lf.formatBigNumber(calculateExp(cost, costMultiplier, presenter.getUpgradeFactor()))));
|
||||
}
|
||||
|
||||
private double calculateExp(double c, double fac, double amount) {
|
||||
|
|
@ -111,4 +92,8 @@ public class UpgradePanel extends JPanel {
|
|||
}
|
||||
return result * c;
|
||||
}
|
||||
|
||||
public double getNPS() {
|
||||
return gain;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue