ПИбд-23 Кислица Егор Дмитриевич Лабораторная работа №2 (усложненная) #2
@ -4,7 +4,6 @@
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/DrawningObjects" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
|
@ -6,12 +6,13 @@ import java.awt.*;
|
||||
|
||||
public class DrawningAirFighter extends DrawningAirplane {
|
||||
public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean dopwings, boolean rackets, int width, int height ){
|
||||
super(speed,weight,bodyColor,width,height);
|
||||
if(EntityAirplane!=null){
|
||||
EntityAirplane = new EntityAirFighter(speed, weight, bodyColor, additionalColor, dopwings,rackets);
|
||||
boolean dopwings, boolean rackets, int width, int height) {
|
||||
super(speed, weight, bodyColor, width, height);
|
||||
if (EntityAirplane != null) {
|
||||
EntityAirplane = new EntityAirFighter(speed, weight, bodyColor, additionalColor, dopwings, rackets);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawAirplane(Graphics2D g2d) {
|
||||
if (!(EntityAirplane instanceof EntityAirFighter)) {
|
||||
@ -19,7 +20,7 @@ public class DrawningAirFighter extends DrawningAirplane {
|
||||
}
|
||||
super.DrawAirplane(g2d);
|
||||
EntityAirFighter _airplaneAirFighter = (EntityAirFighter) EntityAirplane;
|
||||
if (EntityAirFighter.Racket()) {
|
||||
if (_airplaneAirFighter.Racket()) {
|
||||
g2d.setColor(Color.GRAY);
|
||||
g2d.fillRect(_startPosX + 70, _startPosY - 15, 10, 10);
|
||||
g2d.setColor(Color.BLACK);
|
||||
@ -65,5 +66,17 @@ public class DrawningAirFighter extends DrawningAirplane {
|
||||
g2d.drawPolygon(xPoints4ArrNoseRacket, yPoints4ArrNoseRacket, xPoints4ArrNoseRacket.length);
|
||||
|
||||
}
|
||||
if (_airplaneAirFighter.DopWing()) {
|
||||
g2d.setColor(_airplaneAirFighter.AdditionalColor());
|
||||
int[] xPointsrightdopwing = {_startPosX + 30, _startPosX + 30, _startPosX + 35, _startPosX + 45};
|
||||
int[] yPointsrightdopwing = {_startPosY + 4, _startPosY - 34, _startPosY - 34, _startPosY + 4};
|
||||
g2d.fillPolygon(xPointsrightdopwing, yPointsrightdopwing, xPointsrightdopwing.length);
|
||||
|
||||
int[] xPointsleftdopwing = {_startPosX + 30,_startPosX + 30,_startPosX+35,_startPosX+45};
|
||||
int[] yPointsleftdopwing = {_startPosY + 24,_startPosY + 59,_startPosY + 59,_startPosY + 24};
|
||||
g2d.fillPolygon(xPointsleftdopwing,yPointsleftdopwing,xPointsleftdopwing.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,8 +9,8 @@ public class DrawningAirplane {
|
||||
protected EntityAirplane EntityAirplane;
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _startPosX = 0;
|
||||
private int _startPosY = 0;
|
||||
protected int _startPosX = 0;
|
||||
protected int _startPosY = 0;
|
||||
private int _airplaneWidth = 160;
|
||||
private int _airplaneHeight = 68;
|
||||
private int _airplanekorpusHeight = 90;
|
||||
@ -28,14 +28,25 @@ public class DrawningAirplane {
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
||||
|
||||
DrawningEngines = new DrawningEngines (_startPosX,_startPosY);
|
||||
DrawningEngines = new DrawningEngines(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||
Random rand = new Random();
|
||||
int variant = rand.nextInt(0,3);
|
||||
if(variant ==0){
|
||||
DrawningEngines = new DrawningEngines(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||
} else{
|
||||
if(variant ==1){
|
||||
DrawningEngines = new DrawningEnginesQuad(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||
|
||||
}
|
||||
else if(variant==2) {
|
||||
DrawningEngines = new DrawningEnginesOval(_airplaneWidth, _airplaneHeight, _startPosX, _startPosY);
|
||||
}
|
||||
}
|
||||
DrawningEngines.ChangeEnginesNumb(rand.nextInt(1, 5));
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y){
|
||||
if(EntityAirFighter == null)
|
||||
if(EntityAirplane == null)
|
||||
return;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
@ -62,10 +73,10 @@ public class DrawningAirplane {
|
||||
can = _startPosX + EntityAirplane.Step() + _airplaneWidth< _pictureWidth;
|
||||
break;
|
||||
case Down:
|
||||
can = _startPosY + EntityAirFighter.Step() + _airplanekorpusHeight < _pictureHeight;
|
||||
can = _startPosY + EntityAirplane.Step() + _airplanekorpusHeight < _pictureHeight;
|
||||
break;
|
||||
case Up:
|
||||
can = _startPosY - EntityAirplane.Step() >= 0;
|
||||
can = _startPosY - EntityAirplane.Step() - _airplaneHeight >= 0;
|
||||
break;
|
||||
};
|
||||
return can;
|
||||
@ -83,7 +94,7 @@ public class DrawningAirplane {
|
||||
_startPosX = 0;
|
||||
break;
|
||||
case Up:
|
||||
if (_startPosY - EntityAirplane.Step() >= 0)
|
||||
if (_startPosY - EntityAirplane.Step() - _airplaneHeight >= 0)
|
||||
_startPosY -= (int)EntityAirplane.Step();
|
||||
else
|
||||
_startPosY = 0;
|
||||
@ -106,11 +117,11 @@ public class DrawningAirplane {
|
||||
}
|
||||
public void DrawAirplane(Graphics2D g2d){
|
||||
|
||||
if (EntityAirFighter == null)
|
||||
if (EntityAirplane == null)
|
||||
return;
|
||||
DrawningEngines.DrawEngines();
|
||||
DrawningEngines.DrawEngines(g2d);
|
||||
//тело самолёта
|
||||
g2d.setColor(EntityAirFighter.BodyColor());
|
||||
g2d.setColor(EntityAirplane.BodyColor());
|
||||
g2d.fillRect(_startPosX + 20,_startPosY +4,140,20);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(_startPosX + 20,_startPosY +4,140,20);
|
||||
@ -125,7 +136,7 @@ public class DrawningAirplane {
|
||||
// Правое крыло
|
||||
int[] xPointsArrRightWing = {_startPosX + 80,_startPosX+80,_startPosX+85,_startPosX + 100};
|
||||
int[] yPointsArrRightWing = { _startPosY + 4,_startPosY - 66,_startPosY - 66, _startPosY + 4 };
|
||||
g2d.setColor(EntityAirFighter.BodyColor());
|
||||
g2d.setColor(EntityAirplane.BodyColor());
|
||||
g2d.fillPolygon(xPointsArrRightWing, yPointsArrRightWing, xPointsArrRightWing.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPointsArrRightWing, yPointsArrRightWing, xPointsArrRightWing.length);
|
||||
@ -133,7 +144,7 @@ public class DrawningAirplane {
|
||||
// Левое крыло
|
||||
int[] xPointsArrLeftWing = {_startPosX + 80,_startPosX + 100,_startPosX+85,_startPosX+80};
|
||||
int[] yPointsArrLeftWing = {_startPosY + 24,_startPosY + 24,_startPosY + 94,_startPosY + 94};
|
||||
g2d.setColor(EntityAirFighter.BodyColor());
|
||||
g2d.setColor(EntityAirplane.BodyColor());
|
||||
g2d.fillPolygon(xPointsArrLeftWing, yPointsArrLeftWing, xPointsArrLeftWing.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPointsArrLeftWing, yPointsArrLeftWing, xPointsArrLeftWing.length);
|
||||
@ -141,14 +152,14 @@ public class DrawningAirplane {
|
||||
// Правое задние крыло
|
||||
int[] xPointsArrRightBackWing={_startPosX + 140,_startPosX + 160,_startPosX+160,_startPosX+140};
|
||||
int[] yPointsArrRightBackWing={ _startPosY + 4,_startPosY + 4,_startPosY - 22,_startPosY -4};
|
||||
g2d.setColor(EntityAirFighter.BodyColor());
|
||||
g2d.setColor(EntityAirplane.BodyColor());
|
||||
g2d.fillPolygon(xPointsArrRightBackWing, yPointsArrRightBackWing, xPointsArrRightBackWing.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPointsArrRightBackWing, yPointsArrRightBackWing, xPointsArrRightBackWing.length);
|
||||
// Заднее левое крыло
|
||||
int[] xPointsArrLeftBackWing= {_startPosX + 140,_startPosX + 160,_startPosX+160,_startPosX+140};
|
||||
int[] yPointsArrLeftBackWing= {_startPosY + 24,_startPosY + 24,_startPosY + 50,_startPosY + 32};
|
||||
g2d.setColor(EntityAirFighter.BodyColor());
|
||||
g2d.setColor(EntityAirplane.BodyColor());
|
||||
g2d.fillPolygon(xPointsArrLeftBackWing, yPointsArrLeftBackWing, xPointsArrLeftBackWing.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPointsArrLeftBackWing, yPointsArrLeftBackWing, xPointsArrLeftBackWing.length);
|
||||
|
@ -5,11 +5,13 @@ import src.NumberType;
|
||||
|
||||
public class DrawningEngines implements IDraw {
|
||||
|
||||
private NumberType EnginesNumb;
|
||||
private NumberType EngineNumb;
|
||||
private int Width, Height;
|
||||
private Color EngineColor;
|
||||
public int CurX, CurY;
|
||||
boolean DrawningEngines( int curX, int curY){
|
||||
|
||||
public DrawningEngines(int width, int height,int curX, int curY){
|
||||
Width = width;
|
||||
Height = height;
|
||||
CurX = curX;
|
||||
CurY = curY;
|
||||
EngineColor = Color.BLACK;
|
||||
@ -22,29 +24,28 @@ public class DrawningEngines implements IDraw {
|
||||
}
|
||||
public void ChangeEnginesNumb(int x){
|
||||
if(x <= 1)
|
||||
EnginesNumb = NumberType.Two;
|
||||
EngineNumb = NumberType.Two;
|
||||
if(x == 2)
|
||||
EnginesNumb = NumberType.Four;
|
||||
EngineNumb = NumberType.Four;
|
||||
if(x >= 3)
|
||||
EnginesNumb = NumberType.Six;
|
||||
EngineNumb = NumberType.Six;
|
||||
}
|
||||
public NumberType WheelsNumb(){
|
||||
return EnginesNumb;
|
||||
public NumberType EngineNumb(){
|
||||
return EngineNumb;
|
||||
}
|
||||
public void DrawEngines(){
|
||||
Graphics2D g2d = (Graphics2D) AirFighterPanel.getGraphics();
|
||||
public void DrawEngines(Graphics2D g2d){
|
||||
g2d.setColor(EngineColor);
|
||||
g2d.fillOval(CurX + 92,CurY - 15,25,10 );
|
||||
g2d.fillOval(CurX + 92,CurY + 34,25,10 );
|
||||
|
||||
if (EnginesNumb == NumberType.Four || EnginesNumb == NumberType.Six)
|
||||
if (EngineNumb == NumberType.Four || EngineNumb == NumberType.Six)
|
||||
{
|
||||
g2d.fillOval(CurX + 86,CurY - 40,25,10 );
|
||||
|
||||
g2d.fillOval(CurX + 86,CurY +59,25,10 );
|
||||
}
|
||||
|
||||
if (EnginesNumb == NumberType.Six)
|
||||
if (EngineNumb == NumberType.Six)
|
||||
{
|
||||
g2d.fillOval(CurX + 128,CurY -7,25,10 );
|
||||
g2d.fillOval(CurX + 128,CurY +25,25,10 );
|
||||
|
52
src/DrawningObjects/DrawningEnginesOval.java
Normal file
52
src/DrawningObjects/DrawningEnginesOval.java
Normal file
@ -0,0 +1,52 @@
|
||||
package src.DrawningObjects;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningEnginesOval implements IDraw{
|
||||
private src.NumberType EngineNumb;
|
||||
private int Width, Height;
|
||||
private Color EngineColor;
|
||||
public int CurX, CurY;
|
||||
public DrawningEnginesOval(int width, int height,int curX, int curY){
|
||||
Width = width;
|
||||
Height = height;
|
||||
CurX = curX;
|
||||
CurY = curY;
|
||||
EngineColor = Color.BLACK;
|
||||
}
|
||||
public void ChangeX(int x){
|
||||
CurX = x;
|
||||
}
|
||||
public void ChangeY(int y){
|
||||
CurY = y;
|
||||
}
|
||||
public void ChangeEnginesNumb(int x){
|
||||
if(x <= 1)
|
||||
EngineNumb = src.NumberType.Two;
|
||||
if(x == 2)
|
||||
EngineNumb = src.NumberType.Four;
|
||||
if(x >= 3)
|
||||
EngineNumb = src.NumberType.Six;
|
||||
}
|
||||
public src.NumberType EngineNumb(){
|
||||
return EngineNumb;
|
||||
}
|
||||
public void DrawEngines(Graphics2D g2d){
|
||||
g2d.setColor(EngineColor);
|
||||
g2d.drawOval(CurX + 92,CurY - 15,25,10 );
|
||||
g2d.drawOval(CurX + 92,CurY + 34,25,10 );
|
||||
|
||||
if (EngineNumb == src.NumberType.Four || EngineNumb == src.NumberType.Six)
|
||||
{
|
||||
g2d.drawOval(CurX + 86,CurY - 40,25,10 );
|
||||
|
||||
g2d.drawOval(CurX + 86,CurY +59,25,10 );
|
||||
}
|
||||
|
||||
if (EngineNumb == src.NumberType.Six)
|
||||
{
|
||||
g2d.drawOval(CurX + 128,CurY -7,25,10 );
|
||||
g2d.drawOval(CurX + 128,CurY +25,25,10 );
|
||||
}
|
||||
}
|
||||
}
|
55
src/DrawningObjects/DrawningEnginesQuad.java
Normal file
55
src/DrawningObjects/DrawningEnginesQuad.java
Normal file
@ -0,0 +1,55 @@
|
||||
package src.DrawningObjects;
|
||||
|
||||
import src.NumberType;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningEnginesQuad implements IDraw {
|
||||
private src.NumberType EngineNumb;
|
||||
private int Width, Height;
|
||||
private Color EngineColor;
|
||||
public int CurX, CurY;
|
||||
public DrawningEnginesQuad(int width, int height, int curX, int curY){
|
||||
Width = width;
|
||||
Height = height;
|
||||
CurX = curX;
|
||||
CurY = curY;
|
||||
EngineColor = Color.BLACK;
|
||||
}
|
||||
public void ChangeX(int x){
|
||||
CurX = x;
|
||||
}
|
||||
public void ChangeY(int y){
|
||||
CurY = y;
|
||||
}
|
||||
public void ChangeEnginesNumb(int x){
|
||||
if(x <= 1)
|
||||
EngineNumb = src.NumberType.Two;
|
||||
if(x == 2)
|
||||
EngineNumb = src.NumberType.Four;
|
||||
if(x >= 3)
|
||||
EngineNumb = src.NumberType.Six;
|
||||
}
|
||||
public src.NumberType EngineNumb(){
|
||||
return EngineNumb;
|
||||
}
|
||||
public void DrawEngines(Graphics2D g2d){
|
||||
g2d.setColor(EngineColor);
|
||||
g2d.fillRect(CurX + 92,CurY - 15,25,10 );
|
||||
g2d.fillRect(CurX + 92,CurY + 34,25,10 );
|
||||
|
||||
if (EngineNumb == src.NumberType.Four || EngineNumb == src.NumberType.Six)
|
||||
{
|
||||
g2d.fillRect(CurX + 86,CurY - 40,25,10 );
|
||||
|
||||
g2d.fillRect(CurX + 86,CurY +59,25,10 );
|
||||
}
|
||||
|
||||
if (EngineNumb == src.NumberType.Six)
|
||||
{
|
||||
g2d.fillRect(CurX + 128,CurY -7,25,10 );
|
||||
g2d.fillRect(CurX + 128,CurY +25,25,10 );
|
||||
}
|
||||
}
|
||||
}
|
@ -2,8 +2,7 @@ package src.DrawningObjects;
|
||||
import src.NumberType;
|
||||
import java.awt.*;
|
||||
public interface IDraw {
|
||||
public void ChangeEngineNumb(int x);
|
||||
//public NumberType EngineNumb();
|
||||
public void ChangeEnginesNumb(int x);
|
||||
public void DrawEngines(Graphics2D g2d);
|
||||
public void ChangeX(int x);
|
||||
public void ChangeY(int y);
|
||||
|
@ -3,20 +3,22 @@ import java.awt.*;
|
||||
|
||||
public class EntityAirFighter extends EntityAirplane {
|
||||
private Color BodyColor;
|
||||
private boolean Wing;
|
||||
private Color AdditionalColor;
|
||||
private boolean DopWing;
|
||||
private boolean Racket;
|
||||
public Color AdditionalColor(){return AdditionalColor;}
|
||||
public Color BodyColor(){
|
||||
return BodyColor;
|
||||
}
|
||||
public boolean Racket(){return Racket;}
|
||||
public boolean DopWing(){return Wing;}
|
||||
public void Init(int speed, double weight, Color bodyColor,
|
||||
public boolean DopWing(){return DopWing;}
|
||||
public EntityAirFighter(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean racket, boolean dopwing){
|
||||
super(speed, weight, bodyColor);
|
||||
|
||||
BodyColor = bodyColor;
|
||||
|
||||
AdditionalColor=additionalColor;
|
||||
Racket = racket;
|
||||
Wing = wing;
|
||||
DopWing= dopwing;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
package src;
|
||||
import src.DrawningObjects.DrawningAirplaneWithRadar;
|
||||
import src.DrawningObjects.DrawningAirFighter;
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
import src.MovementStrategy.*;
|
||||
import java.awt.*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package MovementStrategy;
|
||||
package src.MovementStrategy;
|
||||
import src.DirectionType;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package MovementStrategy;
|
||||
package src.MovementStrategy;
|
||||
import src.DirectionType;
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package MovementStrategy;
|
||||
package src.MovementStrategy;
|
||||
|
||||
import src.DirectionType;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package MovementStrategy;
|
||||
package src.MovementStrategy;
|
||||
|
||||
public class MoveToBorder extends AbstractStrategy {
|
||||
@Override
|
||||
|
@ -1,4 +1,4 @@
|
||||
package MovementStrategy;
|
||||
package src.MovementStrategy;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy{
|
||||
@Override
|
||||
|
@ -1,4 +1,4 @@
|
||||
package MovementStrategy;
|
||||
package src.MovementStrategy;
|
||||
|
||||
public class ObjectParameters {
|
||||
private final int _x;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package MovementStrategy;
|
||||
package src.MovementStrategy;
|
||||
|
||||
public enum Status {
|
||||
NotInit,
|
||||
|
Loading…
Reference in New Issue
Block a user