Updated structure of files and folders; edited Readme.md
This commit is contained in:
15
.classpath
15
.classpath
@@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" path="src"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-9">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="module" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="module" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
|
||||||
</classpath>
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/bin/
|
|
||||||
17
.project
17
.project
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>GameOfLife</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=9
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=9
|
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.source=9
|
|
||||||
13
README.md
13
README.md
@@ -4,6 +4,15 @@ My Conway's Game of Life project
|
|||||||
***Not optimized yet***
|
***Not optimized yet***
|
||||||
This is just a little side project to work on optimization skills and mess around with different patterns in Conway's Game of Life.
|
This is just a little side project to work on optimization skills and mess around with different patterns in Conway's Game of Life.
|
||||||
|
|
||||||
Download the project and open it in eclipse to edit, or to just run the project download and run the attached jar(***located in the included jar folder***).
|
**To run**
|
||||||
|
Step 1 : Download Repository
|
||||||
|
Step 2 : Open Command Prompt and navigate to the folder you downloaded
|
||||||
|
Step 3 : Enter the following commands
|
||||||
|
cd gameoflife
|
||||||
|
javac GameOfLife.java
|
||||||
|
javac Main.java
|
||||||
|
jar cmvf manifest.txt GameOfLife.jar ./*.java ./*.class
|
||||||
|
java -jar GameOfLife.java
|
||||||
|
Step 4 : *Have fun using my Conway's Game of Life Program!!!*
|
||||||
|
|
||||||
***Note: Requires Java 10***
|
***Note: Requires Java 8***
|
||||||
@@ -1,85 +1,83 @@
|
|||||||
package gameoflife;
|
import javafx.scene.shape.Rectangle;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.input.MouseEvent;
|
|
||||||
import javafx.scene.paint.Color;
|
public class Cell extends Rectangle{
|
||||||
|
public enum Status{
|
||||||
public class Cell extends Rectangle{
|
ALIVE, DEAD
|
||||||
public enum Status{
|
}
|
||||||
ALIVE, DEAD
|
private Status status;
|
||||||
}
|
private boolean aliveNextCycle, deadNextCycle;
|
||||||
private Status status;
|
private int xLocation, yLocation;
|
||||||
private boolean aliveNextCycle, deadNextCycle;
|
public Cell(Double width, Double height, int x, int y){
|
||||||
private int xLocation, yLocation;
|
setWidth(width);
|
||||||
public Cell(Double width, Double height, int x, int y){
|
setHeight(height);
|
||||||
setWidth(width);
|
setStroke(Color.LIGHTGRAY);
|
||||||
setHeight(height);
|
setStatus(Status.DEAD);
|
||||||
setStroke(Color.LIGHTGRAY);
|
aliveNextCycle = false;
|
||||||
setStatus(Status.DEAD);
|
deadNextCycle = false;
|
||||||
aliveNextCycle = false;
|
xLocation = x;
|
||||||
deadNextCycle = false;
|
yLocation = y;
|
||||||
xLocation = x;
|
setOnMousePressed(new EventHandler<MouseEvent>() {
|
||||||
yLocation = y;
|
public void handle(MouseEvent me) {
|
||||||
setOnMousePressed(new EventHandler<MouseEvent>() {
|
if(getStatus() == Status.DEAD) {
|
||||||
public void handle(MouseEvent me) {
|
setStatus(Status.ALIVE);
|
||||||
if(getStatus() == Status.DEAD) {
|
}
|
||||||
setStatus(Status.ALIVE);
|
else {
|
||||||
}
|
setStatus(Status.DEAD);
|
||||||
else {
|
}
|
||||||
setStatus(Status.DEAD);
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
public Status getStatus(){
|
||||||
|
return status;
|
||||||
public Status getStatus(){
|
}
|
||||||
return status;
|
|
||||||
}
|
public void setStatus(Status status){
|
||||||
|
if(status == Status.ALIVE){
|
||||||
public void setStatus(Status status){
|
setFill(Color.BLACK);
|
||||||
if(status == Status.ALIVE){
|
}
|
||||||
setFill(Color.BLACK);
|
else{
|
||||||
}
|
setFill(Color.WHITE);
|
||||||
else{
|
}
|
||||||
setFill(Color.WHITE);
|
this.status = status;
|
||||||
}
|
}
|
||||||
this.status = status;
|
|
||||||
}
|
public void updateStatus(){
|
||||||
|
if(isAliveNextCycle()){
|
||||||
public void updateStatus(){
|
setStatus(Status.ALIVE);
|
||||||
if(isAliveNextCycle()){
|
makeAliveNextCycle(false);
|
||||||
setStatus(Status.ALIVE);
|
}
|
||||||
makeAliveNextCycle(false);
|
else if(isDeadNextCycle()){
|
||||||
}
|
setStatus(Status.DEAD);
|
||||||
else if(isDeadNextCycle()){
|
makeDeadNextCycle(false);
|
||||||
setStatus(Status.DEAD);
|
}
|
||||||
makeDeadNextCycle(false);
|
else{return;}
|
||||||
}
|
}
|
||||||
else{return;}
|
|
||||||
}
|
public boolean isAliveNextCycle(){
|
||||||
|
return aliveNextCycle;
|
||||||
public boolean isAliveNextCycle(){
|
}
|
||||||
return aliveNextCycle;
|
|
||||||
}
|
public boolean isDeadNextCycle(){
|
||||||
|
return deadNextCycle;
|
||||||
public boolean isDeadNextCycle(){
|
}
|
||||||
return deadNextCycle;
|
|
||||||
}
|
public void makeAliveNextCycle(boolean aliveNextCycle){
|
||||||
|
this.aliveNextCycle = aliveNextCycle;
|
||||||
public void makeAliveNextCycle(boolean aliveNextCycle){
|
}
|
||||||
this.aliveNextCycle = aliveNextCycle;
|
|
||||||
}
|
public void makeDeadNextCycle(boolean deadNextCycle){
|
||||||
|
this.deadNextCycle = deadNextCycle;
|
||||||
public void makeDeadNextCycle(boolean deadNextCycle){
|
}
|
||||||
this.deadNextCycle = deadNextCycle;
|
|
||||||
}
|
public int getXLocation() {
|
||||||
|
return xLocation;
|
||||||
public int getXLocation() {
|
}
|
||||||
return xLocation;
|
|
||||||
}
|
public int getYLocation() {
|
||||||
|
return yLocation;
|
||||||
public int getYLocation() {
|
}
|
||||||
return yLocation;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +1,63 @@
|
|||||||
package gameoflife;
|
import javafx.application.Application;
|
||||||
|
import javafx.scene.Scene;
|
||||||
import javafx.application.Application;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.Scene;
|
import javafx.stage.Stage;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.geometry.Pos;
|
||||||
import javafx.stage.Stage;
|
import javafx.scene.control.Button;
|
||||||
import javafx.geometry.Pos;
|
import javafx.animation.AnimationTimer;
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.animation.AnimationTimer;
|
public class GameOfLife extends Application{
|
||||||
|
private Cell[][] cells;
|
||||||
public class GameOfLife extends Application{
|
@Override
|
||||||
private Cell[][] cells;
|
public void start(Stage primaryStage) throws Exception {
|
||||||
@Override
|
cells = new Cell[64][64];
|
||||||
public void start(Stage primaryStage) throws Exception {
|
|
||||||
cells = new Cell[64][64];
|
GridPane root = new GridPane();
|
||||||
|
root.setAlignment(Pos.CENTER);
|
||||||
GridPane root = new GridPane();
|
|
||||||
root.setAlignment(Pos.CENTER);
|
for(int i = 0; i < cells.length; i++){
|
||||||
|
for(int j = 0; j < cells[i].length; j++){
|
||||||
for(int i = 0; i < cells.length; i++){
|
cells[i][j] = new Cell((double)10,(double)10, i, j);
|
||||||
for(int j = 0; j < cells[i].length; j++){
|
root.add(cells[i][j], i, j);
|
||||||
cells[i][j] = new Cell((double)10,(double)10, i, j);
|
}
|
||||||
root.add(cells[i][j], i, j);
|
}
|
||||||
}
|
|
||||||
}
|
AnimationTimer animate = new AnimationTimer(){
|
||||||
|
@Override
|
||||||
AnimationTimer animate = new AnimationTimer(){
|
public void handle(long currentNanoTime){
|
||||||
@Override
|
for(int i = 0; i< cells.length; i++){
|
||||||
public void handle(long currentNanoTime){
|
for(int j = 0; j < cells[i].length; j++){
|
||||||
for(int i = 0; i< cells.length; i++){
|
GameOfLifeRules.checkRules(cells, i, j);
|
||||||
for(int j = 0; j < cells[i].length; j++){
|
}
|
||||||
GameOfLifeRules.checkRules(cells, i, j);
|
}
|
||||||
}
|
for(int i = 0; i< cells.length; i++){
|
||||||
}
|
for(int j = 0; j < cells[i].length; j++){
|
||||||
for(int i = 0; i< cells.length; i++){
|
cells[i][j].updateStatus();
|
||||||
for(int j = 0; j < cells[i].length; j++){
|
}
|
||||||
cells[i][j].updateStatus();
|
}
|
||||||
}
|
try {Thread.sleep(50);}
|
||||||
}
|
catch(Exception e) {}
|
||||||
try {Thread.sleep(50);}
|
}
|
||||||
catch(Exception e) {}
|
};
|
||||||
}
|
|
||||||
};
|
Button stop = new Button("Stop");
|
||||||
|
stop.setOnAction(event->{
|
||||||
Button stop = new Button("Stop");
|
animate.stop();
|
||||||
stop.setOnAction(event->{
|
});
|
||||||
animate.stop();
|
|
||||||
});
|
Button start = new Button("Start");
|
||||||
|
start.setOnAction(event->{
|
||||||
Button start = new Button("Start");
|
animate.start();
|
||||||
start.setOnAction(event->{
|
});
|
||||||
animate.start();
|
|
||||||
});
|
root.add(start, cells.length, cells[cells.length-1].length);
|
||||||
|
root.add(stop, cells.length, cells[cells.length-1].length+1);
|
||||||
root.add(start, cells.length, cells[cells.length-1].length);
|
root.setStyle("-fx-background-color: white");
|
||||||
root.add(stop, cells.length, cells[cells.length-1].length+1);
|
|
||||||
root.setStyle("-fx-background-color: white");
|
Scene scene = new Scene(root);
|
||||||
|
|
||||||
Scene scene = new Scene(root);
|
primaryStage.setTitle("Conway's Game of Life");
|
||||||
|
primaryStage.setScene(scene);
|
||||||
primaryStage.setTitle("Conway's Game of Life");
|
primaryStage.show();
|
||||||
primaryStage.setScene(scene);
|
}
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,35 +1,33 @@
|
|||||||
package gameoflife;
|
public class GameOfLifeRules {
|
||||||
|
public static void checkRules(Cell[][] cells, int x, int y) {
|
||||||
public class GameOfLifeRules {
|
int aliveNeighbors = 0;
|
||||||
public static void checkRules(Cell[][] cells, int x, int y) {
|
for(int i = y-1; i <= y + 1; i++){
|
||||||
int aliveNeighbors = 0;
|
if(i >= 0 && i < cells[x].length){
|
||||||
for(int i = y-1; i <= y + 1; i++){
|
if(x-1 >= 0){
|
||||||
if(i >= 0 && i < cells[x].length){
|
if(cells[x-1][i].getStatus() == Cell.Status.ALIVE){
|
||||||
if(x-1 >= 0){
|
aliveNeighbors++;
|
||||||
if(cells[x-1][i].getStatus() == Cell.Status.ALIVE){
|
}
|
||||||
aliveNeighbors++;
|
}
|
||||||
}
|
if(i != y){
|
||||||
}
|
if(cells[x][i].getStatus() == Cell.Status.ALIVE){
|
||||||
if(i != y){
|
aliveNeighbors++;
|
||||||
if(cells[x][i].getStatus() == Cell.Status.ALIVE){
|
}
|
||||||
aliveNeighbors++;
|
}
|
||||||
}
|
if(x+1 < cells.length){
|
||||||
}
|
if(cells[x+1][i].getStatus() == Cell.Status.ALIVE){
|
||||||
if(x+1 < cells.length){
|
aliveNeighbors++;
|
||||||
if(cells[x+1][i].getStatus() == Cell.Status.ALIVE){
|
}
|
||||||
aliveNeighbors++;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if((aliveNeighbors == 2 || aliveNeighbors == 3) && cells[x][y].getStatus() == Cell.Status.ALIVE){
|
||||||
}
|
cells[x][y].makeAliveNextCycle(true);
|
||||||
if((aliveNeighbors == 2 || aliveNeighbors == 3) && cells[x][y].getStatus() == Cell.Status.ALIVE){
|
}
|
||||||
cells[x][y].makeAliveNextCycle(true);
|
else if((aliveNeighbors < 2 || aliveNeighbors > 3) && cells[x][y].getStatus() == Cell.Status.ALIVE){
|
||||||
}
|
cells[x][y].makeDeadNextCycle(true);
|
||||||
else if((aliveNeighbors < 2 || aliveNeighbors > 3) && cells[x][y].getStatus() == Cell.Status.ALIVE){
|
}
|
||||||
cells[x][y].makeDeadNextCycle(true);
|
if(aliveNeighbors == 3 && cells[x][y].getStatus() == Cell.Status.DEAD){
|
||||||
}
|
cells[x][y].makeAliveNextCycle(true);
|
||||||
if(aliveNeighbors == 3 && cells[x][y].getStatus() == Cell.Status.DEAD){
|
}
|
||||||
cells[x][y].makeAliveNextCycle(true);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
package gameoflife;
|
import javafx.application.Application;
|
||||||
|
|
||||||
import javafx.application.Application;
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
public class Main {
|
Application.launch(GameOfLife.class, args);
|
||||||
public static void main(String[] args) {
|
}
|
||||||
Application.launch(GameOfLife.class, args);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
1
gameoflife/manifest.mf
Normal file
1
gameoflife/manifest.mf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Main-Class: Main
|
||||||
Binary file not shown.
Reference in New Issue
Block a user