Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Домашняя работа #1 #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Домашняя работа #1 #1

wants to merge 2 commits into from

Conversation

abercromb
Copy link
Owner

No description provided.

Copy link

@Ivan-Igorevich Ivan-Igorevich left a comment

Choose a reason for hiding this comment

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

В целом, всё хорошо, ожидаемо не очень хорошо сделан фон, но его и нельзя было сделать хорошо, но неожиданно, в неправильном месте обработка мыши...


GameCanvas(MainCircles gameWindow) {
this.gameWindow = gameWindow;
addMouseListener(new MouseController(this));

Choose a reason for hiding this comment

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

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

private static final int WINDOW_WIDTH = 800;
private static final int WINDOW_HEIGHT = 600;
Sprite[] sprites = new Sprite[10];
BackGround backGround = new BackGround(100);

Choose a reason for hiding this comment

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

не было желания сделать его спрайтом?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Сделать BackGround спрайтом? Не было) Как это вообще)

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class MouseController extends MouseAdapter {

Choose a reason for hiding this comment

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

не обязательно было создавать прям свой отдельный контроллер для такой простой задачи, адаптера было достаточно

Copy link
Owner Author

Choose a reason for hiding this comment

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

Зато в конструкторе канвы на вызов обработчика одна строчка, а не забор

public int getRight() { return getWidth() - 1; }
public int getTop() { return 0; }
public int getBottom() { return getHeight() - 1; }
public MainCircles getGameWindow(){return gameWindow;};

Choose a reason for hiding this comment

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

чую неладное, зачем расприватили?


if (e.getButton() == MouseEvent.BUTTON1)
{
canvas.getGameWindow().addSprite();

Choose a reason for hiding this comment

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

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

Самое интересное, что в Java 1 преподаватель делает цепочки вот такие

board.getGame().getCurrentPlayer().getPlayerSign()

Из чего делаешь вывод, что так делать и нужно)


}

//Удаление шарика из массива

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