Hello I have a programme where you place tiles to build houses and then you sell the houses. I only want to sell the houses if the building has a door an at least one window. My arraylist looks like this:
public static ArrayList<block> b = new ArrayList<block>();
every type of tile has an id. the door tile is 1 and the windows tile is 2 and the wall tile is 3.
for(int i = 0; i < play.b.toArray().length;i++){
if(play.b.contains(play.b.get(i).id == 1)){
cansell= true;
}else{
cansell= false;
}
}
How can I check to see if an object in an arraylist contains a certain value , in this case the value 1.
here is the door class:
public class door extends block{
public cockpit(int x,int y,int rot){
this.x = x;
this.y = y;
this.rotate = rot;
r = new Rectangle(x - (int)play.camx,y - (int)play.camy,20,20);
id = 3;
}
public void tick(){
createCollisionRect();
if(Comp.mr && r.contains(new Point((Comp.mx ) ,(Comp.my) ))){
remove = true;
}
if(remove){
//play.gui.money +=800;
}
}
public void render(Graphics g){
Graphics2D g2 = (Graphics2D) g;
if (rotate == 0) {
ImageIcon i62 = new ImageIcon("res/tiles/cockpit.png");
img = i62.getImage();
g.drawImage(img, x - (int) play.camx, y - (int) play.camy,20,20, null);
}
if (rotate == 1) {
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.rotate(Math.toRadians(90),10,10);
ImageIcon i62 = new ImageIcon("res/tiles/cockpit.png");
img = i62.getImage();
g2.drawImage(img,at, null);
}
if (rotate == 2) {
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.rotate(Math.toRadians(180),10,10);
ImageIcon i62 = new ImageIcon("res/tiles/cockpit.png");
img = i62.getImage();
g2.drawImage(img, at, null);
}
if (rotate == 3) {
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.rotate(Math.toRadians(-90),10,10);
ImageIcon i62 = new ImageIcon("res/tiles/cockpit.png");
img = i62.getImage();
g2.drawImage(img, at, null);
}
}
}
if(list.contains(1) && list.contains(2))?play.b.toArray().lengthcan be also written likeplay.b.size()no need to create a array out of your listplay.b, really? Is itIntegerorblock?