Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<properties>
<mockito.version>2.26.0</mockito.version>
<junit.version>5.5.2</junit.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javadoc.plugin.version>3.1.1</javadoc.plugin.version>
<source.plugin.version>3.2.0</source.plugin.version>
Expand Down Expand Up @@ -67,6 +67,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>21</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/ChosenOne.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.awt.*;

public class ChosenOne extends Human {
// TODO: not sure what action to do *maybe make neighbors immune*
// TODO: needs getColor(), toString(), performAction(), isImmune()
public void performAction(Entity[][] grid, double effectRate, int row, int column){

for (int[] dir : DIRECTIONS) {
int newRow = row + dir[0];
int newColumn = column + dir[1];

// Check bounds of grid
if (newRow < 0 || newRow >= grid.length || newColumn < 0 || newColumn >= grid[0].length) continue;

Entity neighbor = grid[newRow][newColumn];

if (neighbor instanceof Human) {
if (Math.random() < effectRate) {
grid[newRow][newColumn].setImmune(true);
}
}
}
}
@Override
public boolean isImmune() { return true;}


@Override
public Color getColor() { return Color.BLUE; }

@Override
public String toString() { return "C"; }

}
32 changes: 32 additions & 0 deletions src/main/java/Entity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.awt.*;

public abstract class Entity {
//checks all possible sorrounding squares with
//each direction.
protected static final int[][] DIRECTIONS = {
{-1, 0}, {1, 0}, {0, -1}, {0, 1},
{-1, 1}, {-1, -1}, {1, 1}, {1, -1}
};

//@override infect or defend depending on object
public abstract void performAction(Entity[][] grid, double effectRate, int row, int column);

//each class gets its own unique color
public abstract Color getColor();


// default = false, subclasses override what they are. Only zombie classes need to override
public boolean isHuman() { return true; }
// TODO: move to human class
//only chosen one is immune

protected boolean immune = false; // default: not immune

public boolean isImmune() {
return immune;
}

public void setImmune(boolean immune) {
this.immune = immune;
}
}
35 changes: 35 additions & 0 deletions src/main/java/Human.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.awt.*;

public class Human extends Entity {
// TODO: not sure what human action is
private boolean immune = false;

@Override
public void performAction(Entity[][] grid, double effectRate, int row, int column){
for (int[] dir : DIRECTIONS) {
int newRow = row + dir[0];
int newCol = column + dir[1];

if (newRow < 0 || newRow >= grid.length || newCol < 0 || newCol >= grid[0].length) continue;

Entity neighbor = grid[newRow][newCol];
if (neighbor.isHuman()) {
if (Math.random() < effectRate) {
neighbor.setImmune(true);
}
}
}
}
@Override
public Color getColor() {
if (this.isImmune())
return Color.ORANGE;
return Color.GREEN;
}
@Override
public String toString() { return "H"; }

public boolean isImmune() { return immune;}

public void setImmune(boolean immune) { this.immune = immune;}
}
35 changes: 35 additions & 0 deletions src/main/java/Medic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.awt.*;

public class Medic extends Human {
@Override // TODO: finish
public void performAction(Entity[][] grid, double effectRate, int row, int column){

//double healRate = effectRate / 100.0;
for (int[] dir : DIRECTIONS) {
int newRow = row + dir[0];
int newColumn = column + dir[1];

// Check bounds of grid
if (newRow < 0 || newRow >= grid.length || newColumn < 0 || newColumn >= grid[0].length) continue;

Entity neighbor = grid[newRow][newColumn];
//make sure it's human and NOT immune
if (!neighbor.isHuman()) {
if (Math.random() < effectRate) {
grid[newRow][newColumn] = new Human(); // chance to heal zombie
}
}
}
}

@Override
public Color getColor() {
if (this.isImmune())
return Color.CYAN;
return Color.YELLOW;
}


@Override
public String toString() { return "M"; }
}
31 changes: 31 additions & 0 deletions src/main/java/Zombie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.awt.*;

public class Zombie extends Entity {

public void performAction(Entity[][] grid, double effectRate, int row, int column) {
//DIRECTIONS from entity class; checks sorrounding neighbors
//Checks first neighbor {-1, 0} -> {row -1, column + 0}...
//double infectionRate = effectRate / 100.0;
for (int[] dir : DIRECTIONS) {
int newRow = row + dir[0];
int newColumn = column + dir[1];

// Check bounds of grid
if (newRow < 0 || newRow >= grid.length || newColumn < 0 || newColumn >= grid[0].length) continue;

Entity neighbor = grid[newRow][newColumn];
//make sure it's human and NOT immune
if (!neighbor.isImmune() && neighbor.isHuman()) {
if (Math.random() < effectRate) {
grid[newRow][newColumn] = new Zombie(); // chance to infect human
}
}
}
}

public Color getColor() { return Color.red; }

public boolean isHuman() { return false;}
@Override
public String toString() { return "Z"; }
}
Loading
Loading