first commit

This commit is contained in:
2019-08-13 12:23:06 -05:00
commit 916073f43b
337 changed files with 23253 additions and 0 deletions

18
Lab 5/.idea/checkstyle-idea.xml generated Normal file
View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA">
<option name="configuration">
<map>
<entry key="active-configuration" value="LOCAL_FILE:C:/Users/barnestr/Documents/SE 1021/Spring 2018/SE1021_checkStyle - v3.xml:se" />
<entry key="checkstyle-version" value="8.8" />
<entry key="copy-libs" value="true" />
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
<entry key="location-2" value="LOCAL_FILE:C:/Users/barnestr/Documents/SE 1021/Spring 2018/SE1021_checkStyle - v3.xml:se" />
<entry key="scan-before-checkin" value="false" />
<entry key="scanscope" value="JavaOnly" />
<entry key="suppress-errors" value="false" />
</map>
</option>
</component>
</project>

View File

@@ -0,0 +1,6 @@
This folder contains libraries copied from the "Lab 5" project.
It is managed by the CheckStyle-IDEA IDE plugin.
Do not modify this folder while the IDE is running.
When the IDE is stopped, you may delete this folder at any time. It will be recreated as needed.
In order to prevent the CheckStyle-IDEA IDE plugin from creating this folder,
uncheck the "Copy libraries from project directory" option in the CheckStyle-IDEA settings dialog.

23
Lab 5/.idea/compiler.xml generated Normal file
View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

2
Lab 5/.idea/description.html generated Normal file
View File

@@ -0,0 +1,2 @@
<html>Simple <b>JavaFX 2.0</b> application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
</html>

5
Lab 5/.idea/encodings.xml generated Normal file
View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>

7
Lab 5/.idea/gradle.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="gradleHome" value="C:/Program Files (x86)/Gradle/gradle-1.0-rc-3" />
</component>
</project>

12
Lab 5/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectKey">
<option name="state" value="project://e79810c8-c5c8-43b1-b19c-90c1f4095425" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
Lab 5/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Lab 5.iml" filepath="$PROJECT_DIR$/Lab 5.iml" />
</modules>
</component>
</project>

125
Lab 5/.idea/uiDesigner.xml generated Normal file
View File

@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

7
Lab 5/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>

1041
Lab 5/.idea/workspace.xml generated Normal file

File diff suppressed because it is too large Load Diff

12
Lab 5/Lab 5.iml Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<VBox alignment="BOTTOM_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="650.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="barnestr.Controller">
<children>
<Pane fx:id="gamePane" maxHeight="600.0" maxWidth="600.0" minHeight="600.0" minWidth="600.0" onMouseClicked="#mouseClick" prefHeight="600.0" prefWidth="600.0" />
<HBox fx:id="buttons" alignment="CENTER" prefHeight="50.0" prefWidth="600.0">
<children>
<Button fx:id="nextButton" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#iterate" prefWidth="95.0" text="Next">
<opaqueInsets>
<Insets />
</opaqueInsets>
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
</Button>
<Label fx:id="aliveDeadCount" text="Alive: Dead:" />
<Button fx:id="randomizeButton" alignment="BOTTOM_RIGHT" mnemonicParsing="false" onAction="#randomize" prefWidth="95.0" text="Randomize All">
<opaqueInsets>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</opaqueInsets>
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
</Button>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
</HBox>
</children>
</VBox>

View File

@@ -0,0 +1,200 @@
/*
* SE1021
* Winter 2017
* Lab Game Of Life
* Name: Derek Riley (edits by Chris Taylor)
* Created 11/25/2016
*/
package barnestr;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
/**
* This Class represents a cell within John Conway's Game of Life.
* The cell is arranged in a 2D grid and has 8 neighbors (other Cells).
* It contains a Rectangle that is used to visually represent the cell in the JavaFX framework.
*/
public class Cell extends Rectangle {
/**
* This constant represents the scale (size) of the grid in number of pixels
*/
public static final int SCALE = 10;
/**
* This constant represents the color the alive cells are painted
*/
public static final Color ALIVE_COLOR = Color.GREEN;
/**
* This constant represents the color the dead cells are painted
*/
public static final Color DEAD_COLOR = Color.BLACK;
/**
* This variable represents whether the cell is currently alive
*/
private boolean alive;
/**
* This variable represents whether the cell will be alive in the next time tick
*/
private boolean willBeAlive;
/**
* These variables represent the 8 neighbors of the cell
*/
private Cell[][] neighbors = new Cell[3][3];
private final static int ABOVE = 0;
private final static int MIDDLE = 1;
private final static int BELOW = 2;
private final static int LEFT = 0;
private final static int CENTER = 1;
private final static int RIGHT = 2;
/**
* This method returns whether the cell is currently alive or not
* @return true if the cell is currently alive or false if not
*/
public boolean isAlive() {
return alive;
}
/**
* This method sets the cell to be currently alive or not
* @param alive true if the cell is alive or false if not
*/
public void setAlive(boolean alive) {
this.alive = alive;
}
/**
* This method sets the neighbor centered above the current cell
* @param neighborAboveCenter
*/
public void setNeighborAboveCenter(Cell neighborAboveCenter) {
neighbors[ABOVE][CENTER] = neighborAboveCenter;
}
/**
* This method sets the neighbor above and to the right of the current cell
* @param neighborAboveRight
*/
public void setNeighborAboveRight(Cell neighborAboveRight) {
neighbors[ABOVE][RIGHT] = neighborAboveRight;
}
/**
* This method sets the neighbor above and to the left of the current cell
* @param neighborAboveLeft
*/
public void setNeighborAboveLeft(Cell neighborAboveLeft) {
neighbors[ABOVE][LEFT] = neighborAboveLeft;
}
/**
* This method sets the neighbor at the same vertical level but to the right of the current cell
* @param neighborMiddleRight
*/
public void setNeighborMiddleRight(Cell neighborMiddleRight) {
neighbors[MIDDLE][RIGHT] = neighborMiddleRight;
}
/**
* This method sets the neighbor at the same vertical level but to the left of the current cell
* @param neighborMiddleLeft
*/
public void setNeighborMiddleLeft(Cell neighborMiddleLeft) {
neighbors[MIDDLE][LEFT] = neighborMiddleLeft;
}
/**
* This method sets the neighbor below and centered of the current cell
* @param neighborBelowCenter
*/
public void setNeighborBelowCenter(Cell neighborBelowCenter) {
neighbors[BELOW][CENTER] = neighborBelowCenter;
}
/**
* This method sets the neighbor below and to the right of the current cell
* @param neighborBelowRight
*/
public void setNeighborBelowRight(Cell neighborBelowRight) {
neighbors[BELOW][RIGHT] = neighborBelowRight;
}
/**
* This method sets the neighbor below and to the left of the current cell
* @param neighborBelowLeft
*/
public void setNeighborBelowLeft(Cell neighborBelowLeft) {
neighbors[BELOW][LEFT] = neighborBelowLeft;
}
/**
* This constructor creates the cell at the given position within the grid
* @param xPosition the x-Position within the grid
* @param yPosition the y-Position within the grid
*/
public Cell(double xPosition, double yPosition) {
this.setLayoutX(xPosition*SCALE);
this.setLayoutY(yPosition*SCALE);
this.setWidth(SCALE);
this.setHeight(SCALE);
this.alive = false;
this.willBeAlive = false;
updateColors();
}
/**
* This method calculates whether the cell will be alive during the next tick.
*/
public void determineNextTick(){
int neighborsAlive = 0;
for(Cell[] row : neighbors) {
for(Cell neighbor : row) {
if(neighbor!=null && neighbor.isAlive()) {
++neighborsAlive;
}
}
}
runLifeRules(neighborsAlive);
}
/**
* This method updates the cell's life status based on the predicted life status in willBeAlive.
* The cell's Rectangle color is also updated.
*/
public void updateTick(){
alive = willBeAlive;
updateColors();
}
/**
* This method updates the color of the cell based on the ALIVE_COLOR or DEAD_COLOR
*/
public void updateColors(){
if(alive){
this.setFill(ALIVE_COLOR);
} else{
this.setFill(DEAD_COLOR);
}
}
/**
* This method defines the life rules based on the number of neighbors alive
* @param neighborsAlive this is the number of neighbors that are alive for the current cell
*/
private void runLifeRules(int neighborsAlive){
if(neighborsAlive==3) {
willBeAlive = true;
} else if(neighborsAlive<2 || neighborsAlive>3){
willBeAlive = false;
} else{
willBeAlive = alive;
}
}
}

View File

@@ -0,0 +1,84 @@
/*
* SE1021
* Spring 2018
* Lab 5 - Game of Life
* Name: Trevor Barnes
* Created: 4/11/18
*/
package barnestr;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import java.net.URL;
import java.util.ResourceBundle;
/**
* The controller for gameOfLife.fxml
*
* @author Trevor Barnes
* @version 2.0
*/
public class Controller implements Initializable {
@FXML
private Pane gamePane = new Pane();
private LifeGrid game = new LifeGrid(gamePane);
@FXML
private HBox buttons;
@FXML
private Button nextButton;
@FXML
private Label aliveDeadCount;
@FXML
private Button randomizeButton;
@FXML
void mouseClick(MouseEvent location) {
game.setState(location);
labelUpdater();
}
@FXML
void iterate() {
game.iterate();
labelUpdater();
}
@FXML
void randomize() {
game.randomize();
labelUpdater();
}
private void labelUpdater() {
aliveDeadCount.setText("Alive: " + game.aliveCells + " Dead: " + game.deadCells);
}
/**
* The initialize method for the controller
*
* @param location URL
* @param resources ResourceBundle
*/
@Override
public void initialize(URL location, ResourceBundle resources) {
assert gamePane != null : "fx:id=\"gamePane\" was not injected: check your FXML file 'game.fxml'.";
game = new LifeGrid(gamePane);
}
}

View File

@@ -0,0 +1,42 @@
/*
* SE1021
* Spring 2018
* Lab 5 - Game of Life
* Name: Trevor Barnes
* Created: 4/11/18
*/
package barnestr;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
* This class implements the lab5.FXML into the root scene and launches the application window.
* @author barnestr
* @version 2.0
*/
public class Lab5 extends Application {
public static void main(String[] args) {
launch(args);
}
/**
* Starts the primary stage.
* @param primaryStage the base stage
* @throws Exception
*/
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("gameOfLife.fxml"));
primaryStage.setTitle("Game of Life");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}

View File

@@ -0,0 +1,188 @@
/*
* SE1021
* Winter 2017
* Lab Game Of Life
* Name: Derek Riley (edits by Chris Taylor)
* Created 11/25/2016
*/
package barnestr;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import java.util.ArrayList;
import java.util.List;
/**
* This class implements the grid of cells used to model Conway's Game of Life.
*/
public class LifeGrid {
/**
* This instance variable stores the grid of Cells
*/
private List<List<Cell>> cells;
/**
* This instance variable stores the width of the cell grid
*/
private final int numberOfCellsWide;
/**
* This instance variable stores the height of the cell grid
*/
private final int numberOfCellsHigh;
/**
* The amount of dead cells in the LifeGrid
*/
public int deadCells;
/**
* The amount of alive cells in the LifeGrid
*/
public int aliveCells;
/**
* This constructor builds a LifeGrid using the size of the Pane passed and the scale of the cells
*
* @param gamePane viewing pane
*/
public LifeGrid(Pane gamePane) {
this.numberOfCellsWide = (int) gamePane.getPrefWidth() / Cell.SCALE;
this.numberOfCellsHigh = (int) gamePane.getPrefHeight() / Cell.SCALE;
cells = new ArrayList<>();
//initialize the two dimensional ArrayList
for (int i = 0; i < numberOfCellsHigh; i++) {
cells.add(new ArrayList<>());
}
//create cells
for (int i = 0; i < numberOfCellsHigh; i++) { // yPosition
for (int j = 0; j < numberOfCellsWide; j++) { // xPosition
cells.get(i).add(new Cell(j, i));
}
}
//set neighbors for all cells
for (int i = 0; i < numberOfCellsHigh; i++) { // yPosition
for (int j = 0; j < numberOfCellsWide; j++) { // xPosition
if (i > 0) {
if (j > 0) {
cells.get(i).get(j).setNeighborAboveLeft(cells.get(i - 1).get(j - 1));
}
cells.get(i).get(j).setNeighborAboveCenter(cells.get(i - 1).get(j));
if (j < numberOfCellsWide - 1) {
cells.get(i).get(j).setNeighborAboveRight(cells.get(i - 1).get(j + 1));
}
}
if (j > 0) {
cells.get(i).get(j).setNeighborMiddleLeft(cells.get(i).get(j - 1));
}
if (j < numberOfCellsWide - 1) {
cells.get(i).get(j).setNeighborMiddleRight(cells.get(i).get(j + 1));
}
if (i < numberOfCellsHigh - 1) { // bottom boarder elements
if (j > 0) {
cells.get(i).get(j).setNeighborBelowLeft(cells.get(i + 1).get(j - 1));
}
cells.get(i).get(j).setNeighborBelowCenter(cells.get(i + 1).get(j));
if (j < numberOfCellsWide - 1) {
cells.get(i).get(j).setNeighborBelowRight(cells.get(i + 1).get(j + 1));
}
}
}
}
initialize(gamePane);
}
/**
* This method randomizes the life and death attributes of all cells in the cells.
* Cells have a 50% chance of being alive or dead.
*/
public void randomize() {
aliveCells = 0;
deadCells = 0;
final double HALF_CHANCE = .5;
for (List<Cell> row : cells) {
for (Cell cell : row) {
cell.setAlive(Math.random() < HALF_CHANCE);
if (cell.isAlive()) {
aliveCells++;
} else {
deadCells++;
}
cell.updateColors();
}
}
}
/**
* This method triggers one iteration (tick) of the game of life rules for the entire grid.
*/
public void iterate() {
aliveCells = 0;
deadCells = 0;
for (List<Cell> row : cells) {
for (Cell cell : row) {
cell.determineNextTick();
if (cell.isAlive()) {
aliveCells++;
} else {
deadCells++;
}
}
}
for (List<Cell> row : cells) {
for (Cell cell : row) {
cell.updateTick();
}
}
}
/**
* This method adds all the cell rectangles to the Pane
*/
private void initialize(Pane gamePane) {
for (List<Cell> row : cells) {
for (Cell cell : row) {
gamePane.getChildren().add(cell);
}
}
}
/**
* This method takes the location of a mouse click and sets the state of that cell to dead or alive.
*
* @param location the point where the user clicked
*/
public void setState(MouseEvent location) {
final int CELL_SIZE = 10;
for (int i = 0; i < cells.size() * CELL_SIZE; i += CELL_SIZE) {
if (location.getX() < i + CELL_SIZE && location.getX() > i) {
for (int j = 0; j < cells.size() * CELL_SIZE; j += CELL_SIZE) {
if (location.getY() < j + CELL_SIZE && location.getY() > j) {
if (cells.get(j / CELL_SIZE).get(i / CELL_SIZE).isAlive()) {
cells.get(j / CELL_SIZE).get(i / CELL_SIZE).setAlive(false);
cells.get(j / CELL_SIZE).get(i / CELL_SIZE).updateColors();
deadCells++;
aliveCells--;
} else {
cells.get(j / CELL_SIZE).get(i / CELL_SIZE).setAlive(true);
cells.get(j / CELL_SIZE).get(i / CELL_SIZE).updateColors();
aliveCells++;
if (deadCells > 0) {
deadCells--;
}
}
}
}
}
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<VBox alignment="BOTTOM_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="650.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="barnestr.Controller">
<children>
<Pane fx:id="gamePane" maxHeight="600.0" maxWidth="600.0" minHeight="600.0" minWidth="600.0" onMouseClicked="#mouseClick" prefHeight="600.0" prefWidth="600.0" />
<HBox fx:id="buttons" alignment="CENTER" prefHeight="50.0" prefWidth="600.0">
<children>
<Button fx:id="nextButton" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#iterate" prefWidth="95.0" text="Next">
<opaqueInsets>
<Insets />
</opaqueInsets>
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
</Button>
<Label fx:id="aliveDeadCount" text="Alive: Dead:" />
<Button fx:id="randomizeButton" alignment="BOTTOM_RIGHT" mnemonicParsing="false" onAction="#randomize" prefWidth="95.0" text="Randomize All">
<opaqueInsets>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</opaqueInsets>
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
</Button>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
</HBox>
</children>
</VBox>