updated traveler to provide stories

This commit is contained in:
Alexander Karpov 2023-12-16 12:14:47 +03:00
parent 99126cdd9a
commit a906a45583
5 changed files with 33 additions and 11 deletions

View File

@ -72,4 +72,4 @@
## UML Diagram ## UML Diagram
![UML Diagram](https://new.akarpov.ru/media/files/sanspie/xNdHx/123123123.svg "https://new.akarpov.ru/files/HaDSrkLmjVfoPTmXvQaw") ![UML Diagram](https://new.akarpov.ru/media/files/sanspie/aDoSa/bebebe.svg "https://new.akarpov.ru/files/nySsGIMRBJaERBoBWFuu")

View File

@ -3,8 +3,6 @@ import model.*;
import characters.*; import characters.*;
import story.StoryContext; import story.StoryContext;
import java.util.ArrayList;
import java.util.List;
public class StoryTeller { public class StoryTeller {
public static void main(String[] args) { public static void main(String[] args) {
@ -28,11 +26,6 @@ public class StoryTeller {
znaykasHouse.addResident(malish); znaykasHouse.addResident(malish);
znaykasHouse.addResident(malishka); znaykasHouse.addResident(malishka);
List<String> stories = new ArrayList<>(); znaykasHouse.tellEveningStories(context);
stories.add("путешествие в Зеленый город");
stories.add("жизнь в Цветочном городе");
znaykasHouse.tellEveningStories(context, stories);
stories.clear();
} }
} }

View File

@ -2,6 +2,8 @@ package characters;
import enums.CharacterType; import enums.CharacterType;
import java.util.List;
public abstract class Traveler extends Character { public abstract class Traveler extends Character {
public Traveler(String name) { public Traveler(String name) {
@ -19,4 +21,8 @@ public abstract class Traveler extends Character {
public String listen(String subject) { public String listen(String subject) {
return this.name + " слушает историю о " + context.getStoryContext() + "\n"; return this.name + " слушает историю о " + context.getStoryContext() + "\n";
} }
public List<String> returnHomeAndTellAStory() {
return List.of("город", "путешествие");
}
} }

View File

@ -1,5 +1,7 @@
package characters; package characters;
import java.util.List;
public class Znayka extends Traveler { public class Znayka extends Traveler {
String thoughts = ""; String thoughts = "";
@ -21,7 +23,7 @@ public class Znayka extends Traveler {
@Override @Override
public String converse(String subject) { public String converse(String subject) {
String response = name + " умно рассказывает историю о " + context.getStoryContext() + " особенно про " + subject String response = name + " умно рассказывает историю о " + subject
+ "\n" + "и думает: " + this.thoughts; + "\n" + "и думает: " + this.thoughts;
this.thoughts = ""; this.thoughts = "";
return response; return response;
@ -34,4 +36,9 @@ public class Znayka extends Traveler {
this.thoughts = ""; this.thoughts = "";
return response; return response;
} }
@Override
public List<String> returnHomeAndTellAStory() {
return List.of("Путешествие в Зеленый город", "Жизнь в Зеленом городе");
}
} }

View File

@ -1,6 +1,7 @@
package model; package model;
import characters.Character; import characters.Character;
import characters.Traveler;
import story.StoryContext; import story.StoryContext;
import story.StoryElement; import story.StoryElement;
@ -35,7 +36,17 @@ public class House extends StoryElement {
return residents; return residents;
} }
public void tellEveningStories(StoryContext context, List<String> subjects) { public List<Traveler> getTravelers() {
List<Traveler> travelers = new ArrayList<>();
for (Character resident : this.getResidents()) {
if (resident instanceof Traveler) {
travelers.add((Traveler) resident);
}
}
return travelers;
}
public void tellEveningStories(StoryContext context) {
context.gatherResidentsForStories(); context.gatherResidentsForStories();
context.getCity().returnToDailyLifeWithChanges(); context.getCity().returnToDailyLifeWithChanges();
@ -43,7 +54,12 @@ public class House extends StoryElement {
resident.setContext(context); resident.setContext(context);
} }
List<String> subjects = new ArrayList<>();
this.gatherResidents(); this.gatherResidents();
for (Traveler resident : this.getTravelers()) {
subjects.addAll(resident.returnHomeAndTellAStory());
}
for (String subject: subjects) { for (String subject: subjects) {
for (Character resident : this.getResidents()) { for (Character resident : this.getResidents()) {
// if (resident instanceof Traveler) { // if (resident instanceof Traveler) {