Control Update
This commit is contained in:
+57
-15
@@ -67,7 +67,7 @@ public class Control {
|
||||
gui.createGameWindow(this.xSize, this.ySize, this.width, this.height);
|
||||
setRunning(true);
|
||||
|
||||
if (startMode == StartMode.Manuel){
|
||||
if (startMode == StartMode.Manuel) {
|
||||
setRunning(false);
|
||||
gui.buildControlWindow();
|
||||
}
|
||||
@@ -135,10 +135,41 @@ public class Control {
|
||||
return cells;
|
||||
}
|
||||
|
||||
public boolean[][] nextGen() {
|
||||
public void nextGen() {
|
||||
|
||||
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 y = 0; y < ySize; y++) {
|
||||
@@ -172,7 +203,6 @@ public class Control {
|
||||
return cells;
|
||||
}
|
||||
|
||||
|
||||
private int aliveNeigbours(int x, int y) {
|
||||
int count = 0;
|
||||
|
||||
@@ -201,7 +231,7 @@ public class Control {
|
||||
}
|
||||
|
||||
|
||||
public void setVisibility(boolean value){
|
||||
public void setVisibility(boolean value) {
|
||||
gui.setVisibility(value);
|
||||
}
|
||||
|
||||
@@ -228,10 +258,10 @@ public class Control {
|
||||
gui.showGrid(cells);
|
||||
}
|
||||
|
||||
private void calcSize(){
|
||||
private void calcSize() {
|
||||
|
||||
float ratio = (float) (xSize) / (float) (ySize);
|
||||
if (xSize > ySize){
|
||||
if (xSize > ySize) {
|
||||
width = 800;
|
||||
height = (int) (width / ratio);
|
||||
} else {
|
||||
@@ -257,15 +287,15 @@ public class Control {
|
||||
|
||||
}
|
||||
|
||||
public void setRunning(boolean state){
|
||||
clock.setRunning(state);
|
||||
}
|
||||
|
||||
public boolean isRunning(){
|
||||
public boolean isRunning() {
|
||||
return clock.isRunning();
|
||||
}
|
||||
|
||||
public void setVelocity(int velocity){
|
||||
public void setRunning(boolean state) {
|
||||
clock.setRunning(state);
|
||||
}
|
||||
|
||||
public void setVelocity(int velocity) {
|
||||
clock.setVelocity(velocity);
|
||||
}
|
||||
|
||||
@@ -277,8 +307,20 @@ public class Control {
|
||||
this.mouseLocked = mouseLocked;
|
||||
}
|
||||
|
||||
public void multipleGenSkip(int generations){
|
||||
for (int i = 0; i < generations; i++){
|
||||
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) {
|
||||
for (int i = 0; i < generations; i++) {
|
||||
nextGen();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,8 @@ public class ControlWindow {
|
||||
initToggleButton();
|
||||
initNextButton();
|
||||
initDrawLockButton();
|
||||
initClearButton();
|
||||
initMultibleGenSkip();
|
||||
}
|
||||
|
||||
private void initHeading(){
|
||||
@@ -225,6 +227,64 @@ public class ControlWindow {
|
||||
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 initSaveNameField(){}
|
||||
@@ -237,6 +297,9 @@ public class ControlWindow {
|
||||
controlWindow.add(toggleGame);
|
||||
controlWindow.add(nextGenButton);
|
||||
controlWindow.add(lockMouse);
|
||||
controlWindow.add(clearButton);
|
||||
controlWindow.add(multipleGenSkipLable);
|
||||
controlWindow.add(multipleGenSkipButton);
|
||||
}
|
||||
|
||||
public void setVisibility(boolean value) {
|
||||
|
||||
@@ -137,6 +137,12 @@ public class GUI {
|
||||
control.setMouseLocked(value);
|
||||
}
|
||||
|
||||
public void clearGrid(){ control.clearGrid(); }
|
||||
|
||||
public void multipleGenSkip(int generations){
|
||||
control.multipleGenSkip(generations);
|
||||
}
|
||||
|
||||
//TODO: Delet this Methods. Those are shit.
|
||||
public void setVisibility(boolean value){
|
||||
controlWindow.setVisibility(value);
|
||||
|
||||
Reference in New Issue
Block a user