Compare commits
No commits in common. "lab01" and "main" have entirely different histories.
3
.idea/.gitignore
generated
vendored
3
.idea/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="jdk" jdkName="21" jdkType="JavaSDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,6 +0,0 @@
|
|||||||
public enum DirectionType {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
}
|
|
@ -1,171 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class DrawingMotorBoat {
|
|
||||||
private EntityMotorBoat EntityMotorBoat;
|
|
||||||
private Integer _pictureWidth;
|
|
||||||
private Integer _pictureHeight;
|
|
||||||
private Integer _startPosX;
|
|
||||||
private Integer _startPosY;
|
|
||||||
|
|
||||||
private final int _drawingBoatWidth = 100;
|
|
||||||
private final int _drawingBoatHeight = 50;
|
|
||||||
public DrawingMotorBoatOar _drawingMotorBoatOar;
|
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean inboardEngine, boolean oar, boolean protectiveGlass) {
|
|
||||||
EntityMotorBoat = new EntityMotorBoat();
|
|
||||||
EntityMotorBoat.init(speed, weight, bodyColor, additionalColor, inboardEngine, oar, protectiveGlass);
|
|
||||||
_pictureWidth = null;
|
|
||||||
_pictureHeight = null;
|
|
||||||
_startPosX = null;
|
|
||||||
_startPosY = null;
|
|
||||||
|
|
||||||
_drawingMotorBoatOar = new DrawingMotorBoatOar();
|
|
||||||
Random random = new Random();
|
|
||||||
int[] oarsCount = {1, 2, 3};
|
|
||||||
int oarCount = oarsCount[random.nextInt(oarsCount.length)];
|
|
||||||
_drawingMotorBoatOar.setEnumNumber(oarCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean SetPictureSize(int width, int height) {
|
|
||||||
if (_drawingBoatWidth < width && _drawingBoatHeight < height) {
|
|
||||||
this._pictureWidth = width;
|
|
||||||
this._pictureHeight = height;
|
|
||||||
|
|
||||||
if (_startPosX != null && _startPosX + _drawingBoatWidth > _pictureWidth) {
|
|
||||||
_startPosX = _pictureWidth - _drawingBoatWidth;
|
|
||||||
}
|
|
||||||
if (_startPosY != null && _startPosY + _drawingBoatHeight > _pictureHeight) {
|
|
||||||
_startPosY = _pictureHeight - _drawingBoatHeight;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetPosition(int x, int y) {
|
|
||||||
if (_pictureHeight == null || _pictureWidth == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x + _drawingBoatWidth > _pictureWidth) {
|
|
||||||
x = _pictureWidth - _drawingBoatWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y + _drawingBoatHeight > _pictureHeight) {
|
|
||||||
y = _pictureHeight - _drawingBoatHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x < 0) x = 0;
|
|
||||||
if (y < 0) y = 0;
|
|
||||||
|
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean MoveTransport(DirectionType direction) {
|
|
||||||
if (EntityMotorBoat == null || _startPosX == null || _startPosY == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (direction) {
|
|
||||||
case Left:
|
|
||||||
if (_startPosX - EntityMotorBoat.getStep() > 0) {
|
|
||||||
_startPosX -= (int) EntityMotorBoat.getStep();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case Up:
|
|
||||||
if (_startPosY - EntityMotorBoat.getStep() > 0) {
|
|
||||||
_startPosY -= (int) EntityMotorBoat.getStep();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case Right:
|
|
||||||
if (_startPosX + EntityMotorBoat.getStep() < _pictureWidth - _drawingBoatWidth) {
|
|
||||||
_startPosX += (int) EntityMotorBoat.getStep();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case Down:
|
|
||||||
if (_startPosY + EntityMotorBoat.getStep() < _pictureHeight - _drawingBoatHeight) {
|
|
||||||
_startPosY += (int) EntityMotorBoat.getStep();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawTransport(Graphics g) {
|
|
||||||
if (EntityMotorBoat == null || _startPosX == null || _startPosY == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
||||||
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.setStroke(new BasicStroke(1));
|
|
||||||
|
|
||||||
// Границы катера
|
|
||||||
Polygon boatShape = new Polygon();
|
|
||||||
boatShape.addPoint(_startPosX, _startPosY + 10);
|
|
||||||
boatShape.addPoint(_startPosX + 70, _startPosY + 10);
|
|
||||||
boatShape.addPoint(_startPosX + 100, _startPosY + 25);
|
|
||||||
boatShape.addPoint(_startPosX + 70, _startPosY + 40);
|
|
||||||
boatShape.addPoint(_startPosX, _startPosY + 40);
|
|
||||||
|
|
||||||
g2d.draw(boatShape);
|
|
||||||
g2d.setColor(EntityMotorBoat.getBodyColor());
|
|
||||||
g2d.fillPolygon(boatShape);
|
|
||||||
|
|
||||||
// Палуба
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect(_startPosX + 5, _startPosY + 20, 65, 10);
|
|
||||||
g2d.drawRect(_startPosX + 10, _startPosY + 15, 55, 20);
|
|
||||||
|
|
||||||
g2d.setColor(EntityMotorBoat.getBodyColor());
|
|
||||||
g2d.fillRect(_startPosX + 6, _startPosY + 20, 64, 11);
|
|
||||||
g2d.fillRect(_startPosX + 11, _startPosY + 16, 56, 19);
|
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
for (int j = 0; j < 2; j++) {
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawOval(_startPosX + 5 + i * 55, _startPosY + 15 + j * 10, 10, 10);
|
|
||||||
g2d.setColor(EntityMotorBoat.getBodyColor());
|
|
||||||
g2d.fillOval(_startPosX + 5 + i * 55, _startPosY + 15 + j * 10, 11, 11);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Мотор в корме
|
|
||||||
if (EntityMotorBoat.isInboardEngine()) {
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect(_startPosX + 3, _startPosY + 13, 20, 24);
|
|
||||||
g2d.setColor(EntityMotorBoat.getAdditionalColor());
|
|
||||||
g2d.fillRect(_startPosX + 4, _startPosY + 14, 19, 23);
|
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
for (int j = 0; j < 2; j++) {
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawOval(_startPosX + 5 + i * 9, _startPosY + 15 + j * 13, 6, 6);
|
|
||||||
g2d.setColor(EntityMotorBoat.getAdditionalColor());
|
|
||||||
g2d.fillOval(_startPosX + 6 + i * 9, _startPosY + 16 + j * 13, 4, 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Вёсла
|
|
||||||
if (EntityMotorBoat.isOar()) {
|
|
||||||
_drawingMotorBoatOar.drawMotorBoatOar(g, EntityMotorBoat.getAdditionalColor(), _startPosX, _startPosY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Защитное стекло
|
|
||||||
if (EntityMotorBoat.isProtectiveGlass()) {
|
|
||||||
g2d.setColor(Color.CYAN);
|
|
||||||
g2d.fillRect(_startPosX + 45, _startPosY + 20, 25, 11);
|
|
||||||
g2d.fillRect(_startPosX + 45, _startPosY + 16, 17, 19);
|
|
||||||
|
|
||||||
g2d.fillOval(_startPosX + 59, _startPosY + 15, 11, 11);
|
|
||||||
g2d.fillOval(_startPosX + 59, _startPosY + 24, 11, 11);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingMotorBoatOar {
|
|
||||||
private OarCount _oarCount;
|
|
||||||
public void setEnumNumber(int engineCount) {
|
|
||||||
for (OarCount value : OarCount.values()) {
|
|
||||||
if (value.getEnumNumber() == engineCount) {
|
|
||||||
_oarCount = value;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void drawMotorBoatOar(Graphics g, Color color, float startPosX, float startPosY) {
|
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
|
||||||
g2d.setColor(color);
|
|
||||||
g2d.setStroke(new BasicStroke(1));
|
|
||||||
|
|
||||||
if (_oarCount.getEnumNumber() >= 1) {
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect((int)startPosX + 32, (int)startPosY + 3, 2, 17);
|
|
||||||
g2d.setColor(color);
|
|
||||||
g2d.fillRect((int)startPosX + 33, (int)startPosY + 3, 1, 17);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawOval((int)startPosX + 30, (int)startPosY, 6, 8);
|
|
||||||
g2d.setColor(color);
|
|
||||||
g2d.fillOval((int)startPosX + 30, (int)startPosY, 6, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_oarCount.getEnumNumber() >= 2) {
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect((int)startPosX + 27, (int)startPosY + 3 + 27, 2, 17);
|
|
||||||
g2d.setColor(color);
|
|
||||||
g2d.fillRect((int)startPosX + 28, (int)startPosY + 3 + 27, 1, 17);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawOval((int)startPosX + 25, (int)startPosY + 27 + 17, 6, 8);
|
|
||||||
g2d.setColor(color);
|
|
||||||
g2d.fillOval((int)startPosX + 25, (int)startPosY + 27 + 17, 6, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_oarCount.getEnumNumber() >= 3) {
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect((int)startPosX + 36, (int)startPosY + 3 + 27, 2, 17);
|
|
||||||
g2d.setColor(color);
|
|
||||||
g2d.fillRect((int)startPosX + 37, (int)startPosY + 3 + 27, 1, 17);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawOval((int)startPosX + 34, (int)startPosY + 27 + 17, 6, 8);
|
|
||||||
g2d.setColor(color);
|
|
||||||
g2d.fillOval((int)startPosX + 34, (int)startPosY + 27 + 17, 6, 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
import java.awt.Color;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Класс-сущность "Катер"
|
|
||||||
*/
|
|
||||||
public class EntityMotorBoat {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Скорость
|
|
||||||
*/
|
|
||||||
private int Speed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Вес
|
|
||||||
*/
|
|
||||||
private double Weight;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Основной цвет
|
|
||||||
*/
|
|
||||||
private Color BodyColor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Дополнительный цвет (для опциональных элементов)
|
|
||||||
*/
|
|
||||||
private Color AdditionalColor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Признак (опция) наличия внутреннего двигателя
|
|
||||||
*/
|
|
||||||
private boolean InboardEngine;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Признак (опция) наличия весла
|
|
||||||
*/
|
|
||||||
private boolean Oar;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Признак (опция) наличия защитного стекла
|
|
||||||
*/
|
|
||||||
private boolean ProtectiveGlass;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Шаг перемещения катера
|
|
||||||
*
|
|
||||||
* @return Шаг перемещения
|
|
||||||
*/
|
|
||||||
public double getStep() {
|
|
||||||
return Speed * 100 / Weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Инициализация полей объекта-класса катера
|
|
||||||
*/
|
|
||||||
public void init(int speed, double weight, Color bodyColor, Color additionalColor, boolean inboardEngine, boolean oar, boolean protectiveGlass) {
|
|
||||||
this.Speed = speed;
|
|
||||||
this.Weight = weight;
|
|
||||||
this.BodyColor = bodyColor;
|
|
||||||
this.AdditionalColor = additionalColor;
|
|
||||||
this.InboardEngine = inboardEngine;
|
|
||||||
this.Oar = oar;
|
|
||||||
this.ProtectiveGlass = protectiveGlass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSpeed() {
|
|
||||||
return Speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getWeight() {
|
|
||||||
return Weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color getBodyColor() {
|
|
||||||
return BodyColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color getAdditionalColor() {
|
|
||||||
return AdditionalColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInboardEngine() {
|
|
||||||
return InboardEngine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOar() {
|
|
||||||
return Oar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isProtectiveGlass() {
|
|
||||||
return ProtectiveGlass;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,98 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMotorBoat">
|
|
||||||
<grid id="27dc6" binding="PanelWrapper" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<xy x="26" y="28" width="1024" height="525"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<grid id="7443a" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
|
||||||
<minimum-size width="900" height="500"/>
|
|
||||||
<preferred-size width="900" height="500"/>
|
|
||||||
<maximum-size width="900" height="500"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<hspacer id="46e02">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</hspacer>
|
|
||||||
<vspacer id="33eb8">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</vspacer>
|
|
||||||
<component id="568c3" class="javax.swing.JButton" binding="buttonLeft">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<minimum-size width="40" height="40"/>
|
|
||||||
<preferred-size width="40" height="40"/>
|
|
||||||
<maximum-size width="40" height="40"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<enabled value="true"/>
|
|
||||||
<icon value="Resources/arrowLeft.png"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="5221" class="javax.swing.JButton" binding="buttonDown">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<minimum-size width="40" height="40"/>
|
|
||||||
<preferred-size width="40" height="40"/>
|
|
||||||
<maximum-size width="40" height="40"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<icon value="Resources/arrowDown.png"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="ec99" class="javax.swing.JButton" binding="buttonRight">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<minimum-size width="40" height="40"/>
|
|
||||||
<preferred-size width="40" height="40"/>
|
|
||||||
<maximum-size width="40" height="40"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<icon value="Resources/arrowRight.png"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="22e65" class="javax.swing.JButton" binding="buttonUp">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<minimum-size width="40" height="40"/>
|
|
||||||
<preferred-size width="40" height="40"/>
|
|
||||||
<maximum-size width="40" height="40"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<icon value="Resources/arrowUp.png"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="4c090" class="javax.swing.JButton" binding="buttonCreate">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Создать"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</form>
|
|
@ -1,114 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class FormMotorBoat extends JFrame {
|
|
||||||
protected DrawingMotorBoat _drawingMotorBoat = new DrawingMotorBoat();
|
|
||||||
JPanel PanelWrapper;
|
|
||||||
private JPanel PictureBox;
|
|
||||||
private JButton buttonCreate;
|
|
||||||
private JButton buttonRight;
|
|
||||||
private JButton buttonDown;
|
|
||||||
private JButton buttonLeft;
|
|
||||||
private JButton buttonUp;
|
|
||||||
|
|
||||||
private List<JComponent> controls;
|
|
||||||
|
|
||||||
public FormMotorBoat() {
|
|
||||||
buttonUp.setName("buttonUp");
|
|
||||||
buttonDown.setName("buttonDown");
|
|
||||||
buttonLeft.setName("buttonLeft");
|
|
||||||
buttonRight.setName("buttonRight");
|
|
||||||
|
|
||||||
InitializeControlsRepaintList();
|
|
||||||
|
|
||||||
buttonCreate.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
_drawingMotorBoat = new DrawingMotorBoat();
|
|
||||||
Random r = new Random();
|
|
||||||
|
|
||||||
_drawingMotorBoat.Init(r.nextInt(30, 100),
|
|
||||||
r.nextInt(100, 500),
|
|
||||||
new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)),
|
|
||||||
new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)),
|
|
||||||
r.nextBoolean(), r.nextBoolean(), r.nextBoolean());
|
|
||||||
_drawingMotorBoat.SetPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
|
||||||
_drawingMotorBoat.SetPosition(r.nextInt(25, 100),
|
|
||||||
r.nextInt(25, 100));
|
|
||||||
|
|
||||||
Draw();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ActionListener buttonMoveClickedListener = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
String buttonName = ((JButton) e.getSource()).getName();
|
|
||||||
boolean result = false;
|
|
||||||
|
|
||||||
switch (buttonName) {
|
|
||||||
case "buttonUp": {
|
|
||||||
result = _drawingMotorBoat.MoveTransport(DirectionType.Up);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "buttonDown": {
|
|
||||||
result = _drawingMotorBoat.MoveTransport(DirectionType.Down);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "buttonLeft": {
|
|
||||||
result = _drawingMotorBoat.MoveTransport(DirectionType.Left);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "buttonRight": {
|
|
||||||
result = _drawingMotorBoat.MoveTransport(DirectionType.Right);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (result)
|
|
||||||
Draw();
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
|
||||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
|
||||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
|
||||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Draw() {
|
|
||||||
if (_drawingMotorBoat == null)
|
|
||||||
return;
|
|
||||||
if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Graphics g = PictureBox.getGraphics();
|
|
||||||
g.setColor(PictureBox.getBackground());
|
|
||||||
g.fillRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
|
||||||
_drawingMotorBoat.DrawTransport(g);
|
|
||||||
|
|
||||||
RepaintControls();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RepaintControls() {
|
|
||||||
for (JComponent control : controls) {
|
|
||||||
control.repaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitializeControlsRepaintList() {
|
|
||||||
controls = new LinkedList<>();
|
|
||||||
controls.add(buttonCreate);
|
|
||||||
controls.add(buttonUp);
|
|
||||||
controls.add(buttonDown);
|
|
||||||
controls.add(buttonLeft);
|
|
||||||
controls.add(buttonRight);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
JFrame.setDefaultLookAndFeelDecorated(false);
|
|
||||||
JFrame frame = new JFrame("Моторная лодка");
|
|
||||||
frame.setContentPane(new FormMotorBoat().PanelWrapper);
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
frame.setLocation(400, 200);
|
|
||||||
frame.pack();
|
|
||||||
frame.setSize(940, 540);
|
|
||||||
frame.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
public enum OarCount {
|
|
||||||
One(1),
|
|
||||||
Two(2),
|
|
||||||
Three(3);
|
|
||||||
|
|
||||||
final private int EnumNumber;
|
|
||||||
|
|
||||||
OarCount(int enumNumber) {
|
|
||||||
EnumNumber = enumNumber;
|
|
||||||
}
|
|
||||||
public int getEnumNumber() {
|
|
||||||
return EnumNumber;
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
Before Width: | Height: | Size: 524 B |
Binary file not shown.
Before Width: | Height: | Size: 533 B |
Binary file not shown.
Before Width: | Height: | Size: 553 B |
Binary file not shown.
Before Width: | Height: | Size: 524 B |
Loading…
x
Reference in New Issue
Block a user