2020-05-27 17:51:07 +02:00

98 lines
2.8 KiB
Java

package ruscz.game.gameOfProd.Cells;
import ruscz.game.gameOfProd.Dialog.Dialog;
import ruscz.game.gameOfProd.Inventory.Item;
import ruscz.game.gameOfProd.Map.Map;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
import java.awt.*;
public class DoorCell extends InteractionCell {
private boolean isOpen;
private boolean isLocked;
private boolean directionVert;
private String sound;
private String soundOpen;
private String soundClose;
private String soundLocked;
private float volume;
public DoorCell(int x, int y, boolean directionVert, String message, Dialog dialog, Map map, WindowOfFreeMove window) {
super(x, y, message, dialog, map, window, true);
this.isOpen = false;
this.isLocked = true;
this.directionVert = directionVert;
setSound();
}
public DoorCell(int x, int y, boolean directionVert, Map map, WindowOfFreeMove window) {
super(x, y, null, null, map, window, true);
this.isOpen = false;
this.isLocked = false;
this.directionVert = directionVert;
setSound();
}
@Override
public void paint(Graphics2D g) {
int open = isOpen ? 1 : 0;
int direction = directionVert ? 0 : 2;
g.drawImage(super.getImageCell().getImageDoor().getImagesOfDoor()[open + direction], (getX() - 1) * getSize(),
(getY() - 1) * getSize(), getSize() * 2, getSize() * 2, null);
}
@Override
public void useItem(Item item) {
isLocked = false;
setSound();
super.useItem(item);
}
private void setSound() {
if (isOpen) {
sound = super.getSoundManager().getSoundMap().get("doorOpen");
volume = -8.0f;
}
else if (!isOpen && !isLocked) {
sound = super.getSoundManager().getSoundMap().get("doorClose");
volume = -8.0f;
}
else if (isLocked) {
sound = super.getSoundManager().getSoundMap().get("doorLocked");
volume = -10.0f;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
DoorCell doorCell = (DoorCell) o;
return isLocked == doorCell.isLocked &&
directionVert == doorCell.directionVert;
}
public boolean isOpen() {
return isOpen;
}
public void setOpen(boolean open) {
isOpen = open;
setSound();
}
public boolean isLocked() {
return isLocked;
}
public void setLocked(boolean locked) {
isLocked = locked;
setSound();
}
public String getSound() { return sound; }
public float getVolume() { return volume; }
}