This commit is contained in:
Alenka 2023-12-09 15:09:27 +04:00
parent 2577e0d879
commit b953e9735c
9 changed files with 37 additions and 47 deletions

View File

@ -34,7 +34,14 @@ public abstract class AbstractStrategy {
protected boolean MoveRight(){return MoveTo(Direction.Right);}
protected boolean MoveUp(){return MoveTo(Direction.Up);}
protected boolean MoveDown(){return MoveTo(Direction.Down);}
protected ObjectParameters GetObjectParameters(){ return _moveableObject.GetObjectPosition();}
protected ObjectParameters GetObjectParameters(){
if (_moveableObject != null) {
return _moveableObject.GetObjectPosition();
}
else {
return null;
}
}
protected int GetStep()
{
if (_state != Status.InProgress)

View File

@ -7,28 +7,21 @@ public class DrawingAdvancedCruiser extends DrawingCruiser{
EntityCruiser = new EntityAdvancedCruiser(speed, weight, bodyColor, additionalColor, helicopterPad, coating);
}
}
public DrawingAdvancedCruiser(EntityAdvancedCruiser entityAdvancedCruiser, IDop wheels)
{
super(entityAdvancedCruiser, wheels);
{
EntityCruiser = entityAdvancedCruiser;
this.wheels = wheels;
}
}
public EntityAdvancedCruiser getentityAdvancedCruiser(){
return EntityCruiser;
}
@Override
public void DrawTransport(Graphics g)
{
EntityAdvancedCruiser advancedCruiser;
if (EntityCruiser == null )
if (!(EntityCruiser instanceof EntityAdvancedCruiser)) {
return;
}
super.DrawTransport(g);
EntityAdvancedCruiser advancedCruiser = (EntityAdvancedCruiser) EntityCruiser;
if (advancedCruiser == null )
{
return;
}
Color addBrush = EntityCruiser.AdditionalColor;
Color brush = EntityCruiser.BodyColor;
super.DrawTransport(g);
if (EntityCruiser.HelicopterPad)
Color addBrush = advancedCruiser.AdditionalColor;
Color brush = advancedCruiser.BodyColor;
if (advancedCruiser.HelicopterPad)
{
g.setColor(addBrush);
g.drawRect(_startPosX + 35,
@ -36,7 +29,7 @@ public class DrawingAdvancedCruiser extends DrawingCruiser{
g.drawRect(_startPosX + 50,
_startPosY + 19, 30, 25);
}
if (EntityCruiser.Coating)
if (advancedCruiser.Coating)
{
g.drawOval(_startPosX + 70,
_startPosY + 29, 20, 20);

View File

@ -13,8 +13,6 @@ public class DrawingCruiser {
return _startPosX;
}
;
public int GetPosY() {
return _startPosY;
}
@ -23,8 +21,6 @@ public class DrawingCruiser {
return _cruiserWidth;
}
;
public int GetHeight() {
return _cruiserHeight;
}
@ -55,7 +51,6 @@ public class DrawingCruiser {
_cruiserHeight = cruiserHeight;
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
}
public DrawingCruiser(EntityCruiser entityCruiser, IDop wheels) {
EntityCruiser = entityCruiser;
this.wheels = wheels;
@ -64,36 +59,43 @@ public class DrawingCruiser {
_cruiserWidth = 110;
_cruiserHeight = 60;
}
public void SetPosition(int x, int y) {
if (x < 0 || x >= _pictureWidth || y < 0 || y >= _pictureHeight) {
_startPosX = 0;
_startPosY = 0;
if (x < 0 || x + _cruiserWidth > _pictureWidth) {
x = Math.max(0, _pictureWidth - _cruiserWidth);
}
if (y < 0 || y + _cruiserHeight > _pictureHeight) {
y = Math.max(0, _pictureHeight - _cruiserHeight);
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(Direction direction) {
if (!CanMove(direction) || EntityCruiser == null) {
return;
}
switch (direction) {
case Left:
_startPosX -= (int) EntityCruiser.Step();
if (_startPosX - EntityCruiser.Step() >= 0) {
_startPosX -= (int) EntityCruiser.Step();
}
break;
case Up:
_startPosY -= (int) EntityCruiser.Step();
if (_startPosY - EntityCruiser.Step() >= 0) {
_startPosY -= (int) EntityCruiser.Step();
}
break;
case Right:
_startPosX += (int) EntityCruiser.Step();
if (_startPosX + EntityCruiser.Step() + _cruiserWidth <= _pictureWidth) {
_startPosX += (int) EntityCruiser.Step();
}
break;
case Down:
_startPosY += (int) EntityCruiser.Step();
if (_startPosY + EntityCruiser.Step() + _cruiserHeight <= _pictureHeight) {
_startPosY += (int) EntityCruiser.Step();
}
break;
}
}
public boolean CanMove(Direction direction) {
if (EntityCruiser == null) {
return false;
@ -111,7 +113,6 @@ public class DrawingCruiser {
return false;
}
}
public void DrawTransport(Graphics g) {
if (EntityCruiser == null) {
return;

View File

@ -10,6 +10,5 @@ public class EntityAdvancedCruiser extends EntityCruiser{
AdditionalColor = additionalColor;
HelicopterPad = helicopterPad;
Coating = coating;
}
}

View File

@ -19,11 +19,6 @@ public class GameFrame extends JFrame {
this.setVisible(true);
}
private boolean intToBoolean(int input) {
return input != 0;
}
public class GamePanel extends JPanel {
static final int SCREEN_W = 700;
static final int SCREEN_H = 500;

View File

@ -1,7 +1,5 @@
import java.awt.*;
public interface IDop {
public void setNumOfWheels(String num);
public void drawWheels(Graphics g, int _startPosX, int _startPosY, Color c);
}

View File

@ -20,7 +20,6 @@ public class NumberOfWheels implements IDop{
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
}
}
public void drawWheels(Graphics g, int _startPosX, int _startPosY, Color c) {
g.setColor(c);
if (numOfWheels >= 2) {
@ -32,4 +31,4 @@ public class NumberOfWheels implements IDop{
g.fillOval(_startPosX+85, _startPosY+15, 20, 15);
}
}
}
}

View File

@ -3,7 +3,6 @@ public enum NumberOfWheelsEnum {
wheel_3(3),
wheel_4(4);
public int value;
NumberOfWheelsEnum(int value) {
this.value = value;
}

View File

@ -1,5 +1,4 @@
public class ObjectParameters {
private final int _x;
private final int _y;
private final int _width;