Actor[] actorArray = new Actor[100]; ActorWorld world = new ActorWorld(); Random randColor = new Random(); int red = 0; int blue = 0; int yellow = 0; int black = 0; int green = 0;
public SearchWorld() { super(new BoundedGrid<Actor>(10, 10)); //nested loops to load random actors of random colors into the world
ArrayList<Color> colorArray = new ArrayList<Color>(); colorArray.add(Color.red); colorArray.add(Color.blue); colorArray.add(Color.yellow); colorArray.add(Color.black); colorArray.add(Color.GREEN);
for (int i = 0; i <= 10; i++) { for (int c = 0; c < 10; c++) {
for (int r = 0; r < 10; r++) { actorArray[i] = new Bug(colorArray.get(randColor.nextInt(5)));
public SearchWorld(int rows, int cols) { //use the constructor above as an example for (int r = 0; r < 10; r++) { for (int c = 0; c < 10; c++) {
Location loc = new Location(r,c);
for (int i = 0; i <= 10; i++) { if (actorArray[i].getColor()==Color.RED){ red++; } // for (int r = 0; r < 11; r++) { // if (actorArray[r].getColor()==Color.RED){ // red++; // } // if (actorArray[r].getColor()==Color.BLUE){ // blue++; // } // if (actorArray[r].getColor()==Color.YELLOW){ // yellow++; // } // if (actorArray[r].getColor()==Color.BLACK){ // black++; // } // if (actorArray[r].getColor()==Color.GREEN){ // green++; // }
} } }
public int getNumXColoredActors(Color col) { if(col==Color.RED){ System.out.println("Number of RED Actors: "+red); } if(col==Color.BLUE){ System.out.println("Number of BLUE Actors: "+blue); } if(col==Color.BLACK){ System.out.println("Number of BLACK Actors: "+black); } if(col==Color.YELLOW){ System.out.println("Number of YELLOW Actors: "+yellow); } if(col==Color.GREEN){ System.out.println("Number of GREEN Actors: "+green); } else{ return -1; } return -1; } public void colorX(){ System.out.println("RED ACTORS: "+red); } public static void main(String[] args) { SearchWorld m = new SearchWorld();
} } // for (int r = 0; r < 10; r++) { // for (int c = 0; c < 10; c++) { // // // // // // // // world.add(new Location(r, 0), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 1), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 2), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 3), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 4), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 5), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 6), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 7), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 8), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 9), new Bug(colorArray.get(randColor.nextInt(5))));
Actor[] actorArray = new Actor[100]; ActorWorld world = new ActorWorld(); Random randColor = new Random(); int red = 0; int blue = 0; int yellow = 0; int black = 0; int green = 0; ArrayList<Color> colorIndex = new ArrayList<Color>(); public SearchWorld() { super(new BoundedGrid<Actor>(10, 10)); //nested loops to load random actors of random colors into the world
ArrayList<Color> colorArray = new ArrayList<Color>(); colorArray.add(Color.red); colorArray.add(Color.blue); colorArray.add(Color.yellow); colorArray.add(Color.black); colorArray.add(Color.GREEN);
ArrayList<Color> colorIndex = new ArrayList<Color>();
for (int i = 0; i <= 99; i++) { for (int c = 0; c < 10; c++) {
for (int r = 0; r < 10; r++) { actorArray[i] = new Bug(colorArray.get(randColor.nextInt(5)));
public SearchWorld(int rows, int cols) { //use the constructor above as an example // for (int r = 0; r < 10; r++) { // for (int c = 0; c < 10; c++) { // // Location loc = new Location(r,c);
// // for (int i = 0; i <= 99; i++) { // if(colorIndex.get(i)==Color.RED){ // red++; // } //
// for (int r = 0; r < 11; r++) { // if (actorArray[r].getColor()==Color.RED){ // red++; // } // if (actorArray[r].getColor()==Color.BLUE){ // blue++; // } // if (actorArray[r].getColor()==Color.YELLOW){ // yellow++; // } // if (actorArray[r].getColor()==Color.BLACK){ // black++; // } // if (actorArray[r].getColor()==Color.GREEN){ // green++; // }
}
public int getNumXColoredActors(Color col) { if(col==Color.RED){ System.out.println("Number of RED Actors: "+red); } if(col==Color.BLUE){ System.out.println("Number of BLUE Actors: "+blue); } if(col==Color.BLACK){ System.out.println("Number of BLACK Actors: "+black); } if(col==Color.YELLOW){ System.out.println("Number of YELLOW Actors: "+yellow); } if(col==Color.GREEN){ System.out.println("Number of GREEN Actors: "+green); } else{ return -1; } return -1; } public void colorX(){ System.out.println("RED ACTORS: "+red); } public static void main(String[] args) { SearchWorld m = new SearchWorld();
} } // for (int r = 0; r < 10; r++) { // for (int c = 0; c < 10; c++) { // // // // // // // // world.add(new Location(r, 0), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 1), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 2), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 3), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 4), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 5), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 6), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 7), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 8), new Bug(colorArray.get(randColor.nextInt(5)))); // world.add(new Location(r, 9), new Bug(colorArray.get(randColor.nextInt(5))));