lab2 DONE!

This commit is contained in:
Галина Федоренко 2023-11-05 21:56:49 +04:00
parent bf32a6b99a
commit 078b5ffac5
14 changed files with 56 additions and 70 deletions

View File

@ -1,10 +1,6 @@
package org.example;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public class DrawingHydroplane extends DrawingPlane{
@ -40,7 +36,15 @@ public class DrawingHydroplane extends DrawingPlane{
3
);
//windowDrawing.Draw(_startPosX, _startPosY, _EntityHydroplane.AdditionalColor, g);
g.fillRect(_startPosX + 65, _startPosY + 55, 5, 15);
g.fillRect(_startPosX + 125, _startPosY + 55, 5, 15);
g.drawLine(_startPosX + 65, _startPosY + 55, _startPosX + 65, _startPosY + 70);
g.drawLine(_startPosX + 70, _startPosY + 55, _startPosX + 70, _startPosY + 70);
g.drawLine(_startPosX + 125, _startPosY + 55, _startPosX + 125, _startPosY + 70);
g.drawLine(_startPosX + 130, _startPosY + 55, _startPosX + 130, _startPosY + 70);
windowDrawing.Draw(_startPosX, _startPosY, ((EntityHydroplane)_EntityPlane).AdditionalColor, g);
if (((EntityHydroplane)_EntityPlane).Bobber) {
g.fillPolygon(

View File

@ -2,13 +2,10 @@ package org.example;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public class DrawingPlane{
//protected IWheelDrawing wheelDrawing;
protected IWindowDrawing windowDrawing;
public EntityPlane _EntityPlane;
@ -20,9 +17,9 @@ public class DrawingPlane{
protected int _startPosY;
protected int _planeWidth = 190;
protected int _planeWidth = 175;
protected int _planeHeight = 80;
protected int _planeHeight = 90;
public DrawingPlane(int speed, double weight, Color bodyColor, int _numWindow, int width, int height)
{
@ -31,24 +28,24 @@ public class DrawingPlane{
if (_pictureHeight < _planeHeight || _pictureWidth < _planeWidth)
return;
_EntityPlane = new EntityPlane(speed, weight, bodyColor, _numWindow);
/*
Random random = new Random();
switch(random.nextInt(0, 3)){
case 0:
wheelDrawing = new WheelDrawingSimple();
windowDrawing = new WindowDrawing();
break;
case 1:
wheelDrawing = new WheelDrawingBalls();
windowDrawing = new WindowDrawingRect();
break;
case 2:
wheelDrawing = new WheelDrawingDavidStar();
windowDrawing = new WindowDrawingTringle();
break;
default:
wheelDrawing = new WheelDrawingSimple();
windowDrawing = new WindowDrawing();
break;
}
wheelDrawing.setNumWheel(_numWheel);
*/
windowDrawing.setNumWindow(_numWindow);
}
public void SetPosition(int x, int y)
@ -123,9 +120,6 @@ public class DrawingPlane{
new int[]{ _startPosY, _startPosY + 55, _startPosY + 55, _startPosY + 40, _startPosY + 40, _startPosY + 25, _startPosY + 25 },
7);
g.fillRect(_startPosX + 65, _startPosY + 55, 5, 15);
g.fillRect(_startPosX + 125, _startPosY + 55, 5, 15);
g.setColor(Color.black);
g.drawRect(_startPosX + 5, _startPosY + 25, 125, 30);
@ -136,12 +130,7 @@ public class DrawingPlane{
g.drawOval(_startPosX + 35, _startPosY + 43, 80, 7);
g.drawLine(_startPosX + 65, _startPosY + 55, _startPosX + 65, _startPosY + 70);
g.drawLine(_startPosX + 70, _startPosY + 55, _startPosX + 70, _startPosY + 70);
g.drawLine(_startPosX + 125, _startPosY + 55, _startPosX + 125, _startPosY + 70);
g.drawLine(_startPosX + 130, _startPosY + 55, _startPosX + 130, _startPosY + 70);
//windowDrawing.Draw(_startPosX, _startPosY, _EntityHydroplane.AdditionalColor, g);
windowDrawing.Draw(_startPosX, _startPosY, Color.white, g);
}
}

View File

@ -1,11 +1,14 @@
package org.example;
public class DrawningObjectPlane implements IMoveableObject {
private DrawingPlane _drawingPlane = null;
public DrawningObjectPlane(DrawingPlane drawingPlane)
{
_drawingPlane = drawingPlane;
}
public ObjectParameters GetObjectPosition(){
if (_drawingPlane == null || _drawingPlane._EntityPlane ==
null)
@ -16,7 +19,9 @@ public class DrawningObjectPlane implements IMoveableObject {
_drawingPlane.GetPosY(), _drawingPlane.GetWidth(), _drawingPlane.GetHeight());
}
public int GetStep(){ return (int)_drawingPlane._EntityPlane.Step; }
public boolean CheckCanMove(Direction direction) { return _drawingPlane.CanMove(direction);}
public void MoveObject(Direction direction) { _drawingPlane.MoveTransport(direction); }
}

View File

@ -1,10 +1,6 @@
package org.example;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public class EntityHydroplane extends EntityPlane{

View File

@ -1,10 +1,6 @@
package org.example;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public class EntityPlane{

View File

@ -3,10 +3,10 @@ package org.example;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public class FormHydroplane{
private DrawingPlane _drawingPlane;
private AbstractStrategy abstractStrategy;
Canvas canv;
@ -55,13 +55,12 @@ public class FormHydroplane{
buttonCreatePlane.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e){
System.out.println(e.getActionCommand());
Random random = new Random();
_drawingPlane = new DrawingPlane(
random.nextInt(100, 300),
random.nextInt(1000, 3000),
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
random.nextInt(2, 5),
random.nextInt(1, 4) * 10,
pictureBoxWidth,
pictureBoxHeight);
_drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
@ -73,7 +72,6 @@ public class FormHydroplane{
buttonCreateHydroplane.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e){
System.out.println(e.getActionCommand());
Random random = new Random();
_drawingPlane = new DrawingHydroplane(
random.nextInt(100, 300),
@ -82,7 +80,7 @@ public class FormHydroplane{
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
random.nextInt(0, 2) == 1,
random.nextInt(0, 2) == 1,
random.nextInt(2, 5),
random.nextInt(1, 4) * 10,
pictureBoxWidth,
pictureBoxHeight);
_drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
@ -136,7 +134,6 @@ public class FormHydroplane{
ActionListener actioListener = new ActionListener() {
public void actionPerformed(ActionEvent e){
System.out.println(((JButton)(e.getSource())).getName());
if (_drawingPlane == null)
{
return;
@ -169,8 +166,8 @@ public class FormHydroplane{
w.setLayout(null);
canv = new Canvas();
canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight);
buttonCreatePlane.setBounds(2, 540, 100, 20);
buttonCreateHydroplane.setBounds(105, 540, 150, 20);
buttonCreatePlane.setBounds(2, 540, 150, 20);
buttonCreateHydroplane.setBounds(160, 540, 200, 20);
up.setBounds(900, 480, 40, 40);
down.setBounds(900, 520, 40, 40);
left.setBounds(860, 520, 40, 40);
@ -186,13 +183,13 @@ public class FormHydroplane{
w.add(right);
w.add(comboBoxStrategy);
w.add(buttonStrategysStep);
w.setVisible(true);
}
}
class Canvas extends JComponent{
public DrawingPlane _drawingPlane;
public Canvas(){
}
public Canvas(){}
public void paintComponent (Graphics g){
if (_drawingPlane == null){
return;

View File

@ -9,5 +9,6 @@ public interface IMoveableObject {
boolean CheckCanMove(Direction direction);
void MoveObject(Direction direction);
}

View File

@ -1,10 +1,6 @@
package org.example;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public interface IWindowDrawing{

View File

@ -1,6 +1,7 @@
package org.example;
public class MoveToBorder extends AbstractStrategy{
protected boolean IsTargetDestinaion()
{
var objParams = GetObjectParameters();
@ -13,6 +14,7 @@ public class MoveToBorder extends AbstractStrategy{
objParams.DownBorder() <= FieldHeight &&
objParams.DownBorder() + GetStep() >= FieldHeight;
}
protected void MoveToTarget()
{
var objParams = GetObjectParameters();

View File

@ -1,6 +1,7 @@
package org.example;
public class MoveToCenter extends AbstractStrategy {
protected boolean IsTargetDestinaion()
{
var objParams = GetObjectParameters();
@ -13,6 +14,7 @@ public class MoveToCenter extends AbstractStrategy {
&&
Math.abs(objParams.ObjectMiddleVertical() - FieldHeight / 2) <= GetStep();
}
protected void MoveToTarget()
{
var objParams = GetObjectParameters();

View File

@ -1,6 +1,7 @@
package org.example;
public class ObjectParameters {
private int _x;
private int _y;
private int _width;

View File

@ -3,6 +3,7 @@ package org.example;
import java.awt.*;
public class WindowDrawing implements IWindowDrawing{
private NumWindow numWindow;
public NumWindow getNumWindow() {
@ -32,26 +33,26 @@ public class WindowDrawing implements IWindowDrawing{
switch (numWindow) {
case tenWindows -> {
for (int i = 0; i < 10; i++) {
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4);
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
}
}
case twentyWindows -> {
for (int i = 0; i < 10; i++) {
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4);
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
}
for (int i = 0; i < 10; i++) {
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4);
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28 + 6, 4, 4);
}
}
case thirtyWindows -> {
for (int i = 0; i < 10; i++) {
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4);
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
}
for (int i = 0; i < 10; i++) {
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4);
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28 + 5, 4, 4);
}
for (int i = 0; i < 10; i++) {
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 8, 4, 4);
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28 + 10, 4, 4);
}
}
}

View File

@ -3,6 +3,7 @@ package org.example;
import java.awt.*;
public class WindowDrawingRect implements IWindowDrawing{
private NumWindow numWindow;
public NumWindow getNumWindow() {
@ -32,26 +33,26 @@ public class WindowDrawingRect implements IWindowDrawing{
switch (numWindow) {
case tenWindows -> {
for (int i = 0; i < 10; i++) {
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4);
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
}
}
case twentyWindows -> {
for (int i = 0; i < 10; i++) {
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4);
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
}
for (int i = 0; i < 10; i++) {
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4);
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28 + 5, 4, 4);
}
}
case thirtyWindows -> {
for (int i = 0; i < 10; i++) {
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4);
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
}
for (int i = 0; i < 10; i++) {
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4);
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28 + 5, 4, 4);
}
for (int i = 0; i < 10; i++) {
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30 + 8, 4, 4);
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28 + 10, 4, 4);
}
}
}

View File

@ -3,6 +3,7 @@ package org.example;
import java.awt.*;
public class WindowDrawingTringle implements IWindowDrawing{
private NumWindow numWindow;
public NumWindow getNumWindow() {
@ -32,7 +33,6 @@ public class WindowDrawingTringle implements IWindowDrawing{
switch (numWindow) {
case tenWindows -> {
for (int i = 0; i < 10; i++) {
//g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4);
g.fillPolygon(
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
new int[]{ _startPosY + 30, _startPosY + 30 + 4, _startPosY + 30 },
@ -41,40 +41,35 @@ public class WindowDrawingTringle implements IWindowDrawing{
}
case twentyWindows -> {
for (int i = 0; i < 10; i++) {
//g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4);
g.fillPolygon(
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
new int[]{ _startPosY + 30, _startPosY + 30 + 4, _startPosY + 30 },
3);
}
for (int i = 0; i < 10; i++) {
//g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4);
g.fillPolygon(
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
new int[]{ _startPosY + 30 + 4, _startPosY + 30 + 4 + 4, _startPosY + 30 + 4 },
new int[]{ _startPosY + 30 + 5, _startPosY + 30 + 4 + 5, _startPosY + 30 + 5 },
3);
}
}
case thirtyWindows -> {
for (int i = 0; i < 10; i++) {
//g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4);
g.fillPolygon(
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
new int[]{ _startPosY + 30, _startPosY + 30 + 4, _startPosY + 30 },
3);
}
for (int i = 0; i < 10; i++) {
//g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4);
g.fillPolygon(
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
new int[]{ _startPosY + 30 + 4, _startPosY + 30 + 4 + 4, _startPosY + 30 + 4 },
new int[]{ _startPosY + 30 + 5, _startPosY + 30 + 4 + 5, _startPosY + 30 + 5 },
3);
}
for (int i = 0; i < 10; i++) {
//g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 8, 4, 4);
g.fillPolygon(
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
new int[]{ _startPosY + 30 + 8, _startPosY + 30 + 4 + 8, _startPosY + 30 + 8 },
new int[]{ _startPosY + 30 + 10, _startPosY + 30 + 4 + 10, _startPosY + 30 + 10 },
3);
}
}