It is possible to create an implementation that supports an infinite universe. The third thing is that your implementation of Game of Life is limited to a finite universe: the width and height of the universe must be known upfront. The second thing which I noticed right away is that there are no tests.
The visual appearance of Java code should be an indentation of 4 spaces. Some blocks are indented 2, some 3, some 4 spaces. The opening curly braces are misplaced, and the else is misplaced. The code is is not formatted according to the SUN or Google Code Conventions (which are largely identical). The first thing that I notice when looking at the code is something that directly stings in my eyes: Formatting. The code does all of that, but I am not sure about it's performance, look-and-feel, conciseness, or readability. The evolution of the universe is displayed as an animation with options for the user to pause, resume, reset the universe, and adjust the speed of the animation. The purpose of the code is to simulate Conway's game of life based on an initial random state, though I am planning to add a JComponent that allows the user to choose an initial state. ResetButton.addActionListener(e -> universe.reset(height, width, (int) Math.random())) Īny comment, even if it was on one small issue with my code will be appreciated. SlowDownButton.addActionListener(e -> tDelay(speed += 50)) If (playToggleButton.getText().equals("Play") & !timer.isRunning())Įlse if (playToggleButton.getText().equals("Pause") & timer.isRunning()) SetLayout(new BoxLayout(this, BoxLayout.X_AXIS)) tForeground(Color.LIGHT_GRAY) ĪtForeground(Color.LIGHT_GRAY) SetLayout(new BoxLayout(this, BoxLayout.Y_AXIS)) PlayToggleButton = new JToggleButton("Pause") GetContentPane().setBackground(Color.darkGray) tText("Generation #" + universe.getGeneration()) ĪtText("Alive: " + universe.getAlive()) Ĭid = universe.getCurrentGeneration() Public Universe(int height, int width, int seed, String pattern) Here is the non-GUI part of the code: import
Performance, security, readability, conciseness, and the look-and-feel aspects are all important to me.
I am fairly new to GUI programming and I am interested in improving my code from every aspect.