This project was about programming a functioning version of Conway's Game of Life. The purpose of this project was to learn about Java and 2 dimension arrays and nested for loops. I used the 2D array to store the grid of cells that form the Game of Life, and the nested for loops to run through them and access each value. Each cell is stored at a different position, and updated according to the rules of Conway's Game of Life.
The main data structure used in this project was a 2D Array. It stores data in a grid of fixed sized. It actually stores an Array of Arrays, which can be used like a 2 dimensional grid. Nested for loops were also important to this project. They are linked to the 2D Array because as the outer for loop is looping through the Array of Arrays, the inner for loop is looping through each Array of Objects. In this way each Object in the 2D Array can be accessed one by one.
Specifically, in this project each location within the 2D Array stores a Cell with an alive or dead state. Each update the Landscape class will loop through the 2D Array of Cells and find all the adjacent cells of each one. It then creates a copy of the 2D Array with a copy of all the Cells and updates each Cell copies alive state according to the neighbors of the original Cell. Once Landscape has run through the entire nested for loop, it sets the original 2D Array to be equal to the copy, thus updating every cell in the grid according to the rules of Conway's Game of Life.
Below is the initial state of the grid. Note, the below configuration is randomly generated.
Below is the state of the same grid after one update.
Below is a gif the program running through about twenty updates.
I added controls that will allow the user to toggle the grid, clear the cells on the screen, a function to pause updates and toggle cells from alive to dead and vice versa, and reset the screen to a random configuration.
There are also options to set the colors of the alive cells, dead cells, and the grid. Additionally there is a slider to adjust the time between updates. Finally I made the screen automatically re-scale when the window size is adjusted.
I learned how to use generics and use them to implement a data structure. I also learned how to shuffle data more effectively. Additionally, I learned how to use time and random numbers in java.