Repository navigation
24 Hours of Le Mans game - #1
iandrianov wants to merge 1 commit into
Conversation
…n methods have been added. The winner's name is also now displayed in the console.
| int speed; | ||
| String name; |
There was a problem hiding this comment.
Поля лучше пометить final, тем самым исключив возможность их модификации извне
| String[] frames = { | ||
| " 🚗💨", | ||
| " 🚗💨", | ||
| " 🚗💨", | ||
| " 🚗💨", | ||
| " 🚗💨", | ||
| " 🚗💨", | ||
| " 🚗💨", | ||
| " 🚗💨", | ||
| " 🚗💨", | ||
| " 🚗💨" | ||
| }; |
There was a problem hiding this comment.
Массив можно вынести в константу, чтобы не создавать на каждый вызов функции новый массив
|
|
||
| for (String frame : frames) { | ||
| System.out.print("\r" + frame); | ||
| Thread.sleep(150); |
There was a problem hiding this comment.
Значение задержки лучше вынести в константу для повышения читабельности кода
| import java.util.Scanner; | ||
|
|
||
| public class Race { | ||
| ArrayList<Car> raceParticipants = new ArrayList<>(); |
There was a problem hiding this comment.
От хранения массива машин и лишнего цикла при определении победителя можно избавиться, если при вводе данных сразу вычислять победителя и хранить его в отдельной переменной, тогда программа будет требовать меньше памяти и работать быстрее
| if (scanner.hasNextInt()) { | ||
| speed = scanner.nextInt(); | ||
| scanner.nextLine(); | ||
| if (speed > 0 && speed <= 250) { |
There was a problem hiding this comment.
Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода
| return winner; | ||
| } | ||
|
|
||
| static void Print(String text) { |
There was a problem hiding this comment.
В джава функции принято именовать с маленькой буквы
|
|
||
| if (car.name.equalsIgnoreCase("Lada") || car.name.equalsIgnoreCase("Лада") || car.name.equalsIgnoreCase("Жигули")) { | ||
| System.out.println("🚗 " + car.name + " получает бонус! +100 к скорости 💨"); | ||
| car.speed += 100; |
There was a problem hiding this comment.
Интересное авторское решение, но от требований все-таки лучше не отходить =)
Car and race classes, race formation methods, and winner determination methods have been added. The winner's name is also now displayed in the console.