-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCellMoveToggle.java
More file actions
82 lines (82 loc) · 3.53 KB
/
CellMoveToggle.java
File metadata and controls
82 lines (82 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* This file is a CellMoveToggle.java file that stores extends to the parent
* CellMoveUp class. The goal of this is to apply
* inheritance to defining the relationship among different types of cells.
* This file is used to help simulate the Conway's Game of Life which is a
* cellular automaton that is simple to understand but has interesting
* properties.
*/
import java.util.*;
/**
* In each class there will be two constructors (one taking the three int
* parameters in the order specified here and one being a copy constructor
* for the current class), override the toString() method, and override the
* checkApoptosis() method. It adjusts the method parameter
* types (specifically for the constructors) appropriately for each class.
* this class takes in CellMoveToggle objects and uses their attributes to
* describe a situation in the game where the cell moves toggle
* @param toggled if the cell is currently "toggled" or not.
*/
public class CellMoveToggle extends CellMoveUp {
public boolean toggled;
/**
* This is the constructor for the CellMoveToggle subclass.
* it Invokes the parent class's constructor to initialize all instance
* variables with the values passed in as arguments.
* @param toggled if the cell is currently "toggled" or not.
* @param currRow stores the current row as an integer
* @param currCol store the current column as an integer
* @param mass stores the mass of the cell as an integer
* @return no return statement in constructor
*/
public CellMoveToggle(int currRow, int currCol, int mass){
super(currRow, currCol, mass);
this.toggled = true;
}
/**
* This is the copy constructor for the CellMoveToggle subclass.
* it can be assumed that the argument is non- null
* it will Invoke the parent class's copy constructor to initialize all
* instance variables with the instance variables of
* the otherCellMoveToggle object passed in as an argument.
* @param toggled if the cell is currently "toggled" or not.
* @param otherCellMoveToggle CellMoveToggle object that is being copied
* @return no return statement in constructor
*/
public CellMoveToggle(CellMoveToggle otherCellMoveToggle){
super(otherCellMoveToggle);
this.toggled = otherCellMoveToggle.toggled;
}
/**
* the String representation of the current object. Each class will have a
* different representation, but each representation will be a single
* character. dependent on whether it is toggled or not
* @param toggled if the cell is currently "toggled" or not.
* @return returns "T" or "t" as the string representation of CellMoveUp
*/
public String toString(){
if(this.toggled==true){
return "T";
}
return "t";
}
/**
* Return true or false based on neighbors depending on the conditions for
* apoptosis. This method does NOT call apoptosis() . This method is only
* for checking whether apoptosis() should be called later.
* Checks for whether this cell has fewer than 2 or greater than 5 neighbors
* @param neighborsMax max number of neighbors to be true
* @param neighborsMin min number of neighbors to be true
* @param neighbors list of neighbors around the cell
* @return boolean based on neighbors depending on the conditions for
* apoptosis
*/
public boolean checkApoptosis(List<Cell> neighbors){
int neighborsMin = 5;
int neighborsMax = 2;
if(neighbors.size()<neighborsMax||neighbors.size()>neighborsMin){
return true;
}
return false;
}
}