public class GameOfLife
extends java.lang.Object
| Constructor and Description |
|---|
GameOfLife() |
| Modifier and Type | Method and Description |
|---|---|
static void |
clearWorld(boolean[][] world)
Sets all the cells in the world to not alive (false).
|
static boolean[][] |
createNewWorld(int numRows,
int numColumns)
Create a new world
|
static void |
initializeBeacon(boolean[][] world)
Initializes the world to the Beacon pattern.
|
static void |
initializeBoat(boolean[][] world)
Initializes the world to the Boat pattern.
|
static void |
initializeGlider(boolean[][] world)
Initializes the world to the Glider pattern.
|
static void |
initializeRandomWorld(boolean[][] world)
Initialize the GameOfLife world with a random selection of cells alive.
|
static void |
initializeRpentomino(boolean[][] world)
Initializes the world to the R-pentomino pattern.
|
static boolean |
isCellLivingInNextGeneration(int numLivingNeighbors,
boolean cellCurrentlyLiving)
Whether a cell is living in the next generation of the game.
|
static boolean |
isNeighborAlive(boolean[][] world,
int neighborCellRow,
int neighborCellColumn)
Whether a specific neighbor is alive.
|
static void |
main(java.lang.String[] args)
Program execution starts here.
|
static void |
nextGeneration(boolean[][] currentWorld,
boolean[][] newWorld)
Creates the next generation of the world.
|
static int |
numNeighborsAlive(boolean[][] world,
int cellRow,
int cellColumn)
Counts the number of neighbors that are currently living around the
specified cell.
|
static void |
printWorld(java.lang.String patternName,
boolean[][] world,
int generationNum)
Prints out the world showing each cell as alive or dead.
|
public static void main(java.lang.String[] args)
args - UNUSEDpublic static boolean[][] createNewWorld(int numRows,
int numColumns)
numRows - The number of rows to be in the created worldnumColumns - The number of columns to be in the created worldpublic static void clearWorld(boolean[][] world)
world - the world to clear all cellspublic static void initializeGlider(boolean[][] world)
.......... .@........ ..@@...... .@@....... .......... .......... .......... .......... .......... ..........
world - the existing double dimension array that will be
reinitialized to the Glider pattern.public static void initializeBeacon(boolean[][] world)
.......... .@@....... .@........ ....@..... ...@@..... .......... .......... .......... .......... ..........
world - the existing double dimension array that will be
reinitialized to the Beacon pattern.public static void initializeBoat(boolean[][] world)
.......... .@@....... .@.@...... ..@....... .......... .......... .......... .......... .......... ..........
world - the existing double dimension array that will be
reinitialized to the Boat pattern.public static void initializeRpentomino(boolean[][] world)
.......... ..@@...... .@@....... ..@....... .......... .......... .......... .......... .......... ..........
world - the existing double dimension array that will be
reinitialized to the R-pentomino pattern.public static void initializeRandomWorld(boolean[][] world)
world - the existing double dimension array that will be
reinitialized to a Random pattern.public static boolean isCellLivingInNextGeneration(int numLivingNeighbors,
boolean cellCurrentlyLiving)
numLivingNeighbors - The number of neighbors that are currently
living.cellCurrentlyLiving - Whether the cell is currently living.public static boolean isNeighborAlive(boolean[][] world,
int neighborCellRow,
int neighborCellColumn)
world - The current world.neighborCellRow - The row of the cell which we are wanting to know
is alive.neighborCellColumn - The column of the cell for which we are wanting
to know is alive.public static int numNeighborsAlive(boolean[][] world,
int cellRow,
int cellColumn)
world - The current world.cellRow - The row of the cell for which we are looking for neighbors.cellColumn - The column of the cell for which we are looking for
neighbors.public static void nextGeneration(boolean[][] currentWorld,
boolean[][] newWorld)
currentWorld - The world currently shown.newWorld - The new world to determine by looking at
each cells neighbors in the current world.public static void printWorld(java.lang.String patternName,
boolean[][] world,
int generationNum)
patternName - The name of the pattern chosen by the user.world - The array representation of the current world.generationNum - The number of the current generation.