-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGenericAdventure.java
83 lines (66 loc) · 2.43 KB
/
GenericAdventure.java
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
//Помоги главнокомандующему справиться с войсками (поправить компиляцию, упростить, где можно, но трогать функцию main нельзя)
public class GenericAdventure {
public interface Man {
}
public static class Knight implements Man {
public void cry(){}
}
public static class Peasant implements Man {
}
public interface Army<T> {
void move();
}
public static class Avantgarde<T> implements Army<T> {
private T comander;
public Avantgarde(T comander) {
this.comander = comander;
}
public void fallBack() {}
public void move(){}
}
public static class Escort<T> implements Army<T> {
private T comander;
public Escort(T comander) {
this.comander = comander;
}
public void move(){}
}
public static void doScout(Avantgarde<Man> avantgarde) {
avantgarde.move();
avantgarde.fallBack();
}
public static void moveEscort(Escort<Man> escort) {
escort.move();
}
public static void moveKnights(Avantgarde<Knight> avantgarde) {
avantgarde.comander.cry();
avantgarde.move();
}
public static void moveKnights(Escort<Knight> escort) {
escort.comander.cry();
escort.move();
}
public static void moveSomething(Avantgarde<Peasant> army) {
army.move();
}
public static void moveSomething(Escort<Knight> army) {
army.move();
}
public static void main(String[] args) {
final Avantgarde<Knight> knightsAvanLeft = new Avantgarde<>(new Knight());
final Army<Knight> knightsAvanRight = new Avantgarde<>(new Knight());
final Escort<Man> peasantsEscortBack = new Escort<>(new Peasant());
final Escort<Peasant> peasantEscortLeft = new Escort<>(new Peasant());
final Army<Peasant> peasantEscortRigth = new Escort<>(new Peasant());
final Army<Knight> knigthsReserve = new Escort<>(new Knight());
final Avantgarde<Man> raiders = new Avantgarde<>(new Knight());
doScout(knightsAvanLeft);
moveKnights(knightsAvanRight);
moveEscort(peasantsEscortBack);
moveSomething(peasantEscortLeft);
moveSomething(knigthsReserve);
moveKnights(knigthsReserve);
moveSomething(peasantEscortRigth);
moveSomething(raiders);
}
}