Compare commits

..

No commits in common. "Lab4" and "main" have entirely different histories.
Lab4 ... main

29 changed files with 0 additions and 2026 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 281 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 B

View File

@ -1,14 +0,0 @@
package SelfPropelledArtilleryUnit;
public enum DirectionType
{
Up(1),
Down(2),
Left(3),
Right(4);
private final int DirectionTypeCode;
private DirectionType(int DirectionTypeCode){
this.DirectionTypeCode = DirectionTypeCode;
}
}

View File

@ -1,175 +0,0 @@
package SelfPropelledArtilleryUnit.DrawningObjects;
import SelfPropelledArtilleryUnit.NumbeRollers;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
public class DrawningClamps implements IDrawable {
Graphics2D g2d;
int startPosX;
int startPosY;
Color color;
private NumbeRollers _numbeRollers;
@Override
public void setNum(int numRollers) {
if (numRollers < 4 || numRollers > 6 ){
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
return;
}
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
}
public DrawningClamps(Graphics2D g2d, int startPosX, int startPosY, Color color, int numRollers){
this.color = color;
this.g2d = g2d;
this.startPosX = startPosX;
this.startPosY = startPosY;
setNum(numRollers);
}
public DrawningClamps(){}
@Override
public void Draw(Graphics2D g2d, int startPosX, int startPosY, Color color){
this.color = color;
this.g2d = g2d;
this.startPosX = startPosX;
this.startPosY = startPosY;
g2d.setPaint(Color.BLACK);
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
g2d.draw(ellipse7);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
break;
case Mid:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
break;
case Max:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
g2d.fill(ellipse6);
break;
}
Ellipse2D ellipse11 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 10, 10);
Ellipse2D ellipse12 = new Ellipse2D.Double(startPosX + 35, startPosY + 55, 10, 10);
Ellipse2D ellipse13 = new Ellipse2D.Double(startPosX + 60, startPosY + 55, 10, 10);
Ellipse2D ellipse14 = new Ellipse2D.Double(startPosX + 85, startPosY + 55, 10, 10);
Ellipse2D ellipse15 = new Ellipse2D.Double(startPosX + 110, startPosY + 55, 10, 10);
Ellipse2D ellipse16 = new Ellipse2D.Double(startPosX + 127, startPosY + 60, 5, 5);
g2d.setPaint(color);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
break;
case Mid:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
break;
case Max:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
g2d.fill(ellipse16);
break;
}
}
@Override
public void Draw(){
g2d.setPaint(Color.BLACK);
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
g2d.draw(ellipse7);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
break;
case Mid:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
break;
case Max:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
g2d.fill(ellipse6);
break;
}
Ellipse2D ellipse11 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 10, 10);
Ellipse2D ellipse12 = new Ellipse2D.Double(startPosX + 35, startPosY + 55, 10, 10);
Ellipse2D ellipse13 = new Ellipse2D.Double(startPosX + 60, startPosY + 55, 10, 10);
Ellipse2D ellipse14 = new Ellipse2D.Double(startPosX + 85, startPosY + 55, 10, 10);
Ellipse2D ellipse15 = new Ellipse2D.Double(startPosX + 110, startPosY + 55, 10, 10);
Ellipse2D ellipse16 = new Ellipse2D.Double(startPosX + 127, startPosY + 60, 5, 5);
g2d.setPaint(color);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
break;
case Mid:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
break;
case Max:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
g2d.fill(ellipse16);
break;
}
}
}

View File

@ -1,176 +0,0 @@
package SelfPropelledArtilleryUnit.DrawningObjects;
import SelfPropelledArtilleryUnit.NumbeRollers;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
public class DrawningNails implements IDrawable {
Graphics2D g2d;
int startPosX;
int startPosY;
Color color;
private NumbeRollers _numbeRollers;
@Override
public void setNum(int numRollers) {
if (numRollers < 4 || numRollers > 6 ){
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
return;
}
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
}
public DrawningNails(Graphics2D g2d, int startPosX, int startPosY, Color color, int numRollers){
this.color = color;
this.g2d = g2d;
this.startPosX = startPosX;
this.startPosY = startPosY;
setNum(numRollers);
}
public DrawningNails(){}
@Override
public void Draw(Graphics2D g2d, int startPosX, int startPosY, Color color){
this.color = color;
this.g2d = g2d;
this.startPosX = startPosX;
this.startPosY = startPosY;
g2d.setPaint(Color.BLACK);
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
g2d.draw(ellipse7);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
break;
case Mid:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
break;
case Max:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
g2d.fill(ellipse6);
break;
}
Ellipse2D ellipse11 = new Ellipse2D.Double(startPosX + 15, startPosY + 62, 2, 2);
Ellipse2D ellipse12 = new Ellipse2D.Double(startPosX + 40, startPosY + 62, 2, 2);
Ellipse2D ellipse13 = new Ellipse2D.Double(startPosX + 65, startPosY + 62, 2, 2);
Ellipse2D ellipse14 = new Ellipse2D.Double(startPosX + 90, startPosY + 62, 2, 2);
Ellipse2D ellipse15 = new Ellipse2D.Double(startPosX + 115, startPosY + 62, 2, 2);
Ellipse2D ellipse16 = new Ellipse2D.Double(startPosX + 130, startPosY + 65, 1, 1);
g2d.setPaint(color);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
break;
case Mid:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
break;
case Max:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
g2d.fill(ellipse16);
break;
}
}
@Override
public void Draw(){
g2d.setPaint(Color.BLACK);
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
g2d.draw(ellipse7);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
break;
case Mid:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
break;
case Max:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
g2d.fill(ellipse6);
break;
}
Ellipse2D ellipse11 = new Ellipse2D.Double(startPosX + 15, startPosY + 62, 2, 2);
Ellipse2D ellipse12 = new Ellipse2D.Double(startPosX + 40, startPosY + 62, 2, 2);
Ellipse2D ellipse13 = new Ellipse2D.Double(startPosX + 65, startPosY + 62, 2, 2);
Ellipse2D ellipse14 = new Ellipse2D.Double(startPosX + 90, startPosY + 62, 2, 2);
Ellipse2D ellipse15 = new Ellipse2D.Double(startPosX + 115, startPosY + 62, 2, 2);
Ellipse2D ellipse16 = new Ellipse2D.Double(startPosX + 130, startPosY + 65, 1, 1);
g2d.setPaint(color);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
break;
case Mid:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
break;
case Max:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
g2d.fill(ellipse16);
break;
}
}
}

View File

@ -1,110 +0,0 @@
package SelfPropelledArtilleryUnit.DrawningObjects;
import SelfPropelledArtilleryUnit.NumbeRollers;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
public class DrawningRollers implements IDrawable{
Graphics2D g2d;
int startPosX;
int startPosY;
Color color;
private NumbeRollers _numbeRollers;
@Override
public void setNum(int numRollers) {
if (numRollers < 4 || numRollers > 6 ){
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
return;
}
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
}
public DrawningRollers(Graphics2D g2d, int startPosX, int startPosY, Color color, int numRollers){
this.color = color;
this.g2d = g2d;
this.startPosX = startPosX;
this.startPosY = startPosY;
setNum(numRollers);
}
public DrawningRollers(){}
@Override
public void Draw(Graphics2D g2d, int startPosX, int startPosY, Color color){
this.color = color;
this.g2d = g2d;
this.startPosX = startPosX;
this.startPosY = startPosY;
g2d.setPaint(Color.BLACK);
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
g2d.draw(ellipse7);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
break;
case Mid:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
break;
case Max:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
g2d.fill(ellipse6);
break;
}
}
@Override
public void Draw(){
g2d.setPaint(Color.BLACK);
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
g2d.draw(ellipse7);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
break;
case Mid:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
break;
case Max:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
g2d.fill(ellipse6);
break;
}
}
}

View File

@ -1,253 +0,0 @@
package SelfPropelledArtilleryUnit.DrawningObjects;
import java.awt.*;
import java.awt.geom.Path2D;
import SelfPropelledArtilleryUnit.DirectionType;
import SelfPropelledArtilleryUnit.Entities.EntitySPAU;
import SelfPropelledArtilleryUnit.MovementStrategy.DrawningObjectSPAU;
import SelfPropelledArtilleryUnit.MovementStrategy.IMoveableObject;
public class DrawningSPAU {
private EntitySPAU EntitySPAU;
private int pictureWidth;
private int pictureHeight;
protected int startPosX;
protected int startPosY;
private int _numbeRollers;
private int rollVar;
private int carWidth = 135;
private int carHeight = 75;
private IDrawable Rollers;
protected void setEntitySPAU(EntitySPAU entitySPAU) {
this.EntitySPAU = entitySPAU;
}
public EntitySPAU getEntitySPAU() {
return EntitySPAU;
}
public DrawningSPAU(int _numbeRollers, int rollVar, int speed, double weight, Color bodyColor, int width, int height)
{
this._numbeRollers = _numbeRollers;
this.rollVar = rollVar;
this.pictureWidth = width;
this.pictureHeight = height;
if (this.carHeight >= height)
{
return;
}
if (this.carWidth >= width)
{
return;
}
EntitySPAU = new EntitySPAU(speed, weight, bodyColor);
}
public DrawningSPAU(int _numbeRollers, int rollVar, int speed, double weight, Color bodyColor, int width, int height, int carWidth, int carHeight)
{
this._numbeRollers = _numbeRollers;
this.rollVar = rollVar;
this.pictureWidth = width;
this.pictureHeight = height;
this.carWidth = carWidth;
this.carHeight = carHeight;
if (this.carHeight >= height)
{
return;
}
if (this.carWidth >= width)
{
return;
}
EntitySPAU = new EntitySPAU(speed, weight, bodyColor);
}
public DrawningSPAU(EntitySPAU sPAU, IDrawable roll, int width, int height)
{ if (this.carHeight >= height)
{
return;
}
if (this.carWidth >= width)
{
return;
}
startPosX = 0;
startPosY = 0;
pictureWidth = width;
pictureHeight = height;
EntitySPAU = sPAU;
Rollers = roll;
}
public void SetPosition(int x, int y)
{
if (x < 0 || x > this.pictureWidth - this.carWidth)
{
x = 0;
}
if (y < 0 || y > this.pictureHeight - this.carHeight)
{
y = 0;
}
this.startPosX = x;
this.startPosY = y;
}
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntitySPAU == null)
{
return;
}
switch (direction)
{
//влево
case Left:
this.startPosX -= (int)EntitySPAU.getStep();
break;
//вверх
case Up:
this.startPosY -= (int)EntitySPAU.getStep();
break;
// вправо
case Right:
this.startPosX += (int)EntitySPAU.getStep();
break;
//вниз
case Down:
this.startPosY += (int)EntitySPAU.getStep();
break;
}
}
public void DrawTransport(Graphics g) {
if (EntitySPAU == null) {
return;
}
Graphics2D g2d = (Graphics2D) g;
Color bodyColor = EntitySPAU.BodyColor;
Path2D.Double path = new Path2D.Double();
//гусеницы
if (Rollers == null){
Rollers = new DrawningRollers(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
switch (rollVar) {
case 2:
Rollers = new DrawningClamps(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
break;
case 3:
Rollers = new DrawningNails(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
break;
default:
break;
}
Rollers.Draw();
}
else{
Rollers.Draw(g2d, startPosX, startPosY, bodyColor);
}
// пушка
path.moveTo(startPosX + 35, startPosY + 40);
path.lineTo(startPosX + 40, startPosY + 45);
path.lineTo(startPosX + 135, startPosY + 5);
path.lineTo(startPosX + 130, startPosY + 0);
path.closePath();
g2d.setPaint(bodyColor);
g2d.fill(path);
g2d.draw(path);
path.reset();
// корпус
path.moveTo(startPosX, startPosY + 60);
path.lineTo(startPosX + 10, startPosY + 30);
path.lineTo(startPosX + 130, startPosY + 30);
path.lineTo(startPosX + 135, startPosY + 60);
path.closePath();
g2d.setPaint(bodyColor);
g2d.fill(path);
g2d.draw(path);
path.reset();
// башня
path.moveTo(startPosX + 40, startPosY + 30);
path.lineTo(startPosX + 45, startPosY + 15);
path.lineTo(startPosX + 70, startPosY + 15);
path.lineTo(startPosX + 75, startPosY + 30);
path.closePath();
g2d.setPaint(bodyColor);
g2d.fill(path);
g2d.draw(path);
}
/**
* Координата X объекта
*
* @return значение координаты X
*/
public int getPosX() {
return this.startPosX;
}
/**
* Координата Y объекта
*
* @return значение координаты Y
*/
public int getPosY() {
return this.startPosY;
}
/**
* Ширина объекта
*
* @return значение ширины
*/
public int getWidth() {
return this.carWidth;
}
/**
* Высота объекта
*
* @return значение высоты
*/
public int getHeight() {
return this.carHeight;
}
/**
* Проверка, что объект может переместиться в указанном направлении
*
* @param direction Направление
* @return true - можно переместиться в указанном направлении
*/
public boolean CanMove(DirectionType direction) {
if (EntitySPAU == null) {
return false;
}
switch (direction) {
case Left: // влево
return startPosX - EntitySPAU.getStep() > 0;
case Up: // вверх
return startPosY - EntitySPAU.getStep() > 0;
case Right: // вправо
return startPosX + EntitySPAU.getStep() < pictureWidth - carWidth;
case Down: // вниз
return startPosY + EntitySPAU.getStep() < pictureHeight - carHeight;
default:
return false;
}
}
public IMoveableObject GetMoveableObject() {
return new DrawningObjectSPAU(this);
}
}

View File

@ -1,53 +0,0 @@
package SelfPropelledArtilleryUnit.DrawningObjects;
import java.awt.*;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import SelfPropelledArtilleryUnit.Entities.EntitySPAUchild;
public class DrawningSPAUchild extends DrawningSPAU {
private EntitySPAUchild EntitySPAU;
protected void setEntitySPAU(EntitySPAUchild entitySPAU) {
this.EntitySPAU = entitySPAU;
}
public DrawningSPAUchild(int _numbeRollers, int rollVar, int speed, double weight, Color bodyColor, Color additionalColor, boolean bodyKit, boolean ballone, int width, int height) {
super(_numbeRollers, rollVar, speed, weight, bodyColor, width, height);
EntitySPAU = new EntitySPAUchild(speed, weight, bodyColor, additionalColor, bodyKit, ballone);
}
@Override
public void DrawTransport(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
BasicStroke penBlack = new BasicStroke(1);
Color additionalColor = EntitySPAU.AdditionalColor;
boolean hasBodyKit = EntitySPAU.BodyKit;
Path2D.Double path = new Path2D.Double();
// Обвесы
if (hasBodyKit) {
path.moveTo(startPosX + 15, startPosY + 20);
path.lineTo(startPosX + 35, startPosY + 20);
path.lineTo(startPosX + 35, startPosY + 60);
path.lineTo(startPosX + 15, startPosY + 60);
path.closePath();
g2d.setPaint(additionalColor);
g2d.fill(path);
g2d.setPaint(Color.BLACK);
g2d.setStroke(penBlack);
g2d.draw(path);
path.reset();
Line2D line = new Line2D.Double(startPosX + 5, startPosY + 20, startPosX + 15, startPosY + 25);
g2d.draw(line);
super.DrawTransport(g);
}
}
}

View File

@ -1,10 +0,0 @@
package SelfPropelledArtilleryUnit.DrawningObjects;
import java.awt.Color;
import java.awt.Graphics2D;
public interface IDrawable {
public void setNum(int num);
public void Draw();
public void Draw(Graphics2D g2d, int startPosX, int startPosY, Color color);
}

View File

@ -1,19 +0,0 @@
package SelfPropelledArtilleryUnit.Entities;
import java.awt.Color;
public class EntitySPAU {
public int Speed;
public double Weight;
public Color BodyColor;
public EntitySPAU(int speed, double weight, Color bodyColor) {
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
public double getStep() {
return (double) Speed * 100 / Weight;
}
}

View File

@ -1,16 +0,0 @@
package SelfPropelledArtilleryUnit.Entities;
import java.awt.Color;
public class EntitySPAUchild extends EntitySPAU{
public Color AdditionalColor;
public boolean BodyKit;
public boolean Ballone;
public EntitySPAUchild(int speed, double weight, Color bodyColor, Color additionalColor, boolean bodyKit, boolean ballone) {
super(speed, weight, bodyColor); // Вызов конструктора суперкласса
AdditionalColor = additionalColor;
BodyKit = bodyKit;
Ballone = ballone;
}
}

View File

@ -1,98 +0,0 @@
package SelfPropelledArtilleryUnit;
import javax.swing.*;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningClamps;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningNails;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningRollers;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
import SelfPropelledArtilleryUnit.DrawningObjects.IDrawable;
import SelfPropelledArtilleryUnit.Entities.EntitySPAU;
import SelfPropelledArtilleryUnit.Generics.RandomParts;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
public class FormHard {
private JFrame frameMain;
private JPanel panelMain;
private JButton buttonCreate;
private RandomParts<EntitySPAU, IDrawable> generator;
public FormHard() {
InitializeComponent();
Random rand = new Random();
// макс. кол-во вариаций форм дверей/видов автобуса
int maxCnt = rand.nextInt(5, 11);
generator = new RandomParts<>(maxCnt, maxCnt, panelMain.getWidth(), panelMain.getHeight());
// добавление в массивы с дверьми/сущностями рандомные варианты
for (int i = 0; i < maxCnt; i++) {
generator.Add(createRandomEntitySPAU());
generator.Add(createRandomDop());
}
}
private void InitializeComponent() {
//Само окно
frameMain = new JFrame("Усложнённая лаб 3");
frameMain.setSize(900, 500);
frameMain.setLayout(new BorderLayout());
frameMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Панель, на которой отрисовывается
panelMain = new JPanel();
panelMain.setLayout(null);
buttonCreate = new JButton("Создать");
buttonCreate.setBounds(10,400,150,30);
buttonCreate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
createRandomDrawingBus(e);
}
});
frameMain.add(panelMain, BorderLayout.CENTER);
panelMain.add(buttonCreate);
frameMain.setVisible(true);
}
private void Draw(DrawningSPAU drawingSPAU){
if (drawingSPAU == null) {
return;
}
Graphics g = panelMain.getGraphics();
// Очистка перед перерисовкой
panelMain.paint(g);
drawingSPAU.DrawTransport(g);
}
private void createRandomDrawingBus(ActionEvent e) {
DrawningSPAU drawingBus = generator.CreateObject();
drawingBus.SetPosition(50, 50);
Draw(drawingBus);
}
private EntitySPAU createRandomEntitySPAU() {
Random rand = new Random();
Color color = new Color(rand.nextInt(0, 256), rand.nextInt(0, 256), rand.nextInt(0, 256));
EntitySPAU entityBus = new EntitySPAU(rand.nextInt(100, 300), rand.nextDouble(1000, 3000), color);
return entityBus;
}
private IDrawable createRandomDop() {
IDrawable dops;
Random rand = new Random();
int shape = rand.nextInt(1, 3);
if (shape == 1) {
dops = new DrawningClamps();
}
else if (shape == 2) {
dops = new DrawningNails();
}
else {
dops = new DrawningRollers();
}
dops.setNum(rand.nextInt(4, 6));
return dops;
}
}

View File

@ -1,306 +0,0 @@
package SelfPropelledArtilleryUnit;
import javax.swing.*;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAUchild;
import SelfPropelledArtilleryUnit.MovementStrategy.AbstractStrategy;
import SelfPropelledArtilleryUnit.MovementStrategy.DrawningObjectSPAU;
import SelfPropelledArtilleryUnit.MovementStrategy.MoveToBorder;
import SelfPropelledArtilleryUnit.MovementStrategy.MoveToCenter;
import SelfPropelledArtilleryUnit.MovementStrategy.Status;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.Random;
public class FormSPAU extends JFrame {
private JPanel mainPanel;
private JButton buttonCreate;
private JButton buttonCreateParent;
private JButton buttonStep;
private JButton buttonSelectSPAU;
private JComboBox<String> comboBoxStrategy;
private JComboBox<String> comboBoxRoll;
private JButton buttonUp;
private JButton buttonDown;
private JButton buttonLeft;
private JButton buttonRight;
private JLabel pictureBoxSPAU;
private DrawningSPAU drawningSPAU;
private AbstractStrategy abstractStrategy;
private JTextField wheelsTextField;
private JLabel wheelsLabel;
private DrawningSPAU SelectedSPAU;
public DrawningSPAU GetSelectedSPAU() {
return SelectedSPAU;
}
public FormSPAU() {
initComponents();
}
private void Draw() {
if (drawningSPAU == null) {
return;
}
BufferedImage bmp = new BufferedImage(pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight(),
BufferedImage.TYPE_INT_ARGB);
Graphics2D gr = bmp.createGraphics();
drawningSPAU.DrawTransport(gr);
ImageIcon imageIcon = new ImageIcon(bmp);
pictureBoxSPAU.setIcon(imageIcon);
}
private void initComponents() {
mainPanel = new JPanel();
buttonCreate = new JButton("Создать c залповой установкой");
buttonCreateParent = new JButton("Создать базовый");
buttonUp = new JButton(new ImageIcon("resources/upper_arrow.png"));
buttonDown = new JButton(new ImageIcon("resources/down_arrow.png"));
buttonLeft = new JButton(new ImageIcon("resources/left_arrow.png"));
buttonRight = new JButton(new ImageIcon("resources/right_arrow.png"));
pictureBoxSPAU = new JLabel();
wheelsLabel = new JLabel("Количество колёс:");
wheelsTextField = new JTextField();
setLayout(new BorderLayout());
add(mainPanel, BorderLayout.CENTER);
mainPanel.setLayout(null);
pictureBoxSPAU.setBounds(0, 0, 882, 453);
mainPanel.add(pictureBoxSPAU);
wheelsLabel.setBounds(22, 410, 150, 29);
mainPanel.add(wheelsLabel);
wheelsTextField.setBounds(150, 410, 80, 29);
mainPanel.add(wheelsTextField);
// buttonCreate
buttonCreate.setBounds(250, 410, 250, 29);
mainPanel.add(buttonCreate);
buttonCreate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonCreateActionPerformed(e);
}
});
// buttonCreateParent
buttonCreateParent.setBounds(500, 409, 150, 30);
mainPanel.add(buttonCreateParent);
buttonCreateParent.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonCreateParent_Click(e);
}
});
// buttonStep
buttonStep = new JButton("Шаг");
mainPanel.add(buttonStep);
buttonStep.setBounds(794, 55, 76, 30);
buttonStep.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonStep_Click(e);
}
});
// ButtonSelectSPAU
buttonSelectSPAU = new JButton("Выбрать");
mainPanel.add(buttonSelectSPAU);
buttonSelectSPAU.setLocation(new Point(759, 90));
buttonSelectSPAU.setBounds(794, 85, 76, 30);
buttonSelectSPAU.addActionListener(e -> buttonSelectSPAU_Click(e));
// comboBoxRoll
comboBoxRoll = new JComboBox<>();
mainPanel.add(comboBoxRoll);
comboBoxRoll.setModel(new DefaultComboBoxModel<>(new String[] { "1", "2", "3" }));
comboBoxRoll.setBounds(767, 232, 103, 28);
// comboBoxStrategy
comboBoxStrategy = new JComboBox<>();
mainPanel.add(comboBoxStrategy);
comboBoxStrategy.setModel(new DefaultComboBoxModel<>(new String[] { "0", "1" }));
comboBoxStrategy.setBounds(767, 12, 103, 28);
buttonUp.setBounds(804, 336, 30, 30);
mainPanel.add(buttonUp);
ImageIcon iconUp = new ImageIcon("/Arrows/upper-arrow.png");
buttonUp.setIcon(iconUp);
buttonUp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonMoveActionPerformed(buttonUp, e);
}
});
buttonDown.setBounds(804, 409, 30, 30);
mainPanel.add(buttonDown);
ImageIcon iconDown = new ImageIcon("/Arrows/down-arrow.png");
buttonDown.setIcon(iconDown);
buttonDown.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonMoveActionPerformed(buttonDown, e);
}
});
buttonLeft.setBounds(768, 372, 30, 30);
mainPanel.add(buttonLeft);
ImageIcon iconLeft = new ImageIcon("/Arrows/left-arrow.png");
buttonLeft.setIcon(iconLeft);
buttonLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonMoveActionPerformed(buttonLeft, e);
}
});
buttonRight.setBounds(840, 372, 30, 30);
mainPanel.add(buttonRight);
ImageIcon iconRight = new ImageIcon("/Arrows/right-arrow.png");
buttonRight.setIcon(iconRight);
buttonRight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonMoveActionPerformed(buttonRight, e);
}
});
buttonUp.setName("buttonUp");
buttonDown.setName("buttonDown");
buttonLeft.setName("buttonLeft");
buttonRight.setName("buttonRight");
setPreferredSize(new Dimension(882, 453));
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
}
protected void buttonCreateActionPerformed(ActionEvent e) {
int wheelCount;
try {
wheelCount = Integer.parseInt(wheelsTextField.getText());
} catch (NumberFormatException ex) {
wheelCount = 0;
}
if (wheelCount > 0) {
Random random = new Random();
Color color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
Color dopColor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
Color selectedColor = JColorChooser.showDialog(null, "Выберите цвет", color);
if (selectedColor != null) {
color = selectedColor;
}
Color selectedDopColor = JColorChooser.showDialog(null, "Выберите дополнительный цвет", dopColor);
if (selectedDopColor != null) {
dopColor = selectedDopColor;
}
drawningSPAU = new DrawningSPAUchild(wheelCount, Integer.parseInt((String) comboBoxRoll.getSelectedItem()),
random.nextInt(200) + 100,
(double) random.nextInt(2000) + 1000,
color,
dopColor,
true, true,
pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
drawningSPAU.SetPosition(random.nextInt(90) + 20, random.nextInt(90) + 20);
Draw();
}
}
protected void buttonCreateParent_Click(ActionEvent e) {
int wheelCount;
try {
wheelCount = Integer.parseInt(wheelsTextField.getText());
} catch (NumberFormatException ex) {
wheelCount = 0;
}
if (wheelCount > 0) {
Random random = new Random();
Color color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
Color selectedColor = JColorChooser.showDialog(null, "Выберите цвет", color);
if (selectedColor != null) {
color = selectedColor;
}
drawningSPAU = new DrawningSPAU(wheelCount, Integer.parseInt((String) comboBoxRoll.getSelectedItem()),
random.nextInt(200) + 100,
(double) random.nextInt(2000) + 1000,
color,
pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
drawningSPAU.SetPosition(random.nextInt(90) + 20, random.nextInt(90) + 20);
Draw();
}
}
private void buttonSelectSPAU_Click(ActionEvent e) {
SelectedSPAU = drawningSPAU;
int result = JOptionPane.showConfirmDialog(null, "Добавить?", "Add SPAU", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.OK_OPTION) {
dispose();
}
}
protected void buttonStep_Click(ActionEvent e) {
if (drawningSPAU == null) {
return;
}
if (comboBoxStrategy.isEnabled()) {
int selectedIndex = comboBoxStrategy.getSelectedIndex();
switch (selectedIndex) {
case 0:
abstractStrategy = new MoveToCenter();
break;
case 1:
abstractStrategy = new MoveToBorder();
break;
default:
abstractStrategy = null;
break;
}
if (abstractStrategy == null) {
return;
}
abstractStrategy.setData(new DrawningObjectSPAU(drawningSPAU), pictureBoxSPAU.getWidth(),
pictureBoxSPAU.getHeight());
comboBoxStrategy.setEnabled(false);
}
if (abstractStrategy == null) {
return;
}
abstractStrategy.makeStep();
Draw();
if (abstractStrategy.getStatus() == Status.Finish) {
comboBoxStrategy.setEnabled(true);
abstractStrategy = null;
}
}
protected void buttonMoveActionPerformed(Object sender, ActionEvent e) {
if (drawningSPAU == null) {
return;
}
String name = (sender instanceof JButton) ? ((JButton) sender).getName() : "";
switch (name) {
case "buttonUp":
drawningSPAU.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
drawningSPAU.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
drawningSPAU.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
drawningSPAU.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
}

View File

@ -1,124 +0,0 @@
package SelfPropelledArtilleryUnit;
import javax.swing.*;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
import SelfPropelledArtilleryUnit.Generics.SPAUGenericCollection;
import SelfPropelledArtilleryUnit.MovementStrategy.DrawningObjectSPAU;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class FormSPAUCollection extends JFrame {
private JPanel contentPane;
private JLabel pictureBoxCollection;
private JFormattedTextField maskedTextBoxNumber;
private JButton ButtonAddSPAU;
private JButton ButtonRemoveSPAU;
private JButton ButtonRefreshCollection;
private final int countPlaces = 12;
private final SPAUGenericCollection<DrawningSPAU, DrawningObjectSPAU> _SPAUs;
public FormSPAUCollection() {
initComponents();
_SPAUs = new SPAUGenericCollection<>(pictureBoxCollection.getWidth(), pictureBoxCollection.getHeight());
}
private void initComponents() {
contentPane = new JPanel();
pictureBoxCollection = new JLabel();
maskedTextBoxNumber = new JFormattedTextField();
ButtonAddSPAU = new JButton();
ButtonRemoveSPAU = new JButton();
ButtonRefreshCollection = new JButton();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 899, 456);
contentPane.setLayout(null);
pictureBoxCollection.setBounds(12, 12, 680, 432);
contentPane.add(pictureBoxCollection);
maskedTextBoxNumber.setBounds(729, 51, 143, 27);
contentPane.add(maskedTextBoxNumber);
ButtonAddSPAU.setBounds(748, 102, 102, 33);
ButtonAddSPAU.setText("Добавить");
ButtonAddSPAU.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ButtonAddSPAU_Click(e);
}
});
contentPane.add(ButtonAddSPAU);
ButtonRemoveSPAU.setBounds(750, 141, 100, 37);
ButtonRemoveSPAU.setText("Удалить");
ButtonRemoveSPAU.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ButtonRemoveSPAU_Click(e);
}
});
contentPane.add(ButtonRemoveSPAU);
ButtonRefreshCollection.setBounds(750, 195, 100, 35);
ButtonRefreshCollection.setText("Обновить");
ButtonRefreshCollection.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ButtonRefreshCollection_Click(e);
}
});
contentPane.add(ButtonRefreshCollection);
setContentPane(contentPane);
}
private void ButtonAddSPAU_Click(ActionEvent e) {
FormSPAU form = new FormSPAU();
form.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
int addedIndex = _SPAUs.add(form.GetSelectedSPAU());
if (addedIndex != -1 && addedIndex <= countPlaces) {
JOptionPane.showMessageDialog(null, "Объект добавлен");
ImageIcon iconSPAU = new ImageIcon(_SPAUs.showSPAUs());
pictureBoxCollection.setIcon(iconSPAU);
} else {
JOptionPane.showMessageDialog(contentPane, "Не удалось добавить объект");
}
form.dispose();
}
});
int result = JOptionPane.showConfirmDialog(null, "Add SPAU?", "Add SPAU", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
form.setSize(900, 500);
form.setVisible(true);
}
}
private void ButtonRemoveSPAU_Click(ActionEvent e) {
if (JOptionPane.showConfirmDialog(this, "Удалить объект?", "Удаление",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
int pos;
try {
pos = Integer.parseInt(maskedTextBoxNumber.getText());
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, "Не удалось удалить объект");
return;
}
if (_SPAUs.remove(pos)) {
JOptionPane.showMessageDialog(this, "Объект удален");
pictureBoxCollection.setIcon(new ImageIcon(_SPAUs.showSPAUs()));
} else {
JOptionPane.showMessageDialog(this, "Не удалось удалить объект");
}
}
}
private void ButtonRefreshCollection_Click(ActionEvent e) {
pictureBoxCollection.setIcon(new ImageIcon(_SPAUs.showSPAUs()));
}
}

View File

@ -1,60 +0,0 @@
package SelfPropelledArtilleryUnit.Generics;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
import SelfPropelledArtilleryUnit.DrawningObjects.IDrawable;
import SelfPropelledArtilleryUnit.Entities.EntitySPAU;
public class RandomParts<T extends EntitySPAU, I extends IDrawable> {
private ArrayList<T> entities;
private ArrayList<I> interfaceDops;
private int CntOfEnt;
private int MaxCntOfEnt;
private int CntOfDops;
private int MaxCntOfDops;
private int WidthOfPanel;
private int HeightOfPanel;
public RandomParts(int maxCountOfBuses, int maxCountOfDoors, int width, int height) {
MaxCntOfEnt = maxCountOfBuses;
MaxCntOfDops = maxCountOfDoors;
entities = new ArrayList<T>(MaxCntOfEnt);
interfaceDops = new ArrayList<I>(MaxCntOfDops);
CntOfEnt = 0;
CntOfDops = 0;
WidthOfPanel = width;
HeightOfPanel = height;
}
//Полиморфные методы добавления в массив
public boolean Add(T bus) {
if (bus == null || CntOfEnt >= MaxCntOfEnt) {
return false;
}
entities.add(CntOfEnt++, bus);
return true;
}
public boolean Add(I door) {
if (door == null || CntOfDops >= MaxCntOfDops) {
return false;
}
interfaceDops.add(CntOfDops++, door);
return true;
}
public DrawningSPAU CreateObject() {
if (CntOfEnt == 0 || CntOfDops == 0) {
return null;
}
Random rand = new Random();
int indexOfEntity = rand.nextInt(0, CntOfEnt);
int indexOfDop = rand.nextInt(0, CntOfDops);
T ent = entities.get(indexOfEntity);
I dop = interfaceDops.get(indexOfDop);
return new DrawningSPAU(ent, dop, WidthOfPanel, HeightOfPanel);
}
}

View File

@ -1,84 +0,0 @@
package SelfPropelledArtilleryUnit.Generics;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
import SelfPropelledArtilleryUnit.MovementStrategy.IMoveableObject;
public class SPAUGenericCollection<T extends DrawningSPAU, U extends IMoveableObject> {
private final int _pictureWidth;
private final int _pictureHeight;
private final int _placeSizeWidth = 210;
private final int _placeSizeHeight = 90;
private final SetGeneric<T> _collection;
public SPAUGenericCollection(int picWidth, int picHeight) {
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public int add(T obj) {
if (obj == null) {
return -1;
}
return _collection.insert(obj);
}
public boolean remove(int pos) {
if (pos < 0 || pos >= _collection.size()) {
return false;
}
_collection.remove(pos);
return true;
}
public U getU(int pos) {
if (pos < 0 || pos >= _collection.size()) {
return null;
}
return (U) _collection.get(pos).GetMoveableObject();
}
public BufferedImage showSPAUs() {
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = bmp.getGraphics();
drawBackground(g);
drawObjects(g);
return bmp;
}
private void drawBackground(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(0, 0, _pictureWidth, _pictureHeight); // заполняем весь прямоугольник белым цветом
g.setColor(Color.BLACK);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) {
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) {
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
private void drawObjects(Graphics g) {
int j = 0;
int stringCount = 0;
DrawningSPAU current;
for (int i = 0; i < _collection.size(); i++) {
current = _collection.get(i);
current.SetPosition(stringCount * 200, 280 - j * 100);
stringCount++;
if (stringCount >= 3) {
j++;
stringCount = 0;
}
current.DrawTransport(g);
System.out.print(i + " ");
}
}
}

View File

@ -1,37 +0,0 @@
package SelfPropelledArtilleryUnit.Generics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
import SelfPropelledArtilleryUnit.MovementStrategy.DrawningObjectSPAU;
public class SPAUGenericStorage {
private final Map<String, SPAUGenericCollection<DrawningSPAU, DrawningObjectSPAU>> SPAUStorages;
private final int pictureWidth;
private final int pictureHeight;
public SPAUGenericStorage(int pictureWidth, int pictureHeight) {
this.SPAUStorages = new HashMap<>();
this.pictureWidth = pictureWidth;
this.pictureHeight = pictureHeight;
}
public List<String> getKeys() {
return new ArrayList<>(SPAUStorages.keySet());
}
public void addSet(String name) {
SPAUStorages.put(name, new SPAUGenericCollection<>(pictureWidth, pictureHeight));
}
public void delSet(String name) {
SPAUStorages.remove(name);
}
public SPAUGenericCollection<DrawningSPAU, DrawningObjectSPAU> get(String ind) {
return SPAUStorages.get(ind);
}
}

View File

@ -1,63 +0,0 @@
package SelfPropelledArtilleryUnit.Generics;
public class SetGeneric<T> {
private final T[] places;
public int count;
public int size = 0;
public SetGeneric(int count) {
this.count = count;
places = (T[]) new Object[count];
}
public int insert(T spau) {
return insert(spau, 0);
}
public int size(){
return size;
}
public int insert(T spau, int position) {
if (position < 0 || spau == null) {
return -1;
}
if (position >= count) {
return -1;
}
int positionNull = -1;
for (int i = position; i < count; i++) {
if (places[i] == null) {
positionNull = i;
break;
}
}
if (positionNull == -1 && places[count - 1] != null) {
return -1;
} else if (positionNull == -1) {
positionNull = count - 1;
}
for (int i = positionNull; i > position; i--) {
places[i] = places[i - 1];
}
places[position] = spau;
size++;
return position;
}
public boolean remove(int position) {
if (position < 0 || position >= count)
return false;
places[position] = null;
size--;
return true;
}
public T get(int position) {
if (position < 0 || position >= count)
return null;
return places[position];
}
}

View File

@ -1,153 +0,0 @@
package SelfPropelledArtilleryUnit.MovementStrategy;
import SelfPropelledArtilleryUnit.DirectionType;
/**
* Класс-стратегия перемещения объекта
*/
public abstract class AbstractStrategy
{
/**
* Перемещаемый объект
*/
private IMoveableObject moveableObject;
/**
* Статус перемещения
*/
private Status state = Status.NotInit;
/**
* Ширина поля
*/
private int fieldWidth;
/**
* Высота поля
*/
private int fieldHeight;
/**
* Статус перемещения
*/
public Status getStatus() { return state; }
/**
* Получить ширину поля
*/
protected int getFieldWidth() { return fieldWidth; }
/**
* Получить высоту поля
*/
protected int getFieldHeight() { return fieldHeight; }
/**
* Установка данных
* @param moveableObject Перемещаемый объект
* @param width Ширина поля
* @param height Высота поля
*/
public void setData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
{
state = Status.NotInit;
return;
}
state = Status.InProgress;
this.moveableObject = moveableObject;
this.fieldWidth = width;
this.fieldHeight = height;
}
/**
* Шаг перемещения
*/
public void makeStep()
{
if (state != Status.InProgress)
{
return;
}
if (isTargetDestination())
{
state = Status.Finish;
return;
}
moveToTarget();
}
/**
* Перемещение влево
* @return Результат перемещения (true - удалось переместиться, false - неудача)
*/
protected boolean moveLeft() { return moveTo(DirectionType.Left); }
/**
* Перемещение вправо
* @return Результат перемещения (true - удалось переместиться, false - неудача)
*/
protected boolean moveRight() { return moveTo(DirectionType.Right); }
/**
* Перемещение вверх
* @return Результат перемещения (true - удалось переместиться, false - неудача)
*/
protected boolean moveUp() { return moveTo(DirectionType.Up); }
/**
* Перемещение вниз
* @return Результат перемещения (true - удалось переместиться, false - неудача)
*/
protected boolean moveDown() { return moveTo(DirectionType.Down); }
/**
* Параметры объекта
* @return Объект ObjectParameters
*/
protected ObjectParameters getObjectParameters() { return moveableObject != null ? moveableObject.getObjectPosition() : null; }
/**
* Шаг объекта
* @return Шаг объекта
*/
protected Integer getStep()
{
if (state != Status.InProgress)
{
return null;
}
return moveableObject != null ? moveableObject.getStep() : null;
}
/**
* Перемещение к цели
*/
protected abstract void moveToTarget();
/**
* Достигнута ли цель
* @return true если цель достигнута
*/
protected abstract boolean isTargetDestination();
/**
* Попытка перемещения в требуемом направлении
* @param directionType Направление
* @return Результат попытки (true - удалось переместиться, false - неудача)
*/
private boolean moveTo(DirectionType directionType)
{
if (state != Status.InProgress)
{
return false;
}
if (moveableObject != null && moveableObject.checkCanMove(directionType))
{
moveableObject.moveObject(directionType);
return true;
}
return false;
}
}

View File

@ -1,47 +0,0 @@
package SelfPropelledArtilleryUnit.MovementStrategy;
import SelfPropelledArtilleryUnit.DirectionType;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
/**
* Класс-стратегия перемещения объекта, реализация интерфейса IMoveableObject
* для работы с объектом DrawningCar (паттерн Adapter)
*/
public class DrawningObjectSPAU implements IMoveableObject {
private final DrawningSPAU drawningCar;
public DrawningObjectSPAU(DrawningSPAU drawningCar) {
this.drawningCar = drawningCar;
}
@Override
public ObjectParameters getObjectPosition() {
if (drawningCar == null || drawningCar.getEntitySPAU() == null) {
return null;
}
return new ObjectParameters(drawningCar.getPosX(),
drawningCar.getPosY(),
drawningCar.getWidth(),
drawningCar.getHeight());
}
@Override
public int getStep() {
return drawningCar != null && drawningCar.getEntitySPAU() != null
? (int) drawningCar.getEntitySPAU().getStep()
: 0;
}
@Override
public boolean checkCanMove(DirectionType direction) {
return drawningCar != null && drawningCar.CanMove(direction);
}
@Override
public void moveObject(DirectionType direction) {
if (drawningCar != null) {
drawningCar.MoveTransport(direction);
}
}
}

View File

@ -1,30 +0,0 @@
package SelfPropelledArtilleryUnit.MovementStrategy;
import SelfPropelledArtilleryUnit.DirectionType;
public interface IMoveableObject {
/**
* Получение координаты X объекта
* @return координаты объекта
*/
ObjectParameters getObjectPosition();
/**
* Получение шага объекта
* @return шаг объекта
*/
int getStep();
/**
* Проверка, можно ли переместиться по нужному направлению
* @param direction направление
* @return true, если можно переместиться, иначе false
*/
boolean checkCanMove(DirectionType direction);
/**
* Изменение направления перемещения объекта
* @param direction направление
*/
void moveObject(DirectionType direction);
}

View File

@ -1,40 +0,0 @@
package SelfPropelledArtilleryUnit.MovementStrategy;
public class MoveToBorder extends AbstractStrategy {
@Override
protected boolean isTargetDestination() {
ObjectParameters objParams = getObjectParameters();
if (objParams == null) {
return false;
}
return objParams.getRightBorder() <= getFieldWidth() &&
objParams.getRightBorder() + getStep() >= getFieldWidth() &&
objParams.getDownBorder() <= getFieldHeight() &&
objParams.getDownBorder() + getStep() >= getFieldHeight();
}
@Override
protected void moveToTarget() {
ObjectParameters objParams = getObjectParameters();
if (objParams == null) {
return;
}
double diffX = objParams.getRightBorder() - getFieldWidth();
if (Math.abs(diffX) > getStep()) {
if (diffX > 0) {
moveLeft();
} else {
moveRight();
}
}
double diffY = objParams.getDownBorder() - getFieldHeight();
if (Math.abs(diffY) > getStep()) {
if (diffY > 0) {
moveUp();
} else {
moveDown();
}
}
}
}

View File

@ -1,41 +0,0 @@
package SelfPropelledArtilleryUnit.MovementStrategy;
public class MoveToCenter extends AbstractStrategy {
@Override
protected boolean isTargetDestination() {
ObjectParameters objParams = getObjectParameters();
if (objParams == null) {
return false;
}
return objParams.getObjectMiddleHorizontal() <= getFieldWidth() / 2 &&
objParams.getObjectMiddleHorizontal() + getStep() >= getFieldWidth() / 2 &&
objParams.getObjectMiddleVertical() <= getFieldHeight() / 2 &&
objParams.getObjectMiddleVertical() + getStep() >= getFieldHeight() / 2;
}
@Override
protected void moveToTarget() {
ObjectParameters objParams = getObjectParameters();
if (objParams == null) {
return;
}
double diffX = objParams.getObjectMiddleHorizontal() - getFieldWidth() / 2;
if (Math.abs(diffX) > getStep()) {
if (diffX > 0) {
moveLeft();
} else {
moveRight();
}
}
double diffY = objParams.getObjectMiddleVertical() - getFieldHeight() / 2;
if (Math.abs(diffY) > getStep()) {
if (diffY > 0) {
moveUp();
} else {
moveDown();
}
}
}
}

View File

@ -1,70 +0,0 @@
package SelfPropelledArtilleryUnit.MovementStrategy;
public class ObjectParameters {
private final int x;
private final int y;
private final int width;
private final int height;
/**
* Левая граница
* @return координата X
*/
public int getLeftBorder() {
return x;
}
/**
* Верхняя граница
* @return координата Y
*/
public int getTopBorder() {
return y;
}
/**
* Правая граница
* @return координата X + ширина
*/
public int getRightBorder() {
return x + width;
}
/**
* Нижняя граница
* @return координата Y + высота
*/
public int getDownBorder() {
return y + height;
}
/**
* Середина объекта
* @return координата X + ширина / 2
*/
public int getObjectMiddleHorizontal() {
return x + width / 2;
}
/**
* Середина объекта
* @return координата Y + высота / 2
*/
public int getObjectMiddleVertical() {
return y + height / 2;
}
/**
* Конструктор
* @param x координата X
* @param y координата Y
* @param width ширина
* @param height высота
*/
public ObjectParameters(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}

View File

@ -1,7 +0,0 @@
package SelfPropelledArtilleryUnit.MovementStrategy;
public enum Status {
NotInit,
InProgress,
Finish
}

View File

@ -1,28 +0,0 @@
package SelfPropelledArtilleryUnit;
public enum NumbeRollers {
Min(4),
Mid(5),
Max(6);
private final int NumbeRollersCode;
private NumbeRollers(int NumbeRollersCode) {
this.NumbeRollersCode = NumbeRollersCode;
}
public int getNumbeRollersCode() {
return this.NumbeRollersCode;
}
public static NumbeRollers fromNumberToEnum(int number) {
try{
for (NumbeRollers numbeRoller : NumbeRollers.values()) {
if (numbeRoller.getNumbeRollersCode() == number) {
return numbeRoller;
}
}
}catch(NumberFormatException e){
}
return Min;
}
}

View File

@ -1,12 +0,0 @@
package SelfPropelledArtilleryUnit;
import javax.swing.*;
public class SelfPropelledArtilleryUnit {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
FormSPAUCollection form = new FormSPAUCollection();
form.setSize(900, 500);
form.setVisible(true);
});
}
}