-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChild.java
More file actions
140 lines (139 loc) · 5.66 KB
/
Copy pathChild.java
File metadata and controls
140 lines (139 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package lab4;
import java.util.ArrayList;
public class Child extends Creature {
private ArrayList<Instructions.Permission> permissions = new ArrayList<>();
private ArrayList<Instructions.Prohibition> prohibitions = new ArrayList<>();
private ArrayList<Entity> takenItems = new ArrayList<>();
private ArrayList<Forgettable> forgottenInstructions = new ArrayList<>();
private Creature mother;
private Creature father;
private ArrayList<Habit> habits = new ArrayList<>();
private Heart heart;
private String previousPlace;
public Child(){
super();
heart = new Heart();
}
public Child(String name){
super(name);
heart = new Heart();
}
public Child(String name, int age){
super(name, age);
heart = new Heart();
}
public Heart getHeart(){
return heart;
}
public void setProhibition(Instructions.Prohibition prohibition) {
prohibitions.add(prohibition);
}
public void setPermission(Instructions.Permission permission) {
permissions.add(permission);
}
public Instructions getProhibition(int index) {
return prohibitions.get(index);
}
public class Heart {
private String name;
private Heart() {
name = "Сердце";
}
public void skipABeat(String time) {
System.out.println(name + " екнуло, когда " + time + ".");
}
public void notSkipABeat(Entity reason, String time) {
System.out.println(name + " человека по имени " + Child.this.getName() + " не екнуло, когда " + time + ", так как есть " + reason.getInformation() + ".");
}
}
public void addHabit(Habit habit) {
habits.add(habit);
System.out.println("У человека по имени " + getName() + " есть " + habit.getInformation() + ".");
}
public Instructions getPermission(int index) {
return permissions.get(index);
}
public void setMother(Creature mother) {
this.mother = mother;
}
public void setFather(Creature father) {
this.father = father;
}
public void sneak(String object) {
previousPlace = getLocation().getSpecificPlace();
getLocation().setSpecificPlace(object);
System.out.println(getName() + " прокрался в обьект " + object + ".");
}
public void take(Entity object) {
takenItems.add(object);
System.out.println(getName() + " взял объект " + object.getInformation());
}
public void returnFromSomePlace() {
String s = getLocation().getSpecificPlace();
getLocation().setSpecificPlace(previousPlace);
previousPlace = s;
System.out.println(getName() + " вернулся назад и оказался " + getLocation().getSpecificPlace() + ".");
}
public void reactionToTheProhibition(int index, Boolean conditions) {
boolean flag = false;
for (int i = 0; i < forgottenInstructions.size(); i++) {
if ((!forgottenInstructions.get(i).getIsPermission()) && (forgottenInstructions.get(i).getIndex() == index)) {
flag = true;
}
}
if (flag) {
System.out.println(getName() + " будет игнорировать " + prohibitions.get(index).getInformation() + ", так как " + getName() + " забыл о нем.");
} else {
if (conditions) {
System.out.println(getName() + " не может игнорировать " + prohibitions.get(index).getInformation() + ", так как условие \"" + prohibitions.get(index).getCondition() + "\" выполнено.");
} else {
System.out.println(getName() + " может игнорировать " + prohibitions.get(index).getInformation() + ", так как условие \"" + prohibitions.get(index).getCondition() + "\" не выполнено.");
}
}
}
public void reactionToThePermission(int index, Boolean conditions) {
boolean flag = false;
for (int i = 0; i < forgottenInstructions.size(); i++) {
if ((forgottenInstructions.get(i).getIsPermission()) && (forgottenInstructions.get(i).getIndex() == index)) {
flag = true;
}
}
if (flag) {
System.out.println(getName() + " будет использовать " + permissions.get(index).getInformation() + ", так как " + getName() + " забыл об условии.");
} else {
if (conditions) {
System.out.println(getName() + " будет использовать " + permissions.get(index).getInformation() + ", так как условие \"" + permissions.get(index).getCondition() + "\" выполнено.");
} else {
System.out.println(getName() + " не будет использовать " + permissions.get(index).getInformation() + ", так как условие \"" + permissions.get(index).getCondition() + "\" не выполнено.");
}
}
}
private interface Forgettable {
boolean getIsPermission();
int getIndex();
}
public void forgetInstruction(int index, boolean isPermission) {
class ForgottenInstruction implements Forgettable {
private boolean isPermission;
private int index;
public ForgottenInstruction(int index, boolean isPermission) {
this.isPermission = isPermission;
this.index = index;
}
public boolean getIsPermission() {
return isPermission;
}
public int getIndex() {
return index;
}
}
ForgottenInstruction forgottenInstruction = new ForgottenInstruction(index, isPermission);
forgottenInstructions.add(forgottenInstruction);
}
public void beSurprisedIf(Entity reason, TypeOfAmazement type) {
System.out.println(getName() + " " + type.getType() + " удивится, если " + reason.getInformation());
}
public void doNotKnowAboutRelation(Facts fact, String question) {
System.out.println(getName() + " не знает, " + question + " " + fact.getThesis());
}
}