-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
99 lines (96 loc) · 4.32 KB
/
Main.java
File metadata and controls
99 lines (96 loc) · 4.32 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
import characters.MainHero;
import characters.Rabbit;
import enums.*;
import exceptions.NotPutException;
import exceptions.NotTakeException;
import interfaces.IdentificationStrategy;
import materialObjects.*;
import placesPackage.Place;
import java.util.ArrayList;
public class Main {
public static void main(String[] args)throws NotPutException, NotTakeException {
Place nora = new Place(Places.BURROW, 10, PlaceOrientation.HORIZONTAL);
Rabbit rabbit = new Rabbit(Colors.WHITE, "Тиша");
rabbit.run(nora);
IdentificationStrategy strategy = (dir, place, currentCoordinat) -> {
ArrayList<Furniture> seen = new ArrayList<>();
if (dir == Direction.UP) {
System.out.println("Я вижу выход, но не тот :)");
return seen;
}
if (dir == Direction.DOWN) {
System.out.println("Я вижу волшебную дверь. Скорее бы долететь!!!");
return seen;
}
for (Furniture e : place.getFurn()) {
if (e.getDir().toString().equals(dir.toString()) && e.getDeepCoordinat() == (int) currentCoordinat) {
seen.add(e);
}
}
return seen;
};
MainHero Alice = new MainHero("Алиса", 20, Sex.GIRL, 1.0, strategy);
Alice.lookFor(rabbit);
Alice.Move();
while (Alice.getCurrentCoordinat() < nora.getDeep()) {
Alice.Move();
if (Alice.getCurrentCoordinat() >= nora.getDeep()) break;
}
Place pit = new Place(Places.PIT, 12, PlaceOrientation.VERTICAL);
Alice.setPlace(pit);
Alice.setCurrentCoordinat(0);
for (int i = 1; i <= pit.getDeep(); i++) {
for (Direction dir : Direction.values()) {
Thing rnd = Thing.randomThing();
if (rnd == null) continue;
Furniture furn = new Furniture.Builder()
.type(rnd)
.dir(dir)
.deepCoordinat(i)
.subjects()
.build();
try {
Subject sbj = new Subject.Builder()
.type(SubjectType.randomSubject())
.title("")
.build();
furn.addSubject(sbj);
} catch (NotPutException exc){
System.out.println(exc.getMessage());
}
pit.addFurn(furn);
}
}
while (Alice.getCurrentCoordinat() < pit.getDeep()) {
Alice.Move();
if (Alice.getCurrentCoordinat() >= pit.getDeep()) break;
Direction rndDirection = Direction.randomDirection();
Alice.Look(rndDirection);
ArrayList<Furniture> seen = Alice.Identificate(rndDirection);
if (rndDirection != Direction.UP && rndDirection != Direction.DOWN) {
if (seen.size() == 0) System.out.println("Алиса ничего не увидела");
else {
for (Furniture e : seen) {
if (Math.random () <= 0.3 && e.getSubjects().size() != 0) {
try {
int indexTake = (int) (Math.random() * e.getSubjects().size());
Alice.take(e.getSubjects().get(indexTake));
} catch (NotTakeException exc){
System.out.println(exc.getMessage());
}
}
if (Math.random () <= 0.3) {
try {
Alice.put(e);
} catch (NotPutException exc) {
System.out.println(exc.getMessage());
}
}
System.out.println("Алиса увидела " + e.getType().toString());
}
}
}
}
Alice.say("Я молодец. Теперь я не заплачу, когда упаду в следующий раз");
}
}