From 5c70363424df27eb26ec9a606db2416daae5763f Mon Sep 17 00:00:00 2001 From: JackNa0928 <60862957+JackNa0928@users.noreply.github.com> Date: Sun, 16 Feb 2020 16:26:19 +0800 Subject: [PATCH] Revert "Add files via upload" --- src/OOAD/Ants.java | 47 ++---- src/OOAD/Bugs.java | 82 +++-------- src/OOAD/Connector.java | 4 +- src/OOAD/Game.java | 250 +++++++++++++++++++++----------- src/OOAD/Location.java | 3 - src/OOAD/NewGame.java | 310 ---------------------------------------- src/OOAD/Organism.java | 15 +- 7 files changed, 204 insertions(+), 507 deletions(-) delete mode 100644 src/OOAD/NewGame.java diff --git a/src/OOAD/Ants.java b/src/OOAD/Ants.java index 373d248..22aa2f5 100644 --- a/src/OOAD/Ants.java +++ b/src/OOAD/Ants.java @@ -1,38 +1,12 @@ package OOAD; public class Ants extends Organism { - private boolean newBreed = false; - private boolean moved = false; - private Location location = new Location(); - - Ants(String name){ - super(name); + public boolean newBreed = false; + public boolean moved = false; + Ants(){ + super.name = "Ants"; } - public boolean isNewBreed() { - return newBreed; - } - - public void setNewBreed(boolean newBreed) { - this.newBreed = newBreed; - } - - public boolean isMoved() { - return moved; - } - - public void setMoved(boolean moved) { - this.moved = moved; - } - - public Location getLocation() { - return location; - } - - public void setLocation(Location location) { - this.location = location; - } - @Override public boolean checkMovement(int current_x, int current_y, int next_x, int next_y) { if((current_x - next_x == 1 || current_x - next_x == -1) && current_y - next_y == 0 && next_x < 20 && next_x >= 0&& next_y < 20 && next_y >= 0) { @@ -47,24 +21,19 @@ else if(current_x - next_x == 0 && (current_y - next_y == 1 || current_y - next_ @Override public Location checkBreed(int current_x, int current_y, Organism[][] backBoard) { if ((current_y - 1) > 0 && backBoard[current_x][current_y - 1] == null ){ - System.out.println("Breed Up"); return new Location(current_x,current_y-1); } else if ((current_y + 1) < 20 && backBoard[current_x][current_y + 1] == null){ - System.out.println("Breed Down"); - return new Location(current_x,current_y+1); + return new Location(current_x,current_y+1); } else if ((current_x + 1) < 20 && backBoard[current_x + 1][current_y] == null ){ - System.out.println("Breed Right"); - return new Location(current_x+1,current_y); + return new Location(current_x+1,current_y); } else if ((current_x - 1 )> 0 && backBoard [current_x-1][current_y] == null ){ - System.out.println("Breed Left"); - return new Location(current_x-1,current_y); + return new Location(current_x-1,current_y); } else - System.out.println("No breed"); - return null; + return null; } @Override diff --git a/src/OOAD/Bugs.java b/src/OOAD/Bugs.java index 27e4976..966fcbc 100644 --- a/src/OOAD/Bugs.java +++ b/src/OOAD/Bugs.java @@ -2,60 +2,16 @@ public class Bugs extends Organism { //parameter - private boolean newBreed = false; - private boolean moved = false; - private int starveRound = 0; - private int antsKill = 0 ; - private Location location = new Location(); - - public Location getLocation() { - return location; - } - - public void setLocation(Location location) { - this.location = location; - } - - Bugs(String name){ - super(name); + public boolean newBreed = false; + public boolean moved = false; + public int starveRound = 0; + Bugs(){ + super.name = "Bugs"; } - - public boolean isNewBreed() { - return newBreed; - } - - public void setNewBreed(boolean newBreed) { - this.newBreed = newBreed; - } - - public boolean isMoved() { - return moved; - } - - public void setMoved(boolean moved) { - this.moved = moved; - } - - public int getAntsKill() { - return antsKill; - } - - public void plusAntsKill() { - this.antsKill++; - } - - public int getStarveRound() { - return starveRound; - } - - public void plusStarveRound() { - this.starveRound++; - } - - public void reserStarveRound() { - this.starveRound = 0; - } + public void resetMoved(){ + moved = false; + } @Override public boolean checkMovement(int current_x, int current_y, int next_x, int next_y) { if((current_x - next_x == 1 || current_x - next_x == -1) && current_y - next_y == 0 && next_x < 20 && next_x >= 0&& next_y < 20 && next_y >= 0) { @@ -70,27 +26,31 @@ else if(current_x - next_x == 0 && (current_y - next_y == 1 || current_y - next_ @Override public Location checkBreed(int current_x, int current_y, Organism[][] backBoard) { if ((current_y - 1) > 0 && backBoard[current_x][current_y - 1] == null ){ - System.out.println("Breed Up"); return new Location(current_x,current_y-1); } else if ((current_y + 1) < 20 && backBoard[current_x][current_y + 1] == null){ - System.out.println("Breed Down"); - return new Location(current_x,current_y+1); + return new Location(current_x,current_y+1); } else if ((current_x + 1) < 20 && backBoard[current_x + 1][current_y] == null ){ - System.out.println("Breed Right"); - return new Location(current_x+1,current_y); + return new Location(current_x+1,current_y); } else if ((current_x - 1 )> 0 && backBoard [current_x-1][current_y] == null ){ - System.out.println("Breed Left"); - return new Location(current_x-1,current_y); + return new Location(current_x-1,current_y); } else - System.out.println("No breed"); - return null; + return null; } + + public boolean isStarving() { + if(starveRound == 3){ + return true; + } + else + return false; + } + /* public static void main(String[] args){ Bugs bugs = new Bugs(); diff --git a/src/OOAD/Connector.java b/src/OOAD/Connector.java index 472e7f7..5ffef30 100644 --- a/src/OOAD/Connector.java +++ b/src/OOAD/Connector.java @@ -11,7 +11,7 @@ public class Connector { private GUI gui = new GUI(); - private NewGame game = new NewGame(); + private Game game = new Game(); private ImageIcon ant = ant(); private ImageIcon bug = bug(); private ImageIcon ant(){ @@ -43,7 +43,7 @@ private ImageIcon bug(){ @Override public void actionPerformed(ActionEvent e) { System.out.println("first row in start button actionlistener"); - game = new NewGame(); + game = new Game(); gui.counter = 0; gui.counter++; gui.startBtn.setEnabled(false); diff --git a/src/OOAD/Game.java b/src/OOAD/Game.java index 900fa8c..0921732 100644 --- a/src/OOAD/Game.java +++ b/src/OOAD/Game.java @@ -1,6 +1,5 @@ package OOAD; -import java.util.ArrayList; import java.util.Random; public class Game { @@ -10,8 +9,6 @@ public class Game { private int round = 0; private int noOfBugs = 0; private int noOfAnts = 0; - private ArrayList antsArray = new ArrayList(); - private ArrayList bugsArray = new ArrayList(); private boolean game_End = false; private Random random = new Random(); @@ -25,22 +22,19 @@ public class Game { if (backBoard[x][y] != null) { i--; } else - noOfAnts++; - backBoard[x][y] = new Ants("Ant"+noOfAnts); - antsArray.add((Ants)backBoard[x][y]); + backBoard[x][y] = new Ants(); } + noOfAnts =100; for (int i = 0; i < 5; i++) { int x = random.nextInt(20); int y = random.nextInt(20); if (backBoard[x][y] != null) { i--; } else { - noOfBugs++; - backBoard[x][y] = new Bugs("Bug"+noOfBugs); - bugsArray.add((Bugs)backBoard[x][y]); + backBoard[x][y] = new Bugs(); } } - + noOfBugs = 5; tempX = 0; tempY = 0; @@ -106,18 +100,27 @@ public void gameFlow(){ } } System.out.println("Check starve done"); - System.out.println("Check bug starve status."); - for(int i = 0 ; i < bugsArray.size() ; i++) + } + /**************************************************************************/ + //CATEGORY : STARVATION + //Starve + public void starve(int this_x, int this_y){ + if(backBoard[this_x][this_y] instanceof Bugs) { - System.out.println(bugsArray.get(i).name+" Kills "+bugsArray.get(i).getAntsKill()); - System.out.println(bugsArray.get(i).name+" Starve "+bugsArray.get(i).getStarveRound()); + if (((Bugs)backBoard[this_x][this_y]).isStarving()) { + backBoard[this_x][this_y] = null; + noOfBugs--; + System.out.println("Bug is dead"); + } } - System.out.println(round); - System.out.println(noOfAnts); - System.out.println(noOfBugs); - System.out.println("Round End"); + } + /**************************************************************************/ + + //CATEGORY : MOVE + + //check for ants public void checkPrey(int x,int y){ if(backBoard[x][y].checkMovement(x, y, x+1, y)){ if(backBoard[x+1][y] instanceof Ants){ @@ -127,79 +130,164 @@ public void checkPrey(int x,int y){ System.out.println("Bugs eat down"); move(x,y,tempX,tempY); ((Bugs) backBoard[tempX][tempY]).moved = true; - ((Bugs)backBoard[tempX][tempY]).plusAntsKill(); noOfAnts--; } - else if(backBoard[x][y].checkMovement(x, y, x-1, y)){ - if(backBoard[x-1][y] instanceof Ants){ - tempX = x-1; - tempY = y; - ((Bugs)backBoard[x][y]).starveRound = 0; - System.out.println("Bugs eat up"); - move(x,y,tempX,tempY); - ((Bugs) backBoard[tempX][tempY]).moved = true; - ((Bugs)backBoard[tempX][tempY]).plusAntsKill(); - noOfAnts--; - } - else if(backBoard[x][y].checkMovement(x, y, x, y+1)) { - if (backBoard[x][y + 1] instanceof Ants) { - tempX = x; - tempY = y + 1; - ((Bugs) backBoard[x][y]).starveRound = 0; - System.out.println("Bugs eat right"); - move(x,y,tempX,tempY); - ((Bugs) backBoard[tempX][tempY]).moved = true; - ((Bugs)backBoard[tempX][tempY]).plusAntsKill(); - noOfAnts--; - } - else if(backBoard[x][y].checkMovement(x, y, x, y-1)) { - if (backBoard[x][y - 1] instanceof Ants) { - tempX = x; - tempY = y - 1; - ((Bugs) backBoard[x][y]).starveRound = 0; - System.out.println("Bugs eat left"); - move(x,y,tempX,tempY); - ((Bugs) backBoard[tempX][tempY]).moved = true; - ((Bugs)backBoard[tempX][tempY]).plusAntsKill(); - noOfAnts--; - } - else if(backBoard[x][y].checkMovement(x, y, x, y-1)) { - if (backBoard[x][y - 1] instanceof Ants) { - tempX = x; - tempY = y - 1; - ((Bugs) backBoard[x][y]).starveRound = 0; - System.out.println("Bugs eat left"); - move(x,y,tempX,tempY); - ((Bugs) backBoard[tempX][tempY]).moved = true; - ((Bugs)backBoard[tempX][tempY]).plusAntsKill(); - noOfAnts--; - } - else if(backBoard[x][y].checkMovement(x, y, x+random.nextInt(2)-1, y+random.nextInt(2)-1)){ - tempX = x+random.nextInt(2)-1; - tempY = y+random.nextInt(2)-1; - if(backBoard[tempY][tempY] == null) { - ((Bugs)backBoard[x][y]).starveRound++; - System.out.println("bug moved to null"); - move(x,y,tempX,tempY); - ((Bugs) backBoard[tempX][tempY]).moved = true; - } - else{ - System.out.println("Bugs stay same place"); - ((Bugs)backBoard[x][y]).starveRound++; + } + else if(backBoard[x][y].checkMovement(x, y, x-1, y)){ + if(backBoard[x-1][y] instanceof Ants){ + tempX = x-1; + tempY = y; + ((Bugs)backBoard[x][y]).starveRound = 0; + System.out.println("Bugs eat up"); + move(x,y,tempX,tempY); + ((Bugs) backBoard[tempX][tempY]).moved = true; + noOfAnts--; + } + } + else if(backBoard[x][y].checkMovement(x, y, x, y+1)) { + if (backBoard[x][y + 1] instanceof Ants) { + tempX = x; + tempY = y + 1; + ((Bugs) backBoard[x][y]).starveRound = 0; + System.out.println("Bugs eat right"); + move(x,y,tempX,tempY); + ((Bugs) backBoard[tempX][tempY]).moved = true; + noOfAnts--; + } + } + else if(backBoard[x][y].checkMovement(x, y, x, y-1)) { + if (backBoard[x][y - 1] instanceof Ants) { + tempX = x; + tempY = y - 1; + ((Bugs) backBoard[x][y]).starveRound = 0; + System.out.println("Bugs eat left"); + move(x,y,tempX,tempY); + ((Bugs) backBoard[tempX][tempY]).moved = true; + noOfAnts--; + } + } + else if(backBoard[x][y].checkMovement(x, y, x+random.nextInt(2)-1, y+random.nextInt(2)-1)){ + tempX = x+random.nextInt(2)-1; + tempY = y+random.nextInt(2)-1; + if(backBoard[tempY][tempY] == null) { + ((Bugs)backBoard[x][y]).starveRound++; + System.out.println("bug moved to null"); + move(x,y,tempX,tempY); + ((Bugs) backBoard[tempX][tempY]).moved = true; + } + else{ + System.out.println("Bugs stay same place"); + ((Bugs)backBoard[x][y]).starveRound++; + } + } + + } + + + //ants movement + public void AntsMove() { + int noOfMovedAnts = 0; + while (noOfMovedAnts < noOfAnts) { + for(int y = 0; y < 20; y++){ + for(int x = 0; x< 20; x++) { + if (backBoard[x][y] instanceof Ants) { + if (!((Ants) backBoard[x][y]).moved) { + tempX = x + random.nextInt(2) - 1; + tempY = y + random.nextInt(2) - 1; + + if (backBoard[x][y].checkMovement(x, y, tempX, tempY)) { + if (backBoard[tempX][tempY] == null) { + + move(x, y, tempX, tempY); + ((Ants) backBoard[tempX][tempY]).moved = true; + + } } + + + noOfMovedAnts++; } - } - } + } + } + } + + } + } + + //Move + public void move(int current_x, int current_y, int next_x, int next_y){ + backBoard[next_x][next_y] = backBoard[current_x][current_y]; + backBoard[current_x][current_y]= null; + } + + + /**************************************************************************/ + //CATEGORY : BREED + //breed + public void antsBreed(){ + Ants temp = new Ants(); + backBoard[tempX][tempY] = temp; + backBoard[tempX][tempY].newBreed = true; + } + public void bugsBreed(){ + backBoard[tempX][tempY] = new Bugs(); + backBoard[tempX][tempY].newBreed = true; + } + + //get location + public static void getLocation(int x, int y){ + tempX = x; + tempY = y; + } + + //for ant to breed + public void antBreeding(){ + for(int y = 0; y < 20; y++) { + for (int x = 0; x < 20; x++) { + if(backBoard[x][y] instanceof Ants){ + if(!backBoard[x][y].newBreed) { + if (backBoard[x][y].checkBreed(x, y, backBoard) != null) { + tempX = backBoard[x][y].checkBreed(x, y, backBoard).getCoor_x(); + tempY = backBoard[x][y].checkBreed(x, y, backBoard).getCoor_y(); + noOfAnts++; + antsBreed(); + } + } + } + } + } + } + + //for bug to breed + public void bugBreeding(){ + for(int y = 0; y < 20; y++) { + for (int x = 0; x < 20; x++) { + if(backBoard[x][y] instanceof Bugs){ + if(!backBoard[x][y].newBreed) { + if (backBoard[x][y].checkBreed(x, y, backBoard) != null) { + tempX = backBoard[x][y].checkBreed(x, y, backBoard).getCoor_x(); + tempY = backBoard[x][y].checkBreed(x, y, backBoard).getCoor_y(); + noOfBugs++; + bugsBreed(); + } + } } } } - - - - + } + public void resetBreed(){ + for(int y = 0; y < 20; y++) { + for (int x = 0; x < 20; x++) { + if(backBoard[x][y] != null){ + backBoard[x][y].newBreed = false; + } + } + } } + /**************************************************************************/ + //CATEGORY : CONNECTOR //send the 2d array GUI diff --git a/src/OOAD/Location.java b/src/OOAD/Location.java index faa1a44..9f61cfb 100644 --- a/src/OOAD/Location.java +++ b/src/OOAD/Location.java @@ -10,9 +10,6 @@ public class Location { setCoor_y(y); } - public Location() { - } - public int getCoor_x() { return coor_x; } diff --git a/src/OOAD/NewGame.java b/src/OOAD/NewGame.java deleted file mode 100644 index 3a19b96..0000000 --- a/src/OOAD/NewGame.java +++ /dev/null @@ -1,310 +0,0 @@ -package OOAD; - -import java.util.ArrayList; -import java.util.Random; - -public class NewGame { - public Organism[][] backBoard = new Organism[20][20]; - private int round = 0; - private int noOfBugs = 0; - private int noOfAnts = 0; - private ArrayList antsArray = new ArrayList(); - private ArrayList bugsArray = new ArrayList(); - - private boolean game_End = false; - private Random random = new Random(); - - NewGame() { - Random random = new Random(); - for (int i = 0; i < 100; i++) { - int x = random.nextInt(20); - int y = random.nextInt(20); - if (backBoard[x][y] != null) { - i--; - } else { - noOfAnts++; - Location tempLo = new Location(x, y); - backBoard[x][y] = new Ants("Ant" + noOfAnts); - ((Ants) backBoard[x][y]).setLocation(tempLo); - antsArray.add((Ants) backBoard[x][y]); - } - } - for (int i = 0; i < 5; i++) { - int x = random.nextInt(20); - int y = random.nextInt(20); - if (backBoard[x][y] != null) { - i--; - } else { - noOfBugs++; - Location tempLo = new Location(x, y); - backBoard[x][y] = new Bugs("Bug" + noOfBugs); - ((Bugs) backBoard[x][y]).setLocation(tempLo); - bugsArray.add((Bugs) backBoard[x][y]); - } - } - } - - public void starve() { - for (int i = 0; i < bugsArray.size(); i++) - if (bugsArray.get(i).getStarveRound() == 3) { - backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i).getLocation() - .getCoor_y()] = null; - bugsArray.remove(i); - } - } - - // for ant to breed - public void antBreeding() { - int breedingAnts = antsArray.size(); - for (int i = 0; i < breedingAnts; i++) { - if (!antsArray.get(i).isNewBreed()) { - Location tempLoc = backBoard[antsArray.get(i).getLocation().getCoor_x()][antsArray.get(i).getLocation() - .getCoor_y()].checkBreed(antsArray.get(i).getLocation().getCoor_x(), - antsArray.get(i).getLocation().getCoor_y(), backBoard); - if (tempLoc != null) { - noOfAnts++; - backBoard[tempLoc.getCoor_x()][tempLoc.getCoor_y()] = new Ants("Ant" + noOfAnts); - Location tempLo = new Location(tempLoc.getCoor_x(), tempLoc.getCoor_y()); - ((Ants) backBoard[tempLoc.getCoor_x()][tempLoc.getCoor_y()]).setLocation(tempLo); - ((Ants) backBoard[tempLoc.getCoor_x()][tempLoc.getCoor_y()]).setNewBreed(true); - ; - antsArray.add((Ants) backBoard[tempLoc.getCoor_x()][tempLoc.getCoor_y()]); - } - } - } - } - - // for bug to breed - public void bugBreeding() { - int breedingBugs = bugsArray.size(); - for (int i = 0; i < breedingBugs; i++) { - if (!bugsArray.get(i).isNewBreed()) { - Location tempLoc = backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i).getLocation() - .getCoor_y()].checkBreed(bugsArray.get(i).getLocation().getCoor_x(), - bugsArray.get(i).getLocation().getCoor_y(), backBoard); - if (tempLoc != null) { - noOfBugs++; - backBoard[tempLoc.getCoor_x()][tempLoc.getCoor_y()] = new Bugs("Bugs" + noOfBugs); - Location tempLo = new Location(tempLoc.getCoor_x(), tempLoc.getCoor_y()); - ((Bugs) backBoard[tempLoc.getCoor_x()][tempLoc.getCoor_y()]).setLocation(tempLo); - ((Bugs) backBoard[tempLoc.getCoor_x()][tempLoc.getCoor_y()]).setNewBreed(true); - ; - bugsArray.add((Bugs) backBoard[tempLoc.getCoor_x()][tempLoc.getCoor_y()]); - } - } - } - } - - public void resetBugsBreed() { - for (int i = 0; i < bugsArray.size(); i++) { - bugsArray.get(i).setNewBreed(false); - } - } - - public void resetAntsBreed() { - for (int i = 0; i < antsArray.size(); i++) { - antsArray.get(i).setNewBreed(false); - } - } - - public void resetBugsMove() { - for (int i = 0; i < bugsArray.size(); i++) { - bugsArray.get(i).setMoved(false); - } - } - - public void resetAntsMove() { - for (int i = 0; i < antsArray.size(); i++) { - antsArray.get(i).setMoved(false); - } - } - - public void antsMove() { - for (int i = 0; i < antsArray.size(); i++) { - if (!antsArray.get(i).isMoved()) { - int tempX = antsArray.get(i).getLocation().getCoor_x() + random.nextInt(2) - 1; - int tempY = antsArray.get(i).getLocation().getCoor_y() + random.nextInt(2) - 1; - if (antsArray.get(i).checkMovement(antsArray.get(i).getLocation().getCoor_x(), - antsArray.get(i).getLocation().getCoor_y(), tempX, tempY)) { - if (backBoard[tempX][tempY] == null) { - backBoard[tempX][tempY] = backBoard[antsArray.get(i).getLocation().getCoor_x()][antsArray.get(i) - .getLocation().getCoor_y()]; - backBoard[antsArray.get(i).getLocation().getCoor_x()][antsArray.get(i).getLocation() - .getCoor_y()] = null; - ((Ants) backBoard[tempX][tempY]).setMoved(true); - ((Ants) backBoard[tempX][tempY]).getLocation().setCoor_x(tempX); - ((Ants) backBoard[tempX][tempY]).getLocation().setCoor_y(tempY); - antsArray.get(i).setMoved(true); - antsArray.get(i).getLocation().setCoor_x(tempX); - antsArray.get(i).getLocation().setCoor_y(tempY); - } - } - - } - } - } - - public void bugsMove() { - for (int i = 0; i < bugsArray.size(); i++) { - if (!bugsArray.get(i).isMoved()) { - Location tempLocA = new Location(bugsArray.get(i).getLocation().getCoor_x(), - bugsArray.get(i).getLocation().getCoor_y() + 1); // top - Location tempLocB = new Location(bugsArray.get(i).getLocation().getCoor_x(), - bugsArray.get(i).getLocation().getCoor_y() - 1); // btm - Location tempLocC = new Location(bugsArray.get(i).getLocation().getCoor_x() - 1, - bugsArray.get(i).getLocation().getCoor_y()); // left - Location tempLocD = new Location(bugsArray.get(i).getLocation().getCoor_x() + 1, - bugsArray.get(i).getLocation().getCoor_y()); // right - Location tempLocE = new Location(bugsArray.get(i).getLocation().getCoor_x() + random.nextInt(2) - 1, - bugsArray.get(i).getLocation().getCoor_y() + random.nextInt(2) - 1); // rand - if (prey(tempLocA, i)) { - antsArray.remove((Ants)backBoard[tempLocA.getCoor_x()][tempLocA - .getCoor_y()]); - backBoard[tempLocA.getCoor_x()][tempLocA - .getCoor_y()] = backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i) - .getLocation().getCoor_y()]; - backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i).getLocation() - .getCoor_y()] = null; - ((Bugs) backBoard[tempLocA.getCoor_x()][tempLocA.getCoor_y()]).getLocation() - .setCoor_x(tempLocA.getCoor_x()); - ((Bugs) backBoard[tempLocA.getCoor_x()][tempLocA.getCoor_y()]).getLocation() - .setCoor_x(tempLocA.getCoor_y()); - ((Bugs) backBoard[tempLocA.getCoor_x()][tempLocA.getCoor_y()]).setMoved(true); - bugsArray.get(i).setMoved(true); - bugsArray.get(i).getLocation().setCoor_x(tempLocA.getCoor_x()); - bugsArray.get(i).getLocation().setCoor_y(tempLocA.getCoor_y()); - bugsArray.get(i).plusAntsKill(); - bugsArray.get(i).reserStarveRound(); - - } else if (prey(tempLocB, i)) { - antsArray.remove((Ants)backBoard[tempLocB.getCoor_x()][tempLocB - .getCoor_y()]); - backBoard[tempLocB.getCoor_x()][tempLocB - .getCoor_y()] = backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i) - .getLocation().getCoor_y()]; - backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i).getLocation() - .getCoor_y()] = null; - ((Bugs) backBoard[tempLocB.getCoor_x()][tempLocB.getCoor_y()]).getLocation() - .setCoor_x(tempLocB.getCoor_x()); - ((Bugs) backBoard[tempLocB.getCoor_x()][tempLocB.getCoor_y()]).getLocation() - .setCoor_x(tempLocB.getCoor_y()); - ((Bugs) backBoard[tempLocB.getCoor_x()][tempLocB.getCoor_y()]).setMoved(true); - bugsArray.get(i).setMoved(true); - bugsArray.get(i).getLocation().setCoor_x(tempLocB.getCoor_x()); - bugsArray.get(i).getLocation().setCoor_y(tempLocB.getCoor_y()); - bugsArray.get(i).plusAntsKill(); - bugsArray.get(i).reserStarveRound(); - - - } else if (prey(tempLocC, i)) { - antsArray.remove((Ants)backBoard[tempLocC.getCoor_x()][tempLocC - .getCoor_y()]); - backBoard[tempLocC.getCoor_x()][tempLocC - .getCoor_y()] = backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i) - .getLocation().getCoor_y()]; - backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i).getLocation() - .getCoor_y()] = null; - ((Bugs) backBoard[tempLocC.getCoor_x()][tempLocC.getCoor_y()]).getLocation() - .setCoor_x(tempLocC.getCoor_x()); - ((Bugs) backBoard[tempLocC.getCoor_x()][tempLocC.getCoor_y()]).getLocation() - .setCoor_x(tempLocC.getCoor_y()); - ((Bugs) backBoard[tempLocC.getCoor_x()][tempLocC.getCoor_y()]).setMoved(true); - bugsArray.get(i).setMoved(true); - bugsArray.get(i).getLocation().setCoor_x(tempLocC.getCoor_x()); - bugsArray.get(i).getLocation().setCoor_y(tempLocC.getCoor_y()); - bugsArray.get(i).plusAntsKill(); - bugsArray.get(i).reserStarveRound(); - - - } else if ((prey(tempLocD, i))) { - antsArray.remove((Ants)backBoard[tempLocD.getCoor_x()][tempLocD - .getCoor_y()]); - backBoard[tempLocD.getCoor_x()][tempLocD - .getCoor_y()] = backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i) - .getLocation().getCoor_y()]; - backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i).getLocation() - .getCoor_y()] = null; - ((Bugs) backBoard[tempLocD.getCoor_x()][tempLocD.getCoor_y()]).getLocation() - .setCoor_x(tempLocD.getCoor_x()); - ((Bugs) backBoard[tempLocD.getCoor_x()][tempLocD.getCoor_y()]).getLocation() - .setCoor_x(tempLocD.getCoor_y()); - ((Bugs) backBoard[tempLocD.getCoor_x()][tempLocD.getCoor_y()]).setMoved(true); - bugsArray.get(i).setMoved(true); - bugsArray.get(i).getLocation().setCoor_x(tempLocD.getCoor_x()); - bugsArray.get(i).getLocation().setCoor_y(tempLocD.getCoor_y()); - bugsArray.get(i).plusAntsKill(); - bugsArray.get(i).reserStarveRound(); - - } else if (bugsArray.get(i).checkMovement(bugsArray.get(i).getLocation().getCoor_x(), - bugsArray.get(i).getLocation().getCoor_y(), tempLocE.getCoor_x(), tempLocE.getCoor_y())) { - if (backBoard[tempLocE.getCoor_x()][tempLocE.getCoor_y()] == null) { - backBoard[tempLocE.getCoor_x()][tempLocE - .getCoor_y()] = backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i) - .getLocation().getCoor_y()]; - backBoard[bugsArray.get(i).getLocation().getCoor_x()][bugsArray.get(i).getLocation() - .getCoor_y()] = null; - ((Bugs) backBoard[tempLocE.getCoor_x()][tempLocE.getCoor_y()]).getLocation() - .setCoor_x(tempLocE.getCoor_x()); - ((Bugs) backBoard[tempLocE.getCoor_x()][tempLocE.getCoor_y()]).getLocation() - .setCoor_x(tempLocE.getCoor_y()); - ((Bugs) backBoard[tempLocE.getCoor_x()][tempLocE.getCoor_y()]).setMoved(true); - bugsArray.get(i).setMoved(true); - bugsArray.get(i).getLocation().setCoor_x(tempLocE.getCoor_x()); - bugsArray.get(i).getLocation().setCoor_y(tempLocE.getCoor_y()); - bugsArray.get(i).plusStarveRound(); - } else { - bugsArray.get(i).plusStarveRound(); - bugsArray.get(i).setMoved(true); - - } - - }else - { - bugsArray.get(i).plusStarveRound(); - bugsArray.get(i).setMoved(true); - } - } - } - } - - public boolean prey(Location e, int index) { - if (bugsArray.get(index).checkMovement(bugsArray.get(index).getLocation().getCoor_x(), - bugsArray.get(index).getLocation().getCoor_y(), e.getCoor_x(), e.getCoor_y())) { - if (backBoard[e.getCoor_x()][e.getCoor_y()] instanceof Ants) { - return true; - } - } - return false; - } - - public void gameFlow() { - round++; - System.out.println(round); - System.out.println(antsArray.size()); - System.out.println(bugsArray.size()); - bugsMove(); - antsMove(); - resetAntsMove(); - resetBugsMove(); - if (round % 3 == 0) { - antBreeding(); - resetAntsBreed(); - } - if (round % 8 == 0) { - bugBreeding(); - resetBugsBreed(); - } - starve(); - for (int i = 0; i < bugsArray.size(); i++) { - System.out.println(bugsArray.get(i).getName() + " Kills " + bugsArray.get(i).getAntsKill()); - System.out.println(bugsArray.get(i).getName() + " Starve " + bugsArray.get(i).getStarveRound()); - } - System.out.println(round); - System.out.println(antsArray.size()); - System.out.println(bugsArray.size()); - System.out.println(); - System.out.println("**************************************************************************************************************"); - System.out.println(); - - } -} diff --git a/src/OOAD/Organism.java b/src/OOAD/Organism.java index 8e3670e..4f4cf6c 100644 --- a/src/OOAD/Organism.java +++ b/src/OOAD/Organism.java @@ -1,24 +1,17 @@ package OOAD; public abstract class Organism { - private String name; - private boolean moved; - private boolean newBreed; + public String name; + public boolean moved; + public boolean newBreed; - Organism(String name) - { - this.name = name; - } public boolean checkMovement(int current_x, int current_y, int next_x, int next_y){ return false; } public Location checkBreed(int current_x, int current_y, Organism[][] backBoard){ return null; } - public String getName() { - return name; - } - public boolean death(int counter){ + public boolean death(int counter){ return false; } }