Skip to content

Commit

Permalink
version 0.0.1.0 (alpha)
Browse files Browse the repository at this point in the history
changelog:
code cleanup
app and field size changed
build release
  • Loading branch information
kadavr95 committed Dec 15, 2016
1 parent 60021f5 commit ad0a8a4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 59 deletions.
8 changes: 8 additions & 0 deletions .idea/artifacts/GameOfLife_jar.xml

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

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

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

3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.coursework.main.Life

28 changes: 14 additions & 14 deletions src/com/coursework/main/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Life model is running on torus surface, where left side is connected with right and bottom side is connected with top one
*/
public class Field extends JPanel{ //field of cells class
private int boardWidthInCells = 200; //board size in number of cells
private int boardHeightInCells = 100;
private int boardWidthInCells = 100; //board size in number of cells
private int boardHeightInCells = 75;
private FieldElement[][] FieldArray = new FieldElement[boardWidthInCells][boardHeightInCells]; //array of cells
private FieldElement[][] FieldArrayNext = new FieldElement[boardWidthInCells][boardHeightInCells]; //array of cells for next step calculation
Field(){ //creation new instance of field
Expand Down Expand Up @@ -49,7 +49,7 @@ void stepCalculation() //next life iteration calculation
private void cellRecalculation(int xIndex, int yIndex) //calculate next cell state
{
int red=0,green=0,blue=0,quantity=0,iIndex,jIndex; //local variable of cell colors, number of cell neighbours and cell indexes
for (int i=(xIndex-1);i<=(xIndex+1);i++) //cycle throught all neighbours of a cell
for (int i=(xIndex-1);i<=(xIndex+1);i++) //cycle through all neighbours of a cell
{
for (int j=(yIndex-1);j<=(yIndex+1);j++)
{
Expand Down Expand Up @@ -136,7 +136,7 @@ public void paint(Graphics g) //field draw
{
int cellSize = 8;
super.paint(g);
for (int i=0;i<boardWidthInCells;i++) //cycle throught all cells
for (int i=0;i<boardWidthInCells;i++) //cycle through all cells
{
for (int j=0;j<boardHeightInCells;j++)
{
Expand All @@ -146,16 +146,16 @@ public void paint(Graphics g) //field draw
}
}

public void setCell(boolean alive, int xIndex, int yIndex) //default call to set new cell
{
FieldArray[xIndex][yIndex].setAlive(alive); //set cell alive
FieldArray[xIndex][yIndex].setChannelRed(255); //set default cell colors
FieldArray[xIndex][yIndex].setChannelGreen(255);
FieldArray[xIndex][yIndex].setChannelBlue(255);
repaint(); //redraw field
}
// void setCell(boolean alive, int xIndex, int yIndex) //default call to set new cell
// {
// FieldArray[xIndex][yIndex].setAlive(alive); //set cell alive
// FieldArray[xIndex][yIndex].setChannelRed(255); //set default cell colors
// FieldArray[xIndex][yIndex].setChannelGreen(255);
// FieldArray[xIndex][yIndex].setChannelBlue(255);
// repaint(); //redraw field
// }

public void setCell(boolean alive, int xIndex, int yIndex, int channelRed, int channelGreen, int channelBlue) //set new cell
void setCell(boolean alive, int xIndex, int yIndex, int channelRed, int channelGreen, int channelBlue) //set new cell
{
FieldArray[xIndex][yIndex].setAlive(alive); //set cell alive
FieldArray[xIndex][yIndex].setChannelRed(channelRed); //set cell colors
Expand All @@ -164,7 +164,7 @@ public void setCell(boolean alive, int xIndex, int yIndex, int channelRed, int c
repaint(); //redraw field
}

public void clearField () //clear field
void clearField () //clear field
{
for (int i=0;i<boardWidthInCells;i++) //cycle through all cells
{
Expand Down
40 changes: 20 additions & 20 deletions src/com/coursework/main/FieldElement.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.coursework.main;

public class FieldElement { //cell class
class FieldElement { //cell class
private int channelRed, channelGreen, channelBlue; //cell color channels
private boolean alive; //cell alive value

Expand All @@ -19,22 +19,22 @@ int getChannelGreen() { //get cell green channel value
int getChannelRed() { //get cell red channel value
return channelRed;
}

void setAlive() { //default call to set cell alive value
this.alive = false;
}

void setChannelBlue() { //default call to set cell blue channel value
this.channelBlue = 0;
}

void setChannelGreen() { //default call to set cell green channel value
this.channelGreen = 0;
}

void setChannelRed() { //default call to set cell red channel value
this.channelRed = 0;
}
//
// void setAlive() { //default call to set cell alive value
// this.alive = false;
// }
//
// void setChannelBlue() { //default call to set cell blue channel value
// this.channelBlue = 0;
// }
//
// void setChannelGreen() { //default call to set cell green channel value
// this.channelGreen = 0;
// }
//
// void setChannelRed() { //default call to set cell red channel value
// this.channelRed = 0;
// }

void setAlive(boolean alive) { //set cell alive value
this.alive = alive;
Expand All @@ -52,7 +52,7 @@ void setChannelRed(int channelRed) { //set cell red channel value
this.channelRed = channelRed;
}

void changeAlive() { //change cell alive value
this.alive^=alive;
}
// void changeAlive() { //change cell alive value
// this.alive^=alive;
// }
}
12 changes: 6 additions & 6 deletions src/com/coursework/main/Life.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Life extends JFrame{ //application frame class
private Field field = new Field(); //create new field
private Timer timer; //create timer

public Life() //create instance of program
private Life() //create instance of program
{
JPanel buttonPanel = new JPanel(); //panel for buttons
InnerListener listener = new InnerListener(); //listener for button events
Expand All @@ -36,9 +36,9 @@ public Life() //create instance of program
btnFaster.addActionListener(listener);
btnAbout.addActionListener(listener);
this.setTitle("Game of Life"); //set frame title
// setResizable(false);
setResizable(false); //disallow resize of window
getContentPane().setBackground(new Color(50,50,50)); //set background color
setSize(1700,900); //set app size
setSize(805,665); //set app size
setLayout(new BorderLayout()); //set border layout
field.setBackground(new Color(32,32,32)); //set field background color
add(field, BorderLayout.CENTER); //add field to center
Expand Down Expand Up @@ -98,7 +98,7 @@ class TimerTick implements ActionListener //timer listener
public void actionPerformed(ActionEvent e) //listener of timer actions
{
field.stepCalculation(); //calculate next state of field
if (simulationRunning==false) //if simulation was stopped
if (!simulationRunning) //if simulation was stopped
{
timer.stop(); //stop timer
}
Expand All @@ -120,7 +120,7 @@ public void actionPerformed(ActionEvent ae) //button actions
}
if (ae.getSource()==btnStart) //if button was Start/Stop
{
if (btnStart.getText()=="Start") //if button was in stop-mode
if (!simulationRunning) //if button was in stop-mode
{
simulationRunning=true; //enter simulation mode
btnStart.setText("Stop"); //change button title
Expand Down Expand Up @@ -174,7 +174,7 @@ public void actionPerformed(ActionEvent ae) //button actions
}
if (ae.getSource()==btnAbout) //if button was About show info about program
{
JOptionPane.showMessageDialog(null, "Game of Life\nversion 0.0.0.11(pre-alpha)\n\nDevelopment: Yaskovich Dmitry\nDesign: Yaskovich Dmitry\nQuality assuarance: Yaskovich Dmitry\n\n© Dimini Inc., 2016");
JOptionPane.showMessageDialog(null, "Game of Life\nversion 0.0.1.0(alpha)\n\nDevelopment: Yaskovich Dmitry\nDesign: Yaskovich Dmitry\nQuality assuarance: Yaskovich Dmitry\n\n© Dimini Inc., 2016");
}
}
}
Expand Down

0 comments on commit ad0a8a4

Please sign in to comment.