Sunteți pe pagina 1din 12

package numXActors;

// A+ Computer Science - www.apluscompsci.com


//Name -
//Date -
//Class -
//Lab -
import java.awt.Color;
import info.gridworld.actor.*;
import info.gridworld.grid.Grid;
import info.gridworld.world.World;
import info.gridworld.grid.Location;
import info.gridworld.grid.BoundedGrid;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Random;

public class SearchWorld extends ActorWorld {

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)));



world.add(new Location(r, c), actorArray[i]);
actorArray[i].removeSelfFromGrid();
if(actorArray[i].getColor()==Color.red){
red++;
}
world.add(new Location(r, 1), actorArray[i]);
// world.add(new Location(r, 2), actorArray[i]);
// world.add(new Location(r, 3), actorArray[i]);
// world.add(new Location(r, 4), actorArray[i]);
// world.add(new Location(r, 5), actorArray[i]);
// world.add(new Location(r, 6), actorArray[i]);
// world.add(new Location(r, 7), actorArray[i]);
// world.add(new Location(r, 8), actorArray[i]);




world.show();
}
}
}
}

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))));




package numXActors;

// A+ Computer Science - www.apluscompsci.com
//Name -
//Date -
//Class -
//Lab -
import info.gridworld.actor.*;
import info.gridworld.grid.BoundedGrid;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;
import info.gridworld.world.World;
import java.awt.Color;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class SearchWorld extends ActorWorld {

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)));



world.add(new Location(r, c), actorArray[i]);

colorIndex.add(actorArray[i].getColor());


if(colorIndex.get(i)==Color.RED){
red++;
}
// actorArray[i].removeSelfFromGrid();
// if(actorArray[i].getColor()==Color.red){
// red++;
// }





world.show();
}
}
}
}

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))));

S-ar putea să vă placă și