-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hippodrome.java
63 lines (49 loc) · 1.51 KB
/
Hippodrome.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
package com.javarush.task.task21.task2113;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Hippodrome {
private List<Horse> horses;
static Hippodrome game;
public Hippodrome(List<Horse> horses) {
this.horses = horses;
}
public List<Horse> getHorses() {
return horses;
}
public static void main(String[] args) throws InterruptedException {
game = new Hippodrome(new ArrayList<>());
game.horses.add(new Horse("Artax", 3, 0));
game.horses.add(new Horse("Ruffian", 3, 0));
game.horses.add(new Horse("Frankel", 3, 0));
game.run();
game.printWinner();
}
public void run() throws InterruptedException {
for (int i = 0; i < 100; i++) {
move();
print();
Thread.sleep(500);
}
}
public void move() {
for (int i = 0; i < horses.size(); i++) {
horses.get(i).move();
}
}
public void print() {
for (int i = 0; i < horses.size(); i++) {
horses.get(i).print();
}
for (int i = 0; i < 10; i++) {
System.out.println();
}
}
public Horse getWinner() {
return horses.stream().max(Comparator.comparing(Horse::getDistance)).orElse(null);
}
public void printWinner() {
System.out.printf("Winner is %s!%n", getWinner().getName());
}
}