лр2 коммит 2
This commit is contained in:
parent
52f515ce73
commit
c1e50db073
@ -1,13 +1,11 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AbstractMap {
|
||||
private IDrawningObject _drawingObject = null;
|
||||
protected int[][] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
//øèðèíà è âûñîòà ÿ÷åéêè
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected final Random _random = new Random();
|
||||
@ -35,7 +33,6 @@ public abstract class AbstractMap {
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private Direction MoveObjectBack(Direction direction)
|
||||
{
|
||||
switch (direction)
|
||||
@ -51,7 +48,6 @@ public abstract class AbstractMap {
|
||||
}
|
||||
return Direction.None;
|
||||
}
|
||||
|
||||
private boolean CheckBarrier(float Left, float Right, float Top, float Bottom)
|
||||
{
|
||||
int startX = (int)(Left / _size_x);
|
||||
@ -135,12 +131,9 @@ public abstract class AbstractMap {
|
||||
}
|
||||
}
|
||||
}
|
||||
// _drawingObject.DrawingObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
|
||||
}
|
||||
|
@ -17,18 +17,18 @@ public class DrawingBoat extends JComponent {
|
||||
Boat = new EntityBoat(speed, weight, bodyColor);
|
||||
int randomPattern=random.nextInt(3);
|
||||
if (randomPattern==0)
|
||||
_paddles = new DrawingHardPaddle();
|
||||
_paddles = new DrawingPaddleTriangle();
|
||||
else if(randomPattern==1)
|
||||
_paddles = new DrawningHard2Paddle();
|
||||
_paddles = new DrawingPaddleSquare();
|
||||
else
|
||||
_paddles = new DrawingPaddle();
|
||||
_paddles.SetPaddlesCount(paddleCount);
|
||||
}
|
||||
protected DrawingBoat(int speed, float weight, Color bodyColor, int rollersAmount, int bulldozerWidth, int bulldozerHeight)
|
||||
protected DrawingBoat(int speed, float weight, Color bodyColor, int paddleCount, int boatWidth, int boatHeight)
|
||||
{
|
||||
this(speed, weight, bodyColor, rollersAmount);
|
||||
_boatWidth = bulldozerWidth;
|
||||
_boatHeight = bulldozerHeight;
|
||||
this(speed, weight, bodyColor, paddleCount);
|
||||
_boatWidth = boatWidth;
|
||||
_boatHeight = boatHeight;
|
||||
}
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
@ -89,7 +89,6 @@ public class DrawingBoat extends JComponent {
|
||||
return;
|
||||
}
|
||||
Color pen = new Color(0,0,0);
|
||||
//границы лодки
|
||||
int [] pointsX = new int[]{(int)(_startPosX),(int)(_startPosX + 50),(int)(_startPosX + 70),(int)(_startPosX + 50),(int)(_startPosX)};
|
||||
int [] pointsY = new int[]{(int)(_startPosY),(int)(_startPosY),(int)(_startPosY + 20),(int)(_startPosY + 40),(int)(_startPosY+40)};
|
||||
|
||||
|
@ -1,72 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingHardPaddle implements IDrawningObjectPaddle {
|
||||
private AdditionalDirection _paddleEnum;
|
||||
@Override
|
||||
public void SetPaddlesCount(int rollersAmount) {
|
||||
for (AdditionalDirection item: _paddleEnum.values()) {
|
||||
if (item.getCount() == rollersAmount) {
|
||||
_paddleEnum = item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color mainBrush) {
|
||||
Graphics2D g=(Graphics2D)gr;
|
||||
//öâåò
|
||||
Color br = new Color(0,0,0);
|
||||
try { br = mainBrush; }
|
||||
catch (Exception e) {
|
||||
|
||||
}
|
||||
_startPosPaddlesX +=40;
|
||||
_startPosPaddlessY +=33;
|
||||
if (_paddleEnum.getCount() >= 1) {
|
||||
|
||||
paintPaddleUgol(g, _startPosPaddlesX-3, _startPosPaddlessY+5, _startPosPaddlessY + 16+5,mainBrush,false);
|
||||
paintPaddle(g, _startPosPaddlesX, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush);
|
||||
}
|
||||
if (_paddleEnum.getCount() >= 2) {
|
||||
|
||||
paintPaddleUgol(g, _startPosPaddlesX -10-3, _startPosPaddlessY -41+5, _startPosPaddlessY -51+5,mainBrush,true);
|
||||
paintPaddle(g, _startPosPaddlesX -10, _startPosPaddlessY -41, _startPosPaddlessY -51,mainBrush);
|
||||
}
|
||||
if (_paddleEnum.getCount() >= 3) {
|
||||
paintPaddleUgol(g, _startPosPaddlesX -20-3, _startPosPaddlessY+5, _startPosPaddlessY + 16+5,mainBrush,false);
|
||||
paintPaddle(g, _startPosPaddlesX -20, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush);
|
||||
|
||||
}
|
||||
}
|
||||
protected void paintPaddleUgol(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen,boolean need){
|
||||
try { g.setPaint(pen); }
|
||||
catch (Exception e) {
|
||||
g.setPaint(Color.black);
|
||||
}
|
||||
if(need){
|
||||
g.fillPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2-10,_startPosY2},3);
|
||||
g.setPaint(Color.black);
|
||||
g.drawPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2-10,_startPosY2},3);}
|
||||
else{
|
||||
g.fillPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2+10,_startPosY2},3);
|
||||
g.setPaint(Color.black);
|
||||
g.drawPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2+10,_startPosY2},3);
|
||||
}
|
||||
/* g.fillRect(_startPosX,_startPosY1,4,17);
|
||||
g.fillOval(_startPosX-1, _startPosY2, 6, 10);
|
||||
g.setPaint(Color.black);
|
||||
g.drawRect(_startPosX,_startPosY1,4,17);
|
||||
g.drawOval(_startPosX-1, _startPosY2, 6, 10);*/
|
||||
}
|
||||
protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen){
|
||||
try { g.setPaint(pen); }
|
||||
catch (Exception e) {
|
||||
g.setPaint(Color.black);
|
||||
}
|
||||
g.fillRect(_startPosX,_startPosY1,4,17);
|
||||
g.fillOval(_startPosX-1, _startPosY2, 6, 10);
|
||||
g.setPaint(Color.black);
|
||||
g.drawRect(_startPosX,_startPosY1,4,17);
|
||||
g.drawOval(_startPosX-1, _startPosY2, 6, 10);
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class DrawingPaddle implements IDrawningObjectPaddle {
|
||||
private AdditionalDirection _paddle;
|
||||
@ -14,7 +13,6 @@ public class DrawingPaddle implements IDrawningObjectPaddle {
|
||||
@Override
|
||||
public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color pen) {
|
||||
Graphics2D g=(Graphics2D)gr;
|
||||
|
||||
_startPosPaddlesX +=40;
|
||||
_startPosPaddlessY +=33;
|
||||
if (_paddle.getCount() >= 1) {
|
||||
@ -29,9 +27,7 @@ public class DrawingPaddle implements IDrawningObjectPaddle {
|
||||
}
|
||||
protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen){
|
||||
try { g.setPaint(pen); }
|
||||
catch (Exception e) {
|
||||
g.setPaint(Color.black);
|
||||
}
|
||||
catch (Exception e) { g.setPaint(Color.black); }
|
||||
g.fillRect(_startPosX,_startPosY1,4,17);
|
||||
g.fillOval(_startPosX-1, _startPosY2, 6, 10);
|
||||
g.setPaint(Color.black);
|
||||
|
47
src/DrawingPaddleSquare.java
Normal file
47
src/DrawingPaddleSquare.java
Normal file
@ -0,0 +1,47 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingPaddleSquare implements IDrawningObjectPaddle {
|
||||
private AdditionalDirection _paddleDirect;
|
||||
|
||||
@Override
|
||||
public void SetPaddlesCount(int paddlesCount) {
|
||||
for (AdditionalDirection item : _paddleDirect.values()) {
|
||||
if (item.getCount() == paddlesCount) {
|
||||
_paddleDirect = item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color mainBrush) {
|
||||
Graphics2D g = (Graphics2D) gr;
|
||||
Color br = new Color(0, 0, 0);
|
||||
try {
|
||||
br = mainBrush;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
_startPosPaddlesX += 40;
|
||||
_startPosPaddlessY += 33;
|
||||
if (_paddleDirect.getCount() >= 1) {
|
||||
paintPaddle(g, _startPosPaddlesX, _startPosPaddlessY, _startPosPaddlessY + 16, mainBrush);
|
||||
}
|
||||
if (_paddleDirect.getCount() >= 2) {
|
||||
paintPaddle(g, _startPosPaddlesX - 10, _startPosPaddlessY - 41, _startPosPaddlessY - 51, mainBrush);
|
||||
}
|
||||
if (_paddleDirect.getCount() >= 3) {
|
||||
paintPaddle(g, _startPosPaddlesX - 20, _startPosPaddlessY, _startPosPaddlessY + 16, mainBrush);
|
||||
}
|
||||
}
|
||||
protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1, int _startPosY2, Color pen) {
|
||||
try {
|
||||
g.setPaint(pen);
|
||||
} catch (Exception e) {
|
||||
g.setPaint(Color.black);
|
||||
}
|
||||
g.fillRect(_startPosX, _startPosY1, 4, 17);
|
||||
g.fillRect(_startPosX - 5, _startPosY2, 13, 13);
|
||||
g.setPaint(Color.black);
|
||||
g.drawRect(_startPosX, _startPosY1, 4, 17);
|
||||
g.drawRect(_startPosX - 5, _startPosY2, 13, 13);
|
||||
}
|
||||
}
|
70
src/DrawingPaddleTriangle.java
Normal file
70
src/DrawingPaddleTriangle.java
Normal file
@ -0,0 +1,70 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingPaddleTriangle implements IDrawningObjectPaddle {
|
||||
private AdditionalDirection _paddleDirect;
|
||||
|
||||
@Override
|
||||
public void SetPaddlesCount(int paddlesCount) {
|
||||
for (AdditionalDirection item : _paddleDirect.values()) {
|
||||
if (item.getCount() == paddlesCount) {
|
||||
_paddleDirect = item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color mainBrush) {
|
||||
Graphics2D g = (Graphics2D) gr;
|
||||
|
||||
Color br = new Color(0, 0, 0);
|
||||
try {
|
||||
br = mainBrush;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
_startPosPaddlesX += 40;
|
||||
_startPosPaddlessY += 33;
|
||||
if (_paddleDirect.getCount() >= 1) {
|
||||
paintPaddleTriangle(g, _startPosPaddlesX - 3, _startPosPaddlessY + 5, _startPosPaddlessY + 16 + 5, mainBrush, false);
|
||||
paintPaddle(g, _startPosPaddlesX, _startPosPaddlessY, _startPosPaddlessY + 16, mainBrush);
|
||||
}
|
||||
if (_paddleDirect.getCount() >= 2) {
|
||||
paintPaddleTriangle(g, _startPosPaddlesX - 10 - 3, _startPosPaddlessY - 41 + 5, _startPosPaddlessY - 51 + 5, mainBrush, true);
|
||||
paintPaddle(g, _startPosPaddlesX - 10, _startPosPaddlessY - 41, _startPosPaddlessY - 51, mainBrush);
|
||||
}
|
||||
if (_paddleDirect.getCount() >= 3) {
|
||||
paintPaddleTriangle(g, _startPosPaddlesX - 20 - 3, _startPosPaddlessY + 5, _startPosPaddlessY + 16 + 5, mainBrush, false);
|
||||
paintPaddle(g, _startPosPaddlesX - 20, _startPosPaddlessY, _startPosPaddlessY + 16, mainBrush);
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintPaddleTriangle(Graphics2D g, int _startPosX, int _startPosY1, int _startPosY2, Color pen, boolean need) {
|
||||
try {
|
||||
g.setPaint(pen);
|
||||
} catch (Exception e) {
|
||||
g.setPaint(Color.black);
|
||||
}
|
||||
if (need) {
|
||||
g.fillPolygon(new int[]{_startPosX, _startPosX + 5, _startPosX + 10}, new int[]{_startPosY2, _startPosY2 - 10, _startPosY2}, 3);
|
||||
g.setPaint(Color.black);
|
||||
g.drawPolygon(new int[]{_startPosX, _startPosX + 5, _startPosX + 10}, new int[]{_startPosY2, _startPosY2 - 10, _startPosY2}, 3);
|
||||
} else {
|
||||
g.fillPolygon(new int[]{_startPosX, _startPosX + 5, _startPosX + 10}, new int[]{_startPosY2, _startPosY2 + 10, _startPosY2}, 3);
|
||||
g.setPaint(Color.black);
|
||||
g.drawPolygon(new int[]{_startPosX, _startPosX + 5, _startPosX + 10}, new int[]{_startPosY2, _startPosY2 + 10, _startPosY2}, 3);
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1, int _startPosY2, Color pen) {
|
||||
try {
|
||||
g.setPaint(pen);
|
||||
} catch (Exception e) {
|
||||
g.setPaint(Color.black);
|
||||
}
|
||||
g.fillRect(_startPosX, _startPosY1, 4, 17);
|
||||
g.fillOval(_startPosX - 1, _startPosY2, 6, 10);
|
||||
g.setPaint(Color.black);
|
||||
g.drawRect(_startPosX, _startPosY1, 4, 17);
|
||||
g.drawOval(_startPosX - 1, _startPosY2, 6, 10);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningHard2Paddle implements IDrawningObjectPaddle {
|
||||
private AdditionalDirection _paddleEnum;
|
||||
@Override
|
||||
public void SetPaddlesCount(int paddlesCount) {
|
||||
for (AdditionalDirection item: _paddleEnum.values()) {
|
||||
if (item.getCount() == paddlesCount) {
|
||||
_paddleEnum = item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color mainBrush) {
|
||||
Graphics2D g=(Graphics2D)gr;
|
||||
//öâåò
|
||||
Color br = new Color(0,0,0);
|
||||
try { br = mainBrush; }
|
||||
catch (Exception e) {
|
||||
|
||||
}
|
||||
_startPosPaddlesX +=40;
|
||||
_startPosPaddlessY +=33;
|
||||
if (_paddleEnum.getCount() >= 1) {
|
||||
paintPaddle(g, _startPosPaddlesX, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush);
|
||||
}
|
||||
if (_paddleEnum.getCount() >= 2) {
|
||||
paintPaddle(g, _startPosPaddlesX -10, _startPosPaddlessY -41, _startPosPaddlessY -51,mainBrush);
|
||||
}
|
||||
if (_paddleEnum.getCount() >= 3) {
|
||||
paintPaddle(g, _startPosPaddlesX -20, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush);
|
||||
|
||||
}
|
||||
}
|
||||
protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen){
|
||||
try { g.setPaint(pen); }
|
||||
catch (Exception e) {
|
||||
g.setPaint(Color.black);
|
||||
}
|
||||
g.fillRect(_startPosX,_startPosY1,4,17);
|
||||
g.fillRect(_startPosX-5, _startPosY2, 13, 13);
|
||||
g.setPaint(Color.black);
|
||||
g.drawRect(_startPosX,_startPosY1,4,17);
|
||||
g.drawRect(_startPosX-5, _startPosY2, 13, 13);
|
||||
}
|
||||
}
|
@ -1,77 +1,60 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningMotorBoat extends DrawingBoat{
|
||||
public DrawningMotorBoat(int speed, float weight, Color bodyColor, int paddleamount, Color dopColor, boolean attachment, boolean ripper)
|
||||
{
|
||||
super(speed, weight, bodyColor, paddleamount, 138, 78);
|
||||
Boat = new EntityMotorBoat(speed, weight, bodyColor, dopColor, attachment, ripper);
|
||||
public class DrawningMotorBoat extends DrawingBoat {
|
||||
public DrawningMotorBoat(int speed, float weight, Color bodyColor, int paddleCount, Color dopColor, boolean nose, boolean side) {
|
||||
super(speed, weight, bodyColor, paddleCount, 138, 78);
|
||||
Boat = new EntityMotorBoat(speed, weight, bodyColor, dopColor, nose, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics gr)
|
||||
{
|
||||
public void paintComponent(Graphics gr) {
|
||||
boolean check = Boat instanceof EntityMotorBoat;
|
||||
if (!check) {
|
||||
return;
|
||||
}
|
||||
EntityMotorBoat bulldozer = (EntityMotorBoat) Boat;
|
||||
//_startPosY+=40;
|
||||
Graphics2D g=(Graphics2D)gr;
|
||||
Color dopBrush = bulldozer.DopColor();
|
||||
EntityMotorBoat boat = (EntityMotorBoat) Boat;
|
||||
Graphics2D g = (Graphics2D) gr;
|
||||
Color dopBrush = boat.DopColor();
|
||||
|
||||
gr.setColor(dopBrush);
|
||||
g.fillOval( (int)_startPosX - 17, (int)_startPosY - 24, 14, 5);
|
||||
g.fillOval((int) _startPosX - 17, (int) _startPosY - 24, 14, 5);
|
||||
gr.setColor(Color.BLACK);
|
||||
g.drawOval((int) _startPosX - 17, (int)_startPosY - 24, 14, 5);
|
||||
g.drawOval((int) _startPosX - 17, (int) _startPosY - 24, 14, 5);
|
||||
gr.setColor(dopBrush);
|
||||
g.fillRect((int) _startPosX - 10, (int)_startPosY - 30, 10, 20);
|
||||
g.fillRect((int) _startPosX - 10, (int) _startPosY - 30, 10, 20);
|
||||
gr.setColor(Color.BLACK);
|
||||
g.drawRect( (int)_startPosX - 10, (int)_startPosY - 30, 10, 20);
|
||||
g.drawRect((int) _startPosX - 10, (int) _startPosY - 30, 10, 20);
|
||||
|
||||
int[] pointsx;
|
||||
int[] pointsy;
|
||||
|
||||
if (bulldozer.Attachment())
|
||||
{
|
||||
pointsx = new int[]{(int)(_startPosX),(int)(_startPosX),(int)(_startPosX+50),(int)(_startPosX+50)};
|
||||
pointsy = new int[]
|
||||
{
|
||||
(int)(_startPosY-50),(int)(_startPosY+10),(int)(_startPosY),(int)(_startPosY-40)
|
||||
};
|
||||
if (boat.Side()) {
|
||||
pointsx = new int[]{(int) (_startPosX), (int) (_startPosX), (int) (_startPosX + 50), (int) (_startPosX + 50)};
|
||||
pointsy = new int[]{(int) (_startPosY - 50), (int) (_startPosY + 10), (int) (_startPosY), (int) (_startPosY - 40)};
|
||||
gr.setColor(dopBrush);
|
||||
g.fillPolygon(pointsx,pointsy,4);
|
||||
g.fillPolygon(pointsx, pointsy, 4);
|
||||
gr.setColor(Color.BLACK);
|
||||
g.drawPolygon(pointsx,pointsy,4);
|
||||
g.drawPolygon(pointsx, pointsy, 4);
|
||||
}
|
||||
|
||||
/* _startPosX -= 15;
|
||||
_startPosY -= 5;*/
|
||||
if (bulldozer.Ripper())
|
||||
{
|
||||
pointsx = new int[]{(int)(_startPosX)+50,(int)(_startPosX)+80,(int)(_startPosX+50)};
|
||||
pointsy = new int[]{(int)(_startPosY-40),(int)(_startPosY-20),(int)(_startPosY)};
|
||||
if (boat.Nose()) {
|
||||
pointsx = new int[]{(int) (_startPosX) + 50, (int) (_startPosX) + 80, (int) (_startPosX + 50)};
|
||||
pointsy = new int[]{(int) (_startPosY - 40), (int) (_startPosY - 20), (int) (_startPosY)};
|
||||
gr.setColor(dopBrush);
|
||||
g.fillPolygon(pointsx,pointsy,3);
|
||||
g.fillPolygon(pointsx, pointsy, 3);
|
||||
gr.setColor(Color.BLACK);
|
||||
g.drawPolygon(pointsx,pointsy,3);
|
||||
g.drawPolygon(pointsx, pointsy, 3);
|
||||
}
|
||||
_startPosY-=40;
|
||||
/* _startPosX += 15;
|
||||
_startPosY += 5;*/
|
||||
_startPosY -= 40;
|
||||
super.paintComponent(gr);
|
||||
_startPosY+=40;
|
||||
_startPosY += 40;
|
||||
|
||||
pointsx = new int[]
|
||||
{
|
||||
(int)(_startPosX)+50,(int)(_startPosX)+57,(int)(_startPosX+50) };
|
||||
pointsy = new int[]
|
||||
{
|
||||
(int)(_startPosY-34),(int)(_startPosY-20),(int)(_startPosY-6)
|
||||
};
|
||||
pointsx = new int[]{(int) (_startPosX) + 50, (int) (_startPosX) + 57, (int) (_startPosX + 50)};
|
||||
pointsy = new int[]{(int) (_startPosY - 34), (int) (_startPosY - 20), (int) (_startPosY - 6)};
|
||||
gr.setColor(Color.CYAN);
|
||||
g.fillPolygon(pointsx,pointsy,3);
|
||||
g.fillPolygon(pointsx, pointsy, 3);
|
||||
gr.setColor(Color.BLACK);
|
||||
((Graphics2D) gr).setStroke(new BasicStroke(1));
|
||||
g.drawPolygon(pointsx,pointsy,3);
|
||||
g.drawPolygon(pointsx, pointsy, 3);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -12,22 +12,18 @@ public class DrawningObjectBoat implements IDrawningObject{
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height) {
|
||||
_boat.SetPosition(x+20, y+50, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void MoveObject(Direction direction) {
|
||||
_boat.MoveTransport(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawingObject(Graphics g) {
|
||||
_boat.paintComponent(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] GetCurrentPosition()
|
||||
{
|
||||
|
@ -3,7 +3,9 @@ import java.util.Random;
|
||||
|
||||
public class EntityBoat {
|
||||
private int speed;
|
||||
public int Speed() { return speed; }
|
||||
public int Speed() {
|
||||
return speed;
|
||||
}
|
||||
private float weight;
|
||||
public float Weight() {
|
||||
return weight;
|
||||
@ -12,10 +14,10 @@ public class EntityBoat {
|
||||
public Color BodyColor() {
|
||||
return bodyColor;
|
||||
}
|
||||
public float Step()
|
||||
{ return Speed() * 20 / Weight(); }
|
||||
public EntityBoat(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
public float Step() {
|
||||
return Speed() * 20 / Weight();
|
||||
}
|
||||
public EntityBoat(int speed, float weight, Color bodyColor) {
|
||||
Random random = new Random();
|
||||
this.speed = speed <= 0 ? random.nextInt(50, 150) : speed;
|
||||
this.weight = weight <= 0 ? random.nextInt(40, 70) : weight;
|
||||
|
@ -1,21 +1,16 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityMotorBoat extends EntityBoat{
|
||||
// Äîïîëíèòåëüíûé öâåò
|
||||
private Color dopColor;
|
||||
public Color DopColor() { return dopColor; }
|
||||
// Ïðèçíàê íàëè÷èÿ îòâàëà
|
||||
private boolean attachment;
|
||||
public boolean Attachment() { return attachment; }
|
||||
// Ïðèçíàê íàëè÷èÿ ðûõëèòåëÿ
|
||||
private boolean ripper;
|
||||
public boolean Ripper() { return ripper; }
|
||||
// Èíèöèàëèçàöèÿ ñâîéñòâ
|
||||
public EntityMotorBoat(int speed, float weight, Color bodyColor, Color dopColor, boolean attachment, boolean ripper)
|
||||
private boolean nose;
|
||||
public boolean Nose() { return nose; }
|
||||
private boolean side;
|
||||
public boolean Side() { return side; }
|
||||
public EntityMotorBoat(int speed, float weight, Color bodyColor, Color dopColor, boolean nose, boolean side)
|
||||
{
|
||||
super(speed*100, weight, bodyColor);
|
||||
this.dopColor = dopColor;
|
||||
this.attachment = attachment;
|
||||
this.ripper = ripper;
|
||||
this.nose = nose;
|
||||
this.side = side;
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,6 @@ import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Random;
|
||||
public class FormBoat extends JFrame {
|
||||
|
||||
|
||||
private JPanel mainPanel;
|
||||
private JPanel statusStrip;
|
||||
private JLabel toolStripStatusLabelSpeed;
|
||||
@ -26,8 +24,6 @@ public class FormBoat extends JFrame {
|
||||
private int pictureBoxBoatWidth;
|
||||
private int pictureBoxBoatHeight;
|
||||
ButtonGroup buttonGroupPaddlesRadBut;
|
||||
|
||||
/*
|
||||
public FormBoat() {
|
||||
super("Моторная лодка");
|
||||
buttonGroupPaddlesRadBut = new ButtonGroup();
|
||||
@ -36,7 +32,6 @@ public class FormBoat extends JFrame {
|
||||
buttonGroupPaddlesRadBut.add(radioButtonPaddle3);
|
||||
setPreferredSize(new Dimension(1000, 700));
|
||||
getContentPane().add(mainPanel);
|
||||
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@ -46,7 +41,7 @@ public class FormBoat extends JFrame {
|
||||
}
|
||||
Random random = new Random();
|
||||
_boat = new DrawingBoat(random.nextInt(50, 150), random.nextInt(40, 70), new Color(random.nextInt(0, 256),
|
||||
random.nextInt(0, 256), random.nextInt(0, 256)), GetRollersAmount());
|
||||
random.nextInt(0, 256), random.nextInt(0, 256)), GetPaddleCount());
|
||||
SetData();
|
||||
}
|
||||
});
|
||||
@ -60,7 +55,7 @@ public class FormBoat extends JFrame {
|
||||
Random random = new Random();
|
||||
_boat = new DrawningMotorBoat(random.nextInt(30, 50), random.nextInt(1000, 2000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256),
|
||||
random.nextInt(0, 256)), GetRollersAmount(), new Color(random.nextInt(0, 256), random.nextInt(0, 256),
|
||||
random.nextInt(0, 256)), GetPaddleCount(), new Color(random.nextInt(0, 256), random.nextInt(0, 256),
|
||||
random.nextInt(0, 256)), random.nextBoolean(), random.nextBoolean());
|
||||
SetData();
|
||||
}
|
||||
@ -79,7 +74,6 @@ public class FormBoat extends JFrame {
|
||||
pictureBoxBoat.add(_boat, BorderLayout.CENTER);
|
||||
}
|
||||
});
|
||||
//джижение
|
||||
ButtonsMove buttonsMove = new ButtonsMove();
|
||||
buttonUp.setName("Up");
|
||||
buttonLeft.setName("Left");
|
||||
@ -112,7 +106,6 @@ public class FormBoat extends JFrame {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangePictureBoxBoatBorders() {
|
||||
char[] temp = pictureBoxBoat.getSize().toString().toCharArray();
|
||||
for (int i = 0; i < temp.length; i++) {
|
||||
@ -125,7 +118,7 @@ public class FormBoat extends JFrame {
|
||||
pictureBoxBoatWidth = Integer.parseInt(parameters[1]);
|
||||
pictureBoxBoatHeight = Integer.parseInt(parameters[2]);
|
||||
}
|
||||
private int GetRollersAmount() {
|
||||
private int GetPaddleCount() {
|
||||
if (radioButtonPaddle1.isSelected()) {
|
||||
return 1;
|
||||
}
|
||||
@ -134,5 +127,5 @@ public class FormBoat extends JFrame {
|
||||
} else {
|
||||
return 3;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,12 @@ import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
public class FormMap extends JFrame {
|
||||
public static void main(String[] args) {
|
||||
|
||||
FormMap window = new FormMap();
|
||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
window.pack();
|
||||
window.setLocationRelativeTo(null);
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
private JPanel mainPanel;
|
||||
private JPanel statusStrip;
|
||||
private JLabel toolStripStatusLabelSpeed;
|
||||
@ -46,13 +44,12 @@ public class FormMap extends JFrame {
|
||||
buttonGroupPaddlesRadBut.add(radioButtonPaddle3);
|
||||
setPreferredSize(new Dimension(1000, 700));
|
||||
getContentPane().add(mainPanel);
|
||||
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random random = new Random();
|
||||
var _boat = new DrawingBoat(random.nextInt(50, 150), random.nextInt(40, 70), new Color(random.nextInt(0, 256),
|
||||
random.nextInt(0, 256), random.nextInt(0, 256)), GetRollersAmount());
|
||||
random.nextInt(0, 256), random.nextInt(0, 256)), GetPaddleCount());
|
||||
SetData(_boat);
|
||||
}
|
||||
});
|
||||
@ -62,7 +59,7 @@ public class FormMap extends JFrame {
|
||||
Random random = new Random();
|
||||
var _boat = new DrawningMotorBoat(random.nextInt(30, 50), random.nextInt(1000, 2000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256),
|
||||
random.nextInt(0, 256)), GetRollersAmount(), new Color(random.nextInt(0, 256), random.nextInt(0, 256),
|
||||
random.nextInt(0, 256)), GetPaddleCount(), new Color(random.nextInt(0, 256), random.nextInt(0, 256),
|
||||
random.nextInt(0, 256)), random.nextBoolean(), random.nextBoolean());
|
||||
SetData(_boat);
|
||||
}
|
||||
@ -82,8 +79,6 @@ public class FormMap extends JFrame {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//джижение
|
||||
ButtonsMove buttonsMove = new ButtonsMove();
|
||||
buttonUp.setName("Up");
|
||||
buttonLeft.setName("Left");
|
||||
@ -100,7 +95,6 @@ public class FormMap extends JFrame {
|
||||
pictureBoxBoat.remove(pictureLabel);
|
||||
} catch (Exception c) { }
|
||||
ChangePictureBoxBoatBorders();
|
||||
// _boat.SetPosition(random.nextInt(20, 100), random.nextInt(50, 100), pictureBoxBoatWidth, pictureBoxBoatHeight);
|
||||
toolStripStatusLabelSpeed.setText("Скорость: " + _boat.Boat.Speed());
|
||||
toolStripStatusLabelWeight.setText("Вес: " + _boat.Boat.Weight());
|
||||
toolStripStatusLabelBodyColor.setText("Цвет: " + Integer.toHexString(_boat.Boat.BodyColor().getRGB()));
|
||||
@ -131,7 +125,6 @@ public class FormMap extends JFrame {
|
||||
pictureBoxBoat.add(pictureLabel, BorderLayout.CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangePictureBoxBoatBorders() {
|
||||
char[] temp = pictureBoxBoat.getSize().toString().toCharArray();
|
||||
for (int i = 0; i < temp.length; i++) {
|
||||
@ -144,7 +137,7 @@ public class FormMap extends JFrame {
|
||||
pictureBoxBoatWidth = Integer.parseInt(parameters[1]);
|
||||
pictureBoxBoatHeight = Integer.parseInt(parameters[2]);
|
||||
}
|
||||
private int GetRollersAmount() {
|
||||
private int GetPaddleCount() {
|
||||
if (radioButtonPaddle1.isSelected()) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -2,12 +2,8 @@ import java.awt.*;
|
||||
|
||||
public interface IDrawningObject {
|
||||
public float Step();
|
||||
// Установка позиции объекта
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
// Изменение направления пермещения объекта
|
||||
void MoveObject(Direction direction);
|
||||
// Отрисовка объекта
|
||||
void DrawingObject(Graphics g);
|
||||
// Получение текущей позиции объекта
|
||||
float[] GetCurrentPosition();
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawningObjectPaddle {
|
||||
//ñâîéñòâî äëÿ ïåðåäà÷è ÷èñëîâîãî çíà÷åíèÿ
|
||||
void SetPaddlesCount(int rollersAmount);
|
||||
//ìåòîä, ïðèíèìàþùèé ïàðàìåòðû äëÿ îòðèñîâêè
|
||||
void DrawPaddles(Graphics gr, int _startPosRollersX, int _startPosRollersY, Color mainBrush);
|
||||
void SetPaddlesCount(int paddleCount);
|
||||
void DrawPaddles(Graphics gr, int _startPosPadX, int _startPosPadY, Color mainBrush);
|
||||
}
|
||||
|
@ -2,43 +2,35 @@ import java.awt.*;
|
||||
|
||||
public class SeaMap extends SimpleMap {
|
||||
private final Color barrierColor = Color.BLUE;
|
||||
// Öâåò ó÷àñòêà îòêðûòîãî
|
||||
private final Color roadColor = Color.CYAN;
|
||||
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
_map = new int[100][100];
|
||||
_size_x = (float)_width / _map.length;
|
||||
_size_y = (float)_height / _map[0].length;
|
||||
_size_x = (float) _width / _map.length;
|
||||
_size_y = (float) _height / _map[0].length;
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
for (int i = 0; i < _map.length; ++i) {
|
||||
for (int j = 0; j < _map[0].length; ++j) {
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 10)
|
||||
{
|
||||
while (counter < 10) {
|
||||
int x = _random.nextInt(0, 100);
|
||||
int y = _random.nextInt(0, 100);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
if (_map[x][y] == _freeRoad) {
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j) {
|
||||
g.setColor(roadColor);
|
||||
g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j * (_size_y + 1)));
|
||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect((int)(i * _size_x), (int)(j * _size_y),(int) (i * (_size_x + 1)), (int)(j * (_size_y + 1)));
|
||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
}
|
@ -1,45 +1,36 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap {
|
||||
|
||||
private final Color barrierColor = Color.BLACK;
|
||||
// Öâåò ó÷àñòêà îòêðûòîãî
|
||||
private final Color roadColor = Color.GRAY;
|
||||
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
_map = new int[100][100];
|
||||
_size_x = (float)_width / _map.length;
|
||||
_size_y = (float)_height / _map[0].length;
|
||||
_size_x = (float) _width / _map.length;
|
||||
_size_y = (float) _height / _map[0].length;
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
for (int i = 0; i < _map.length; ++i) {
|
||||
for (int j = 0; j < _map[0].length; ++j) {
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 10)
|
||||
{
|
||||
while (counter < 10) {
|
||||
int x = _random.nextInt(0, 100);
|
||||
int y = _random.nextInt(0, 100);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
if (_map[x][y] == _freeRoad) {
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j) {
|
||||
g.setColor(roadColor);
|
||||
g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j * (_size_y + 1)));
|
||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect((int)(i * _size_x), (int)(j * _size_y),(int) (i * (_size_x + 1)), (int)(j * (_size_y + 1)));
|
||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user