Control Update
This commit is contained in:
+49
-7
@@ -135,10 +135,41 @@ public class Control {
|
|||||||
return cells;
|
return cells;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean[][] nextGen() {
|
public void nextGen() {
|
||||||
|
|
||||||
gen++;
|
gen++;
|
||||||
System.out.println("Generation:" + gen);
|
// System.out.println("Generation:" + gen);
|
||||||
|
|
||||||
|
for (int x = 0; x < xSize; x++) {
|
||||||
|
for (int y = 0; y < ySize; y++) {
|
||||||
|
int n = aliveNeigbours(x, y);
|
||||||
|
|
||||||
|
switch (n) {
|
||||||
|
case 3:
|
||||||
|
newcells[x][y] = true;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
newcells[x][y] = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x = 0; x < this.xSize; x++) {
|
||||||
|
for (int y = 0; y < this.ySize; y++) {
|
||||||
|
cells[x][y] = newcells[x][y];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean[][] nextGenBackup() {
|
||||||
|
|
||||||
|
gen++;
|
||||||
|
// System.out.println("Generation:" + gen);
|
||||||
|
|
||||||
for (int x = 0; x < xSize; x++) {
|
for (int x = 0; x < xSize; x++) {
|
||||||
for (int y = 0; y < ySize; y++) {
|
for (int y = 0; y < ySize; y++) {
|
||||||
@@ -172,7 +203,6 @@ public class Control {
|
|||||||
return cells;
|
return cells;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private int aliveNeigbours(int x, int y) {
|
private int aliveNeigbours(int x, int y) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
@@ -257,14 +287,14 @@ public class Control {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRunning(boolean state){
|
|
||||||
clock.setRunning(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRunning() {
|
public boolean isRunning() {
|
||||||
return clock.isRunning();
|
return clock.isRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRunning(boolean state) {
|
||||||
|
clock.setRunning(state);
|
||||||
|
}
|
||||||
|
|
||||||
public void setVelocity(int velocity) {
|
public void setVelocity(int velocity) {
|
||||||
clock.setVelocity(velocity);
|
clock.setVelocity(velocity);
|
||||||
}
|
}
|
||||||
@@ -277,6 +307,18 @@ public class Control {
|
|||||||
this.mouseLocked = mouseLocked;
|
this.mouseLocked = mouseLocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearGrid() {
|
||||||
|
|
||||||
|
for (int x = 0; x < xSize; x++) {
|
||||||
|
for (int y = 0; y < ySize; y++) {
|
||||||
|
cells[x][y] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
syncCells();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void multipleGenSkip(int generations) {
|
public void multipleGenSkip(int generations) {
|
||||||
for (int i = 0; i < generations; i++) {
|
for (int i = 0; i < generations; i++) {
|
||||||
nextGen();
|
nextGen();
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ public class ControlWindow {
|
|||||||
initToggleButton();
|
initToggleButton();
|
||||||
initNextButton();
|
initNextButton();
|
||||||
initDrawLockButton();
|
initDrawLockButton();
|
||||||
|
initClearButton();
|
||||||
|
initMultibleGenSkip();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initHeading(){
|
private void initHeading(){
|
||||||
@@ -225,6 +227,64 @@ public class ControlWindow {
|
|||||||
updateLockedMouse();
|
updateLockedMouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initClearButton(){
|
||||||
|
clearButton = new JButton();
|
||||||
|
clearButton.setText("Clear Grid");
|
||||||
|
clearButton.setFont(text);
|
||||||
|
clearButton.setForeground(Color.decode("#121212"));
|
||||||
|
clearButton.setBorderPainted(true);
|
||||||
|
clearButton.setFocusPainted(false);
|
||||||
|
clearButton.setContentAreaFilled(false);
|
||||||
|
clearButton.setBounds(50, 525, 300, 50);
|
||||||
|
clearButton.setVisible(true);
|
||||||
|
clearButton.addMouseListener(hover);
|
||||||
|
clearButton.setBorder(new RoundedBorder(25));
|
||||||
|
clearButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
gui.clearGrid();
|
||||||
|
gui.showGrid(gui.getCells());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initMultibleGenSkip(){
|
||||||
|
|
||||||
|
multipleGenSkipButton = new JButton();
|
||||||
|
multipleGenSkipButton.setText("Next Generation");
|
||||||
|
multipleGenSkipButton.setFont(text);
|
||||||
|
multipleGenSkipButton.setForeground(Color.decode("#121212"));
|
||||||
|
multipleGenSkipButton.setBorderPainted(true);
|
||||||
|
multipleGenSkipButton.setFocusPainted(false);
|
||||||
|
multipleGenSkipButton.setContentAreaFilled(false);
|
||||||
|
multipleGenSkipButton.setBounds(50, 450, 300, 50);
|
||||||
|
multipleGenSkipButton.setVisible(true);
|
||||||
|
multipleGenSkipButton.addMouseListener(hover);
|
||||||
|
multipleGenSkipButton.setBorder(new RoundedBorder(25));
|
||||||
|
multipleGenSkipButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
gui.multipleGenSkip(Integer.parseInt(multipleGenSkipLable.getText()));
|
||||||
|
gui.showGrid(gui.getCells());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
multipleGenSkipLable = new JTextField("6");
|
||||||
|
multipleGenSkipLable.setBackground(null);
|
||||||
|
multipleGenSkipLable.setBorder(null);
|
||||||
|
multipleGenSkipLable.setBounds(50, 450, 200, 30);
|
||||||
|
multipleGenSkipLable.setFont(text);
|
||||||
|
multipleGenSkipLable.setForeground(Color.decode("#121212"));
|
||||||
|
multipleGenSkipLable.setVisible(true);
|
||||||
|
multipleGenSkipLable.addKeyListener(new KeyAdapter() {
|
||||||
|
public void keyTyped(KeyEvent evt) {
|
||||||
|
if (!Character.isDigit(evt.getKeyChar())) {
|
||||||
|
evt.consume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void initSaveButton(){}
|
private void initSaveButton(){}
|
||||||
|
|
||||||
private void initSaveNameField(){}
|
private void initSaveNameField(){}
|
||||||
@@ -237,6 +297,9 @@ public class ControlWindow {
|
|||||||
controlWindow.add(toggleGame);
|
controlWindow.add(toggleGame);
|
||||||
controlWindow.add(nextGenButton);
|
controlWindow.add(nextGenButton);
|
||||||
controlWindow.add(lockMouse);
|
controlWindow.add(lockMouse);
|
||||||
|
controlWindow.add(clearButton);
|
||||||
|
controlWindow.add(multipleGenSkipLable);
|
||||||
|
controlWindow.add(multipleGenSkipButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisibility(boolean value) {
|
public void setVisibility(boolean value) {
|
||||||
|
|||||||
@@ -137,6 +137,12 @@ public class GUI {
|
|||||||
control.setMouseLocked(value);
|
control.setMouseLocked(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearGrid(){ control.clearGrid(); }
|
||||||
|
|
||||||
|
public void multipleGenSkip(int generations){
|
||||||
|
control.multipleGenSkip(generations);
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Delet this Methods. Those are shit.
|
//TODO: Delet this Methods. Those are shit.
|
||||||
public void setVisibility(boolean value){
|
public void setVisibility(boolean value){
|
||||||
controlWindow.setVisibility(value);
|
controlWindow.setVisibility(value);
|
||||||
|
|||||||
Reference in New Issue
Block a user