-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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)); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не было желания сделать его спрайтом?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не обязательно было создавать прям свой отдельный контроллер для такой простой задачи, адаптера было достаточно
There was a problem hiding this comment.
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;}; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ах вот оно что... понял зачем расприватили... собственно, это должно было натолкнуть на мысль, что вешать обработчик мыши на канву - плохо, длинноватая цепочка у сигнала получается
There was a problem hiding this comment.
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()
Из чего делаешь вывод, что так делать и нужно)
|
||
} | ||
|
||
//Удаление шарика из массива |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
на мой взгляд дороговато каждый раз пересоздавать массив и по + и по -... но об этом мы поговорим на уроке.
No description provided.