diff --git a/src/StoryTeller.java b/src/StoryTeller.java index fed9bb5..a0d824e 100644 --- a/src/StoryTeller.java +++ b/src/StoryTeller.java @@ -1,21 +1,31 @@ import characters.Character; import model.*; import characters.*; +import story.StoryContext; + +import java.util.ArrayList; +import java.util.List; public class StoryTeller { public static void main(String[] args) { + // Creating the setting for the story City flowerCity = new City("Цветочный город"); House znaykasHouse = new House("Домик Знайки"); StoryContext context = new StoryContext(flowerCity, znaykasHouse); - Character znayka = new Znayka("описание"); + // Creating the characters + Character znayka = new Znayka("Знайка"); Character malish = new Child("Малыш", "Малыш"); - Character malishka = new Child("Малышка","Малышка"); + Character malishka = new Child("Малышка", "Малышка"); + // Adding characters to Znayka's house znaykasHouse.addResident(znayka); znaykasHouse.addResident(malish); znaykasHouse.addResident(malishka); - znaykasHouse.tellEveningStories(context); + List stories = new ArrayList<>(); + stories.add("о жизни в Зеленом городе"); + + znaykasHouse.tellEveningStories(context, stories); } } diff --git a/src/characters/Character.java b/src/characters/Character.java index a3e66f1..6fd4b4e 100644 --- a/src/characters/Character.java +++ b/src/characters/Character.java @@ -3,7 +3,7 @@ package characters; import enums.CharacterType; import interfaces.Interactable; import interfaces.Listenable; -import model.StoryContext; +import story.StoryContext; import model.StoryElement; public abstract class Character extends StoryElement implements Interactable, Listenable { @@ -16,13 +16,30 @@ public abstract class Character extends StoryElement implements Interactable, Li this.name = name; } + // Method where characters can reminisce about past events + public abstract void reminisce(String memory); + + // Method for characters to react to stories being told + public abstract void reactToStory(); + + // Method for telling a story about a specific place or event + public abstract void tellStoryOf(String place); + + // Method for characters, especially children, to ask questions about the story + public abstract void askQuestionsAbout(String subject); + public abstract void listen(); public abstract void tell(); + + public abstract void converse(StoryContext context, String subject); + + // Interaction method for general purposes @Override public abstract void interact(StoryContext context); + // Listening method within a story context @Override public abstract void listen(StoryContext context); -} \ No newline at end of file +} diff --git a/src/characters/Child.java b/src/characters/Child.java index 51b48f9..d3b76db 100644 --- a/src/characters/Child.java +++ b/src/characters/Child.java @@ -1,7 +1,7 @@ package characters; import enums.CharacterType; -import model.StoryContext; +import story.StoryContext; public class Child extends Character { @@ -9,9 +9,29 @@ public class Child extends Character { super(description, CharacterType.CHILD, name); } + @Override + public void reminisce(String memory) { + + } + + @Override + public void reactToStory() { + + } + + @Override + public void tellStoryOf(String place) { + + } + + @Override + public void askQuestionsAbout(String subject) { + System.out.println(name + " спрашивает вопросы о " + subject); + } + @Override public void listen() { - System.out.println(name + " listens to the story with wide-eyed wonder."); + System.out.println(name + " слушает с удивлением"); } @Override @@ -23,7 +43,12 @@ public class Child extends Character { @Override public void interact(StoryContext context) { // Child-specific interactions - System.out.println(name + " shares their impressions about the story."); + System.out.println(name + " говорят свое мнение об истории."); + } + + @Override + public void converse(StoryContext context, String subject) { + askQuestionsAbout(subject); } @Override diff --git a/src/characters/Traveler.java b/src/characters/Traveler.java index f97bbbf..746b47b 100644 --- a/src/characters/Traveler.java +++ b/src/characters/Traveler.java @@ -1,7 +1,7 @@ package characters; import enums.CharacterType; -import model.StoryContext; +import story.StoryContext; public class Traveler extends Character { @@ -9,6 +9,26 @@ public class Traveler extends Character { super(description, CharacterType.TRAVELER, name); } + @Override + public void reminisce(String memory) { + + } + + @Override + public void reactToStory() { + + } + + @Override + public void tellStoryOf(String place) { + + } + + @Override + public void askQuestionsAbout(String subject) { + + } + @Override public void listen() { @@ -19,6 +39,11 @@ public class Traveler extends Character { // Logic for telling a story } + @Override + public void converse(StoryContext context, String subject) { + tellStoryOf(subject); + } + @Override public void interact(StoryContext context) { System.out.println(name + " рассказывает историю о Зеленом городе."); diff --git a/src/characters/Znayka.java b/src/characters/Znayka.java index e4fe4d3..5755aba 100644 --- a/src/characters/Znayka.java +++ b/src/characters/Znayka.java @@ -1,20 +1,15 @@ package characters; -import enums.CharacterType; import interfaces.Listener; -import model.StoryContext; public class Znayka extends Traveler implements Listener { - private String name; public Znayka(String description) { super(description, "Знайка"); - this.name = name; } - @Override - public void tell() { - System.out.println(name + " рассказывает истории о жизни в Зеленом городе."); + public void tellStoryOf(String about) { + System.out.println("Знайка рассказывает истории " + about); } @Override diff --git a/src/enums/CharacterType.java b/src/enums/CharacterType.java index 86c2f55..34e75ae 100644 --- a/src/enums/CharacterType.java +++ b/src/enums/CharacterType.java @@ -1,5 +1,6 @@ package enums; public enum CharacterType { - TRAVELER, CHILD + TRAVELER, // Represents characters who are travelers + CHILD // Represents child characters } diff --git a/src/interfaces/Interactable.java b/src/interfaces/Interactable.java index caa9264..bc9b024 100644 --- a/src/interfaces/Interactable.java +++ b/src/interfaces/Interactable.java @@ -1,6 +1,6 @@ package interfaces; -import model.StoryContext; +import story.StoryContext; public interface Interactable { void interact(StoryContext context); diff --git a/src/interfaces/Listenable.java b/src/interfaces/Listenable.java index 934021e..1926a6a 100644 --- a/src/interfaces/Listenable.java +++ b/src/interfaces/Listenable.java @@ -1,6 +1,6 @@ package interfaces; -import model.StoryContext; +import story.StoryContext; public interface Listenable { void listen(StoryContext context); diff --git a/src/model/City.java b/src/model/City.java index 8f9c021..bbb9502 100644 --- a/src/model/City.java +++ b/src/model/City.java @@ -1,8 +1,19 @@ package model; public class City extends StoryElement { + private final String name; - public City(String description) { - super(description); + public City(String name) { + super(name); // Assuming the super class StoryElement's constructor takes a name or description + this.name = name; } -} \ No newline at end of file + + public String getName() { + return this.name; + } + + public void returnToDailyLifeWithChanges() { + // Implementation of the method as before + System.out.println("Жизнь в " + this.getName() + " потекла по-старому... хотя нет, нельзя сказать, чтобы совсем по-старому."); + } +} diff --git a/src/model/House.java b/src/model/House.java index 5e2ab5b..8beae03 100644 --- a/src/model/House.java +++ b/src/model/House.java @@ -1,28 +1,57 @@ package model; import characters.Character; -import interfaces.Listenable; +import characters.Traveler; +import story.StoryContext; + import java.util.ArrayList; import java.util.List; public class House extends StoryElement { - private List residents; + private final String name; + private final List residents; - public House(String description) { - super(description); + public House(String name) { + super(name); // Assuming the super class StoryElement's constructor takes a name or description + this.name = name; this.residents = new ArrayList<>(); } + public String getName() { + return this.name; + } + public void addResident(Character character) { this.residents.add(character); } - public void tellEveningStories(StoryContext context) { - for (Character resident : residents) { - if (resident != null) { - ((Listenable) resident).listen(context); + // Method to gather all the residents of the house + public void gatherResidents() { + System.out.println("Жители " + this.getDescription() + " собираются чтобы рассказать истории"); + } + + // Method to retrieve the list of residents + public List getResidents() { + return residents; + } + + public void tellEveningStories(StoryContext context, List subjects) { + context.gatherResidentsForStories(); + context.getCity().returnToDailyLifeWithChanges(); + + this.gatherResidents(); + for (String subject: subjects) { + for (Character resident : this.getResidents()) { + if (resident instanceof Traveler) { + resident.converse(context, subject); + } else { + resident.converse(context, subject); + } } } + + // The method could end with a closing statement or a setup for the next day's stories. + System.out.println("Истории захватывали дух, и каждый вечер собирались всё больше жителей, чтобы слышать новые приключения."); } -} \ No newline at end of file +} diff --git a/src/model/StoryContext.java b/src/model/StoryContext.java deleted file mode 100644 index 42217e1..0000000 --- a/src/model/StoryContext.java +++ /dev/null @@ -1,13 +0,0 @@ -package model; - -public class StoryContext { - private City city; - private House house; - - public StoryContext(City city, House house) { - this.city = city; - this.house = house; - } - - // Getters and setters for city and house -} \ No newline at end of file diff --git a/src/story/StoryContext.java b/src/story/StoryContext.java new file mode 100644 index 0000000..e0e2dd5 --- /dev/null +++ b/src/story/StoryContext.java @@ -0,0 +1,31 @@ +package story; + +import model.City; +import model.House; + +public class StoryContext { + private City city; + private House house; + + public StoryContext(City city, House house) { + this.city = city; + this.house = house; + } + + // Getters and setters for city and house + public City getCity() { + return this.city; + } + + // Methods for story actions + public void returnToDailyLifeWithChanges() { + // Implement the logic for the city's daily life with subtle changes after the travelers' return + System.out.println("Жизнь в " + city.getName() + " потекла по-старому... хотя нет, нельзя сказать, чтобы совсем по-старому."); + } + + public void gatherResidentsForStories() { + // Implement the logic for gathering residents to listen to stories + house.gatherResidents(); + System.out.println("Все жители, и малыши и малышки, приходили по вечерам к " + house.getName() + " и слушали рассказы путешественников."); + } +} \ No newline at end of file