Skip to content

Conversation

@EvgenySobko
Copy link

@EvgenySobko EvgenySobko commented Mar 3, 2018

Now it works!

@@ -0,0 +1,178 @@
package myClass;
Copy link
Owner

Choose a reason for hiding this comment

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

Не самое лучшее название для пакета. Название должно описывать, что именно содержится в пакете.


public class Cube {
public char[][][] cube;
public int n;
Copy link
Owner

Choose a reason for hiding this comment

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

Имя переменной

public char[][][] cube;
public int n;

char[] symbols = {'W', 'R', 'B', 'O', 'Y', 'G'};
Copy link
Owner

Choose a reason for hiding this comment

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

К вашей задаче очень хорошо подойдет Enum для описания цветов.


public Cube(int n) {
this.n = n;
this.cube = new char[6][n][n];
Copy link
Owner

Choose a reason for hiding this comment

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

Выносите "магические" константы в отдельные final переменные.


for (int i = 0; i < 6; ++i) {
for (int j = 0; j < n; ++j) {
Arrays.fill(cube[i][j], symbols[i]);
Copy link
Owner

Choose a reason for hiding this comment

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

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

@@ -0,0 +1,57 @@
package myClass;

public class PrintCube {
Copy link
Owner

Choose a reason for hiding this comment

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

А вот классы обычно обозначаются существительными. CubePrinter тогда уж.

private int n;

PrintCube(int n) {
this.arr = new char[n * 8 + 1][n * 18 + 1];
Copy link
Owner

Choose a reason for hiding this comment

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

Почему 8? Почему 18? Почему + 1?

char[][][] ptr = cube.Get();
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
arr[i * 2 + 1][n * 6 + 3 + j * 6] = ptr[0][i][j];
Copy link
Owner

Choose a reason for hiding this comment

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

Вот где-где, а тут я "магии" совсем не ожидал

RotateUp();
}

public void Spin(int t) {
Copy link
Owner

Choose a reason for hiding this comment

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

Что означает t? Если я буду пользователем вашего класса, как я могу догадаться, что означает данный аргумент?

Copy link
Author

Choose a reason for hiding this comment

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

Поправил имя переменной, это направление поворота.

Copy link
Owner

Choose a reason for hiding this comment

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

Как задается направление? Если я хочу повернуть грань влево, что мне нужно записать в direction? 10? 1? 0?

@Test
public void rotateUp() {
result.RotateUp();
assertArrayEquals(result.cube[0], actual.cube[2]);
Copy link
Owner

Choose a reason for hiding this comment

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

Опять магия. Надеюсь, когда сделаете стороны через Enum, будет понятнее.

Copy link
Author

Choose a reason for hiding this comment

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

Аналогично тому что я писал ранее, у нас есть 2 грани (result и actual) для сравнения, actual - измененная грань.

@@ -0,0 +1,57 @@
package myRubiksCube;

public class CubePrinter {
Copy link
Owner

Choose a reason for hiding this comment

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

Давайте подумаем, как можно разгрузить этот класс от "магии". Я вижу два варианта.

  1. Итак, у нас в изображении-развертке 12 блоков (6 граней куба плюс 6 пустых блоков). Можно сделать метод, который будет заполнять один конкретный блок. То есть на выходе он будет давать строку, которая описывает блок. Соединить потом блоки - не проблема.
    Для каждого блока мы делаем сетку. Вынесем это тоже в отдельный метод. Можно опять же создать одну ячейку, а потом "размножить" её путем склеивания строк. Заполнение ячейки - тоже отдельный метод, пусть и совсем маленький. Путем такого разбиения можно постепенного избавиться от магических констант.
  2. Создать текстовый файл, который будет содержать шаблон. Можно оставить текущий внешний вид, можно сделать вид а-ля проекция, используя, например, символы /. Вместо цветов на гранях - буквы. Цифр, заглавных и строчных букв хватит, чтобы отметить все квадраты разными символами. Потом, используя replace, подставляем вместо символов нужные цвета.
    Если бы было побольше времени, можно было бы аналогичным образом даже сформировать картинку.

Есть ещё такой вариант. Вы не убираете "магию" из кода, не переделываете char на enum, исправляете оставшиеся замечания, но оценка будет 4.

Copy link
Author

Choose a reason for hiding this comment

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

Не видел Вашего комментария, я подумаю что можно с этим сделать.

@h31
Copy link
Owner

h31 commented Mar 15, 2018

Пока что 4. Задание непростое, вы его решили. Но запутанный код - это бомба замедленного действия.

@h31 h31 added the good Хорошо label Mar 15, 2018
@h31
Copy link
Owner

h31 commented Mar 15, 2018

Если вы болеете, то я готов подождать исправлений. Выздоравливайте!

@EvgenySobko
Copy link
Author

Понимая объем кода, который мне придется переписать, и учитывая мое текущее состояние, сомневаюсь, что смогу что-либо изменить. Плюс, не могу заставлять ждать, да и самому хочется перейти к следующему заданию. Понимаю, что код запутан очень сильно, постараюсь впредь писать понятнее. Постараюсь поскорее поправиться, спасибо!

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

Labels

good Хорошо

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants