Skip to content

Commit

Permalink
Get it to work with Java 21 and fix dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxe12 committed Jan 7, 2024
1 parent 8864ae0 commit 916f171
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 10 deletions.
Binary file added .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/SimpleGameOfLife.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Conway.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/bin" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="JavaSE-12" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file modified bin/gameoflife/Draw.class
Binary file not shown.
Binary file modified bin/gameoflife/GameLoop.class
Binary file not shown.
Binary file modified bin/gameoflife/Grid.class
Binary file not shown.
Binary file modified bin/gameoflife/Main.class
Binary file not shown.
Binary file modified bin/module-info.class
Binary file not shown.
4 changes: 2 additions & 2 deletions src/gameoflife/Draw.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ protected void paintComponent(Graphics g) {
super.paintComponent(g);

g.setColor(Color.BLACK);
g.drawRect(9, 9, 514, 514);
g.drawRect(9, 9, 514, 258);

for(int x=0; x < Grid.CELLCOUNT; x++) {
for(int y=0; y < Grid.CELLCOUNT; y++) {
for(int y=0; y < Grid.CELLCOUNT_Y; y++) {
if(Grid.cells[x][y]) {
g.setColor(Color.RED);
g.drawRect(x + 10, y + 10, 1, 1);
Expand Down
5 changes: 3 additions & 2 deletions src/gameoflife/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class Grid {
public static final int CELLCOUNT = 512;
public static final int CELLCOUNT_Y = 256;
public static boolean[][] cells = new boolean[CELLCOUNT][CELLCOUNT];

public final int startCells = 10000;
Expand All @@ -12,7 +13,7 @@ public class Grid {
public void init() {
for (int i = 0; i < startCells; i++) {
int x = genRandom(0, CELLCOUNT);
int y = genRandom(0, CELLCOUNT);
int y = genRandom(0, CELLCOUNT_Y);
cells[x][y] = true;
}
}
Expand All @@ -21,7 +22,7 @@ public static void step() {
gen++;
System.out.println("generation: " + gen);
for (int x = 0; x < CELLCOUNT; x++) {
for (int y = 0; y < CELLCOUNT; y++) {
for (int y = 0; y < CELLCOUNT_Y; y++) {
int neighbours = countNeighbours(x, y);
// rule: if cell is dead and has 3 neighbours revive it
if (neighbours == 3 && !cells[x][y]) {
Expand Down
13 changes: 7 additions & 6 deletions src/gameoflife/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
public class Main extends JFrame{

public static void main(String [] args) {

Draw drawer = new Draw();
drawer.setVisible(true);

JFrame GUI = new JFrame("Game of Life");
GUI.setSize(550, 570);
GUI.setSize(540, 310);
GUI.setDefaultCloseOperation(EXIT_ON_CLOSE);
GUI.setResizable(false);
GUI.setLocationRelativeTo(null);
GUI.setVisible(true);

Draw drawer = new Draw();
GUI.add(drawer);
drawer.setVisible(true);
GUI.setVisible(true);

Grid g = new Grid();
GameLoop gl = new GameLoop();
g.init();
Expand Down

0 comments on commit 916f171

Please sign in to comment.