updated traveler to provide stories
This commit is contained in:
parent
99126cdd9a
commit
a906a45583
|
@ -72,4 +72,4 @@
|
|||
|
||||
## 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")
|
|
@ -3,8 +3,6 @@ import model.*;
|
|||
import characters.*;
|
||||
import story.StoryContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StoryTeller {
|
||||
public static void main(String[] args) {
|
||||
|
@ -28,11 +26,6 @@ public class StoryTeller {
|
|||
znaykasHouse.addResident(malish);
|
||||
znaykasHouse.addResident(malishka);
|
||||
|
||||
List<String> stories = new ArrayList<>();
|
||||
stories.add("путешествие в Зеленый город");
|
||||
stories.add("жизнь в Цветочном городе");
|
||||
|
||||
znaykasHouse.tellEveningStories(context, stories);
|
||||
stories.clear();
|
||||
znaykasHouse.tellEveningStories(context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package characters;
|
|||
|
||||
import enums.CharacterType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Traveler extends Character {
|
||||
|
||||
public Traveler(String name) {
|
||||
|
@ -19,4 +21,8 @@ public abstract class Traveler extends Character {
|
|||
public String listen(String subject) {
|
||||
return this.name + " слушает историю о " + context.getStoryContext() + "\n";
|
||||
}
|
||||
|
||||
public List<String> returnHomeAndTellAStory() {
|
||||
return List.of("город", "путешествие");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package characters;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Znayka extends Traveler {
|
||||
String thoughts = "";
|
||||
|
||||
|
@ -21,7 +23,7 @@ public class Znayka extends Traveler {
|
|||
|
||||
@Override
|
||||
public String converse(String subject) {
|
||||
String response = name + " умно рассказывает историю о " + context.getStoryContext() + " особенно про " + subject
|
||||
String response = name + " умно рассказывает историю о " + subject
|
||||
+ "\n" + "и думает: " + this.thoughts;
|
||||
this.thoughts = "";
|
||||
return response;
|
||||
|
@ -34,4 +36,9 @@ public class Znayka extends Traveler {
|
|||
this.thoughts = "";
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> returnHomeAndTellAStory() {
|
||||
return List.of("Путешествие в Зеленый город", "Жизнь в Зеленом городе");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package model;
|
||||
|
||||
import characters.Character;
|
||||
import characters.Traveler;
|
||||
import story.StoryContext;
|
||||
import story.StoryElement;
|
||||
|
||||
|
@ -35,7 +36,17 @@ public class House extends StoryElement {
|
|||
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.getCity().returnToDailyLifeWithChanges();
|
||||
|
||||
|
@ -43,7 +54,12 @@ public class House extends StoryElement {
|
|||
resident.setContext(context);
|
||||
}
|
||||
|
||||
List<String> subjects = new ArrayList<>();
|
||||
|
||||
this.gatherResidents();
|
||||
for (Traveler resident : this.getTravelers()) {
|
||||
subjects.addAll(resident.returnHomeAndTellAStory());
|
||||
}
|
||||
for (String subject: subjects) {
|
||||
for (Character resident : this.getResidents()) {
|
||||
// if (resident instanceof Traveler) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user