Structure UpDate

This commit is contained in:
Noah
2021-12-03 21:02:45 +01:00
parent cb8e4246db
commit bd16b8e401
20 changed files with 91 additions and 1339 deletions
+82
View File
@@ -0,0 +1,82 @@
package gamecontrol;
import gui.control.GUI;
import java.util.Timer;
import java.util.TimerTask;
public class Clock extends Thread {
private Control control;
private GUI gui;
private boolean running = true;
private int velocity, delay;
private boolean isFirstGen;
private Timer t;
private TimerTask tt;
public Clock(Control control, GUI gui) {
this.control = control;
this.gui = gui;
this.velocity = 500;
this.delay = 0;
this.isFirstGen = true;
}
public void start() {
this.delay = this.velocity;
if (isFirstGen) {
t = new Timer();
this.delay = 0;
this.isFirstGen = false;
}
if (tt != null){
tt.cancel();
}
tt = new TimerTask() {
@Override
public void run() {
if (running) {
control.showGrid(control.getCells());
control.nextGen();
}
}
};
t.scheduleAtFixedRate(tt, delay, this.velocity);
}
public boolean isRunning() {
return running;
}
public void setRunning(boolean running) {
this.running = running;
}
public int getVelocity() {
return velocity;
}
public void setVelocity(int velocity) {
this.velocity = velocity;
start();
}
public boolean isFirstGen() {
return isFirstGen;
}
public void setFirstGen(boolean firstGen) {
isFirstGen = firstGen;
}
}