//For some reason my elevator doors keeps opening and closing each time the "Controller" class reaches the location clicked on. And it will end in a closed position Any Idea why?
public void act()
{
checkMouse();
active();
}
public Controller()
{
this.setImage("Controller.png");
}
public void checkMouse()
{
MouseInfo mi = Greenfoot.getMouseInfo();
if (mi != null)
{
int buttonNumber = mi.getButton();
if(buttonNumber==3 || buttonNumber==1)
{
if (mi.getX() > this.getX()-20 && mi.getX() < this.getX()+20)
move();
}
}
}
public void move()
{
MouseInfo mi = Greenfoot.getMouseInfo();
if(mi.getY() > (100-20) && mi.getY() < (100+20)) moveTo=100;
if(mi.getY() > (173-20) && mi.getY() < (173+20)) moveTo=173;
if(mi.getY() > (246-20) && mi.getY() < (246+20)) moveTo=246;
if(mi.getY() > (319-20) && mi.getY() < (319+20)) moveTo=319;
if(mi.getY() > (392-20) && mi.getY() < (392+20)) moveTo=392;
if(mi.getY() > (465-20) && mi.getY() < (465+20)) moveTo=465;
if(mi.getY() > (538-20) && mi.getY() < (538+20)) moveTo=538;
}
public void active()
{
if(moveTo != this.getY())
{
if(moveTo < this.getY())
{
setLocation(this.getX(), this.getY()-1);
}
if(moveTo > this.getY())
{
setLocation(this.getX(), this.getY()+1);
}
}
int gety=this.getY();
if (moveTo == gety)
{
LeftDoor leftDoor = (LeftDoor) getIntersectingObjects(LeftDoor.class).get(0);
RightDoor rightDoor = (RightDoor) getIntersectingObjects(RightDoor.class).get(0);
if(leftDoor.getX() > getX()-18)//moves door when elevator is stationary
leftDoor.setLocation(leftDoor.getX()-2, leftDoor.getY());
if(rightDoor.getX() < getX()+18)//moves door when elevator is stationary
rightDoor.setLocation(rightDoor.getX()+2, rightDoor.getY());
}
else if (gety > (moveTo-15) && gety < (moveTo+15) && moveTo != gety)
{
LeftDoor leftDoor = (LeftDoor) getIntersectingObjects(LeftDoor.class).get(0);
RightDoor rightDoor = (RightDoor) getIntersectingObjects(RightDoor.class).get(0);
if(leftDoor.getX() < getX()+18)//moves doors when new location is selected
leftDoor.setLocation(leftDoor.getX()+2, leftDoor.getY());
if(rightDoor.getX() > getX()-18)//moves doors when new location is selected
rightDoor.setLocation(rightDoor.getX()-2, rightDoor.getY());
}

