@Override public void timePassed() { // Moves if there is empty space underneath if (this.world.getTunnel().isPositionEmptySpaceUnder(this.getPosition())) { this.timeWaited++; // Delays the falling so it won't kill you if you empty the space // right under it if (this.timeWaited > 80) { this.emptySpacesUnder++; this.moveTo(new Point2D.Double(this.getPosition().getX(), this.getPosition().getY() + 3)); Monster m = this.encounteredWithMonster(); if (m != null) { m.die(); } // Kills the hero if it encounters it while falling if (this.encounteredWithHero()) { this.getWorld().getHero().die(); } Bag bag = this.bagEncounteredWithBag(); // If a bag falls on top of another bag, they both break // Value of gold is doubled since it was two bags if (bag != null) { Gold gold = new Gold(this.getWorld(), this.getPosition()); bag.die(); this.die(); gold.setValue(gold.getValue() * 2); this.world.addBlocks(gold); return; } } } else { this.timeWaited = 0; // If it dropped more than one block, it will break into gold if (this.emptySpacesUnder > 47) { Bag bag = this.bagEncounteredWithBag(); Gold gold = new Gold(this.getWorld(), this.getPosition()); // If a bag falls on top of another bag, they both break // Value of gold is doubled since it was two bags if (bag != null) { bag.die(); gold.setValue(gold.getValue() * 2); } this.die(); this.world.addBlocks(gold); } this.emptySpacesUnder = 0; } // Moves the bag if the hero encounters it int deltaX = 0; int deltaY = 0; if (this.encounteredWithHero()) { Hero hero = this.getWorld().getHero(); char direction = hero.getDirection(); if (direction == 'u') if (hero.getPosition().getX() > this.getPosition().getX()) deltaX -= 3; if (direction == 'd') if (hero.getPosition().getX() < this.getPosition().getX()) deltaX += 3; this.moveTo( new Point2D.Double( this.getPosition().getX() + deltaX, this.getPosition().getY() + deltaY)); } // Adds an empty space if there isn't one already where the bag abject // is if (!this.getWorld().getTunnel().isInEmptySpace(this)) { this.getWorld().getFootprintsToAdd().add(new FootPrint(this.getWorld(), this.getPosition())); } }
public boolean isEquals(Gold one, Gold two) { return one.getLength() * one.getUnit() == two.getLength() * two.getUnit(); }