updated code for story telling to work
This commit is contained in:
parent
48ad83ea5a
commit
249021b63f
|
@ -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<String> stories = new ArrayList<>();
|
||||
stories.add("о жизни в Зеленом городе");
|
||||
|
||||
znaykasHouse.tellEveningStories(context, stories);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 + " рассказывает историю о Зеленом городе.");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package enums;
|
||||
|
||||
public enum CharacterType {
|
||||
TRAVELER, CHILD
|
||||
TRAVELER, // Represents characters who are travelers
|
||||
CHILD // Represents child characters
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package interfaces;
|
||||
|
||||
import model.StoryContext;
|
||||
import story.StoryContext;
|
||||
|
||||
public interface Interactable {
|
||||
void interact(StoryContext context);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package interfaces;
|
||||
|
||||
import model.StoryContext;
|
||||
import story.StoryContext;
|
||||
|
||||
public interface Listenable {
|
||||
void listen(StoryContext context);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void returnToDailyLifeWithChanges() {
|
||||
// Implementation of the method as before
|
||||
System.out.println("Жизнь в " + this.getName() + " потекла по-старому... хотя нет, нельзя сказать, чтобы совсем по-старому.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Character> residents;
|
||||
private final String name;
|
||||
private final List<Character> 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<Character> getResidents() {
|
||||
return residents;
|
||||
}
|
||||
|
||||
public void tellEveningStories(StoryContext context, List<String> 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("Истории захватывали дух, и каждый вечер собирались всё больше жителей, чтобы слышать новые приключения.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
31
src/story/StoryContext.java
Normal file
31
src/story/StoryContext.java
Normal file
|
@ -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() + " и слушали рассказы путешественников.");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user