fix: interface IGrabbalbe cancellation

This commit is contained in:
Ivan Zinchenko 2023-12-12 11:51:54 +03:00
parent 6463f53f0d
commit b111e9bbee
Signed by: zinch
GPG Key ID: 6D45AA2C8FD6A37E
14 changed files with 42 additions and 61 deletions

View File

@ -1,6 +1,7 @@
package Characters;
import Entity.*;
import Entity.Entity;
import Items.Item;
import java.util.Objects;
@ -9,7 +10,7 @@ public abstract class Character extends Entity {
private Entity position;
private String currentState = "";
protected Feels feel;
protected IGrabbable itemInHand;
protected Item itemInHand;
public Character(String name, Gender gender) {
this(name, gender, Feels.NORMAL);
@ -26,14 +27,19 @@ public abstract class Character extends Entity {
}
public abstract void setFeel(Feels feel);
public abstract void moveTo(Entity obj);
public abstract void grab(IGrabbable obj);
public IGrabbable getItemInHand() {
public abstract void grab(Item obj);
public Item getItemInHand() {
return this.itemInHand;
}
public Entity getPosition() {
return this.position;
}
protected void setPosition(Entity obj) {
this.position = obj;
}
@ -42,9 +48,11 @@ public abstract class Character extends Entity {
public String toString() {
return this.currentState;
}
protected void setState(String state) {
this.currentState = state;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -1,11 +1,11 @@
package Characters;
public enum Feels {
ANGRY ("злиться"),
SCARY ("дрогнул губой"),
SAD ("надулся"),
RAGE ("взревела от бешенства"),
NORMAL ("Нормально");
ANGRY("злиться"),
SCARY("дрогнул губой"),
SAD("надулся"),
RAGE("взревела от бешенства"),
NORMAL("Нормально");
private final String feel;

View File

@ -1,10 +1,11 @@
package Characters;
import Entity.*;
import Entity.Entity;
import Items.Item;
public class FrenBok extends Character {
private IGrabbableCharacter characterInHand;
public FrenBok() {
super("Фрекен Бок", Gender.WOMAN);
}
@ -22,7 +23,7 @@ public class FrenBok extends Character {
}
@Override
public void grab(IGrabbable obj) {
public void grab(Item obj) {
this.itemInHand = obj;
this.setState(String.format("%s взяла %s", this.getGender(), obj.getName()));
}

View File

@ -1,8 +1,8 @@
package Characters;
public enum Gender {
MAN ("Он"),
WOMAN ("Она");
MAN("Он"),
WOMAN("Она");
private final String gender;

View File

@ -1,9 +1,11 @@
package Characters;
import Entity.Entity;
import Entity.IGrabbable;
public interface IGrabbableCharacter extends IGrabbable {
interface IGrabbableCharacter {
String getGrabbablePart();
void moveTo(Entity obj);
String getName();
}

View File

@ -1,12 +1,14 @@
package Characters;
import Entity.*;
import Entity.Entity;
import Items.Container;
import Items.Item;
public class Karlson extends Character implements IGrabbableCharacter {
public Karlson() {
super("Кралсон", Gender.MAN);
}
public Karlson(Feels feel) {
this();
this.feel = feel;
@ -25,9 +27,9 @@ public class Karlson extends Character implements IGrabbableCharacter {
}
@Override
public void grab(IGrabbable obj) {
public void grab(Item obj) {
this.itemInHand = obj;
this.setState(String.format("%s взял %s", this.getGender() ,obj));
this.setState(String.format("%s взял %s", this.getGender(), obj));
}
public void grabFrom(Container container) {

View File

@ -4,6 +4,7 @@ import java.util.Objects;
public abstract class Entity {
protected String name;
public final String getName() {
return this.name;
}

View File

@ -1,7 +0,0 @@
package Entity;
import Characters.Character;
public interface IGrabbable {
String getName();
}

View File

@ -1,25 +1,24 @@
package Items;
import Characters.Character;
import Entity.IGrabbable;
import java.util.Objects;
public class Container extends Item {
private final IGrabbable innerItem;
private final Item innerItem;
public Container(String name, IGrabbable item) {
public Container(String name, Item item) {
super(name);
this.innerItem = item;
}
public Container(String name, IGrabbableItem item, Character owner) {
public Container(String name, Item item, Character owner) {
super(name, owner);
item.setOwner(owner);
this.innerItem = (IGrabbable) item;
this.innerItem = item;
}
public IGrabbable getInnerItem() {
public Item getInnerItem() {
return this.innerItem;
}

View File

@ -1,8 +0,0 @@
package Items;
import Characters.Character;
import Entity.IGrabbable;
public interface IGrabbableItem extends IGrabbable {
void setOwner(Character owner);
}

View File

@ -1,15 +1,17 @@
package Items;
import Characters.Character;
import Entity.*;
import Entity.Entity;
import java.util.Objects;
public class Item extends Entity {
private Character owner;
public Item(String name) {
this.name = name;
}
public Item(String name, Character owner) {
this.name = name;
this.owner = owner;
@ -18,6 +20,7 @@ public class Item extends Entity {
public Character getOwner() {
return owner;
}
public void setOwner(Character owner) {
this.owner = owner;
}

View File

@ -1,9 +0,0 @@
package Items;
import Entity.IGrabbable;
public class SmallItem extends Item implements IGrabbableItem {
public SmallItem(String name) {
super(name);
}
}

View File

@ -1,9 +1,3 @@
import Characters.Feels;
import Characters.FrenBok;
import Characters.Karlson;
import Items.Container;
import Items.Item;
import Items.SmallItem;
import StoryTeller.StoryTeller;
public class Main {

View File

@ -1,15 +1,10 @@
package StoryTeller;
import Characters.Character;
import Characters.Feels;
import Characters.FrenBok;
import Characters.Karlson;
import Entity.*;
import Items.Container;
import Items.Item;
import Items.SmallItem;
import java.util.function.Function;
public class StoryTeller {
// Персонажи
@ -18,7 +13,7 @@ public class StoryTeller {
// Предметы
private final Item kitchenHob = new Item("плита");
private final SmallItem meatball = new SmallItem("тефтелька");
private final Item meatball = new Item("тефтелька");
private final Container fryingPan = new Container("сковородка", meatball, frenBok);
private final Item door = new Item("дверь");