Skip to content

24 Hours of Le Mans game - #1

Open
iandrianov wants to merge 1 commit into
mainfrom
dev
Open

iandrianov wants to merge 1 commit into
mainfrom
dev

Conversation

@iandrianov

Copy link
Copy Markdown
Owner

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.

…n methods have been added. The winner's name is also now displayed in the console.
Comment thread src/main/java/Car.java
Comment on lines +2 to +3
int speed;
String name;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поля лучше пометить final, тем самым исключив возможность их модификации извне

Comment thread src/main/java/Main.java
Comment on lines +46 to +57
String[] frames = {
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨"
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Массив можно вынести в константу, чтобы не создавать на каждый вызов функции новый массив

Comment thread src/main/java/Main.java

for (String frame : frames) {
System.out.print("\r" + frame);
Thread.sleep(150);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Значение задержки лучше вынести в константу для повышения читабельности кода

Comment thread src/main/java/Race.java
import java.util.Scanner;

public class Race {
ArrayList<Car> raceParticipants = new ArrayList<>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

От хранения массива машин и лишнего цикла при определении победителя можно избавиться, если при вводе данных сразу вычислять победителя и хранить его в отдельной переменной, тогда программа будет требовать меньше памяти и работать быстрее

Comment thread src/main/java/Race.java
if (scanner.hasNextInt()) {
speed = scanner.nextInt();
scanner.nextLine();
if (speed > 0 && speed <= 250) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода

Comment thread src/main/java/Race.java
return winner;
}

static void Print(String text) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В джава функции принято именовать с маленькой буквы

Comment thread src/main/java/Race.java

if (car.name.equalsIgnoreCase("Lada") || car.name.equalsIgnoreCase("Лада") || car.name.equalsIgnoreCase("Жигули")) {
System.out.println("🚗 " + car.name + " получает бонус! +100 к скорости 💨");
car.speed += 100;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Интересное авторское решение, но от требований все-таки лучше не отходить =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants