Первый коммит. Вторая усложненная лабораторная работа. Выполнена (много изменений из за перехода на IntellIJ Ultimate)
This commit is contained in:
parent
6b1d2f4816
commit
efbca96f66
148
src/AbstractMap.java
Normal file
148
src/AbstractMap.java
Normal file
@ -0,0 +1,148 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AbstractMap {
|
||||
private IDrawingObject _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();
|
||||
protected final int _freeWaterArea = 0;
|
||||
protected final int _land = 1;
|
||||
|
||||
public BufferedImage CreateMap(int width, int height, IDrawingObject drawingObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawingObject = drawingObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
float[] dim = _drawingObject.GetCurrentPosition();
|
||||
|
||||
if (CheckLand(dim[0], dim[1], dim[2], dim[3]) != 0)
|
||||
{
|
||||
_drawingObject.MoveObject(SetOppositDirection(direction));
|
||||
}
|
||||
|
||||
if (true)
|
||||
{
|
||||
_drawingObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (_drawingObject==null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.nextInt(10);
|
||||
int y = _random.nextInt(10);
|
||||
_drawingObject.SetObject(x, y, _width, _height);
|
||||
|
||||
float[] dim = _drawingObject.GetCurrentPosition();
|
||||
|
||||
while (CheckLand(dim[0], dim[1], dim[2], dim[3]) != 2)
|
||||
{
|
||||
int res;
|
||||
do
|
||||
{
|
||||
res = CheckLand(dim[0], dim[1], dim[2], dim[3]);
|
||||
if (res == 0)
|
||||
{
|
||||
_drawingObject.SetObject((int)dim[0], (int)dim[1], _width, _height);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
dim[0] += _size_x;
|
||||
}
|
||||
} while (res != 2);
|
||||
dim[0] = x;
|
||||
dim[1] += _size_y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private BufferedImage DrawMapWithObject()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_width, _height,BufferedImage.TYPE_INT_RGB);
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics gr = bmp.getGraphics();
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; ++j)
|
||||
{
|
||||
if (_map[i][j] == _freeWaterArea)
|
||||
{
|
||||
DrawWaterPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i][j] == _land)
|
||||
{
|
||||
DrawLandPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawingObject.DrawingObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
private int CheckLand(float Left, float Right, float Top, float Bottom)
|
||||
{
|
||||
int RUi = (int)(Left / _size_x);
|
||||
int RUj = (int)(Right / _size_y);
|
||||
int LDi = (int)(Top / _size_x);
|
||||
int LDj = (int)(Bottom / _size_y);
|
||||
|
||||
if (RUi < 0 || RUj < 0 || LDi >= _map[0].length || LDj >= _map.length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int x = RUi; x <= LDi; x++)
|
||||
{
|
||||
for (int y = RUj; y <= LDj; y++)
|
||||
{
|
||||
if (_map[x][y] == _land)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private Direction SetOppositDirection(Direction dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case Up:
|
||||
return Direction.Down;
|
||||
case Down:
|
||||
return Direction.Up;
|
||||
case Left:
|
||||
return Direction.Right;
|
||||
case Right:
|
||||
return Direction.Left;
|
||||
case None:
|
||||
return Direction.None;
|
||||
}
|
||||
return Direction.None;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawWaterPart(Graphics gr, int i, int j);
|
||||
protected abstract void DrawLandPart(Graphics gr, int i, int j);
|
||||
}
|
9
src/BlockForm.java
Normal file
9
src/BlockForm.java
Normal file
@ -0,0 +1,9 @@
|
||||
public enum BlockForm {
|
||||
Rect(0),
|
||||
Round(1),
|
||||
Triangle(2);
|
||||
public final int Value;
|
||||
BlockForm(int i) {
|
||||
Value=i;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ public enum Direction {
|
||||
Up(1),
|
||||
Down(2),
|
||||
Left(3),
|
||||
Right(4);
|
||||
Right(4),
|
||||
None(0);
|
||||
Direction(int value){}
|
||||
}
|
||||
|
71
src/DrawingAdvancedWarship.java
Normal file
71
src/DrawingAdvancedWarship.java
Normal file
@ -0,0 +1,71 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingAdvancedWarship extends DrawingWarship {
|
||||
|
||||
public DrawingAdvancedWarship(int speed, float weight, Color bodyColor, Color dopColor, boolean Helipad,boolean Antenna, boolean Missile,int blockForm) {
|
||||
super(speed, weight, bodyColor, 120, 50);
|
||||
Warship=new EntityAdvancedWarship(speed,weight,bodyColor,dopColor,Helipad,Antenna,Missile);
|
||||
Blocks= GetFormOfBlock(blockForm);
|
||||
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics g) {
|
||||
|
||||
if (! (Warship instanceof EntityAdvancedWarship))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EntityAdvancedWarship advancedWarship = (EntityAdvancedWarship)Warship;
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
int [] x1 ={_startPosX+25,_startPosX+65,_startPosX+75,_startPosX+25,_startPosX+25};
|
||||
int [] y1 ={_startPosY,_startPosY,_startPosY+5,_startPosY+5,_startPosY};
|
||||
int [] x2 ={_startPosX+25,_startPosX+75,_startPosX+65,_startPosX+25,_startPosX+25};
|
||||
int [] y2 ={_startPosY+45,_startPosY+45,_startPosY+50,_startPosY+50,_startPosY+45};
|
||||
|
||||
if (advancedWarship.Missile)
|
||||
{
|
||||
g2.setColor(advancedWarship.GetDopColor());
|
||||
g2.fillPolygon(x1,y1,5);
|
||||
|
||||
g2.setColor(Color.BLACK);
|
||||
g.drawLine(_startPosX + 25, _startPosY + 5 - 5, _startPosX + 65, _startPosY + 5 - 5);
|
||||
g.drawLine(_startPosX + 65, _startPosY + 5 - 5,_startPosX + 75, _startPosY + 10 - 5);
|
||||
g.drawLine(_startPosX + 75, _startPosY + 10 - 5, _startPosX + 25, _startPosY + 10 - 5);
|
||||
g.drawLine(_startPosX + 25, _startPosY + 10 - 5, _startPosX + 25, _startPosY + 5 - 5);
|
||||
|
||||
g2.setColor(advancedWarship.GetDopColor());
|
||||
g2.fillPolygon(x2,y2,5);
|
||||
|
||||
g2.setColor(Color.BLACK);
|
||||
g.drawLine(_startPosX + 25, _startPosY + 50 - 5,_startPosX + 75, _startPosY + 50 - 5);
|
||||
g.drawLine(_startPosX + 75, _startPosY + 50 - 5,_startPosX + 65, _startPosY + 55 - 5);
|
||||
g.drawLine(_startPosX + 65, _startPosY + 55 - 5,_startPosX + 25, _startPosY + 55 - 5);
|
||||
g.drawLine(_startPosX + 25, _startPosY + 55 - 5,_startPosX + 25, _startPosY + 50 - 5);
|
||||
}
|
||||
|
||||
_startPosY += 5;
|
||||
super.DrawTransport(g);
|
||||
_startPosY -= 5;
|
||||
|
||||
if (advancedWarship.Helipad)
|
||||
{
|
||||
g2.setColor(advancedWarship.GetDopColor());
|
||||
g.fillOval(_startPosX + 85, _startPosY + 20-5, 20, 20);
|
||||
|
||||
g2.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 85, _startPosY + 20-5, 20, 20);
|
||||
g.drawLine(_startPosX + 90, _startPosY + 25 - 5, _startPosX + 90, _startPosY + 35 - 5);
|
||||
g.drawLine(_startPosX + 90+10, _startPosY + 25 - 5, _startPosX + 90+10, _startPosY + 35 - 5);
|
||||
g.drawLine(_startPosX + 90, _startPosY + 30 - 5, _startPosX + 100, _startPosY + 30 - 5);
|
||||
}
|
||||
if (advancedWarship.Antenna)
|
||||
{
|
||||
g2.setColor(Color.BLACK);
|
||||
g.drawLine(_startPosX + 15, _startPosY + 20 - 5, _startPosX + 15, _startPosY + 40 - 5);
|
||||
g.drawLine(_startPosX +10, _startPosY + 30 - 5, _startPosX + 20, _startPosY + 30 - 5);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,14 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingBlock {
|
||||
public class DrawingBlock implements IDrawingObjectBlock{
|
||||
|
||||
private BlockCount _block;
|
||||
private BlockCount _block=null;
|
||||
|
||||
public DrawingBlock(BlockCount block) {
|
||||
_block=block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetBlockCount(int count){
|
||||
for (BlockCount temp: BlockCount.values())
|
||||
if (temp.GetBlockCount() == count){
|
||||
@ -11,7 +16,7 @@ public class DrawingBlock {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawBlock(Graphics2D g,int _startPosX, int _startPosY) {
|
||||
if (_block.GetBlockCount() >= 2) {
|
||||
g.setColor(Color.GRAY);
|
||||
|
@ -1,62 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingField extends JPanel {
|
||||
private final FormWarship Field;
|
||||
DrawingWarship _warship;
|
||||
public DrawingField(FormWarship field) {
|
||||
this.Field = field;
|
||||
}
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 =(Graphics2D)g;
|
||||
if (_warship!=null)
|
||||
_warship.DrawTransport(g2);
|
||||
else return;
|
||||
}
|
||||
public void DrawWarship(Graphics g){
|
||||
if (_warship!=null)
|
||||
_warship.DrawTransport(g);
|
||||
else return;
|
||||
}
|
||||
public void UpButtonAction(){
|
||||
if (_warship!=null)
|
||||
_warship.MoveTransport(Direction.Up);
|
||||
else
|
||||
return;
|
||||
}
|
||||
public void DownButtonAction(){
|
||||
if (_warship!=null)
|
||||
_warship.MoveTransport(Direction.Down);
|
||||
else
|
||||
return;
|
||||
}
|
||||
public void RightButtonAction(){
|
||||
if (_warship!=null)
|
||||
_warship.MoveTransport(Direction.Right);
|
||||
else
|
||||
return;
|
||||
}
|
||||
public void LeftButtonAction(){
|
||||
if (_warship!=null)
|
||||
_warship.MoveTransport(Direction.Left);
|
||||
else
|
||||
return;
|
||||
}
|
||||
public void CreateButtonAction(){
|
||||
Random rand=new Random();
|
||||
_warship=new DrawingWarship();
|
||||
_warship.Init(rand.nextInt(50)+10,rand.nextInt(3000)+20000,new Color(rand.nextInt(256),rand.nextInt(256),rand.nextInt(256)));
|
||||
_warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||||
Field.SpeedLabel.setText("Скорость: "+_warship.GetWarship().GetSpeed());
|
||||
Field.WeightLabel.setText("Вес: "+_warship.GetWarship().GetWeight());
|
||||
Field.BodyColorLabel.setText("Цвет: "+Integer.toHexString(_warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
||||
}
|
||||
public void ResizeField(){
|
||||
if (_warship!=null)
|
||||
_warship.ChangeBorders(getWidth(),getHeight());
|
||||
else return;
|
||||
}
|
||||
}
|
71
src/DrawingMap.java
Normal file
71
src/DrawingMap.java
Normal file
@ -0,0 +1,71 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingMap extends JPanel {
|
||||
private final FormMap Map;
|
||||
private AbstractMap _abstractMap;
|
||||
BufferedImage bufferedImage;
|
||||
|
||||
public DrawingMap(FormMap map){
|
||||
Map=map;
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
}
|
||||
|
||||
private void SetData(DrawingWarship warship) {
|
||||
Random rand=new Random();
|
||||
warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||||
Map.SpeedLabel.setText("Скорость: "+warship.GetWarship().GetSpeed());
|
||||
Map.WeightLabel.setText("Вес: "+warship.GetWarship().GetWeight());
|
||||
Map.BodyColorLabel.setText("Цвет: "+Integer.toHexString(warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
||||
bufferedImage = _abstractMap.CreateMap(700,550,new DrawingObjectWarship(warship));
|
||||
}
|
||||
public void CreateButtonAction(){
|
||||
Random rand=new Random();
|
||||
Color color1 = JColorChooser.showDialog(Map, "Выберите цвет тела корабля", null);
|
||||
if(color1==null)
|
||||
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
DrawingWarship warship=new DrawingWarship(rand.nextInt(50)+10,rand.nextInt(3000)+20000,color1,rand.nextInt(3));
|
||||
SetData(warship);
|
||||
}
|
||||
public void CreateModifButtonAction(){
|
||||
Random rand=new Random();
|
||||
Color color1=JColorChooser.showDialog(Map, "Выберите цвет тела корабля",null);
|
||||
Color color2=JColorChooser.showDialog(Map, "Выборите цвет модификаций корабля",null);
|
||||
if(color1==null)
|
||||
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if (color2==null)
|
||||
color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
DrawingWarship warship = new DrawingAdvancedWarship(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, color1,
|
||||
color2, rand.nextBoolean(), rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
||||
SetData(warship);
|
||||
}
|
||||
public void DirectionButtonAction(Direction side){
|
||||
if(_abstractMap != null){
|
||||
bufferedImage = _abstractMap.MoveObject(side);
|
||||
}
|
||||
}
|
||||
|
||||
public void ComboBoxSelectorMapAction(String name){
|
||||
switch (name){
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Вторая карта":
|
||||
_abstractMap = new SecondMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawMap(Graphics g){
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
}
|
||||
|
||||
}
|
39
src/DrawingObjectWarship.java
Normal file
39
src/DrawingObjectWarship.java
Normal file
@ -0,0 +1,39 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingObjectWarship implements IDrawingObject {
|
||||
|
||||
private DrawingWarship _warship=null;
|
||||
|
||||
public DrawingObjectWarship(DrawingWarship warship)
|
||||
{
|
||||
_warship= warship;
|
||||
}
|
||||
|
||||
public float Step() {
|
||||
if(_warship != null && _warship.Warship != null)
|
||||
return _warship.Warship.Step;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height) {
|
||||
_warship.SetPosition(x,y,width,height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void MoveObject(Direction direction) {
|
||||
_warship.MoveTransport(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawingObject(Graphics g) {
|
||||
_warship.DrawTransport(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] GetCurrentPosition() {
|
||||
if(_warship!=null)
|
||||
return _warship.GetCurrentPosition();
|
||||
return null;
|
||||
}
|
||||
}
|
51
src/DrawingRoundBlocks.java
Normal file
51
src/DrawingRoundBlocks.java
Normal file
@ -0,0 +1,51 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingRoundBlocks implements IDrawingObjectBlock{
|
||||
private BlockCount _block;
|
||||
|
||||
public DrawingRoundBlocks(BlockCount block){
|
||||
_block=block;
|
||||
}
|
||||
@Override
|
||||
public void SetBlockCount(int count) {
|
||||
for (BlockCount temp: BlockCount.values())
|
||||
if (temp.GetBlockCount() == count){
|
||||
_block=temp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawBlock(Graphics2D g, int _startPosX, int _startPosY) {
|
||||
if (_block.GetBlockCount() >= 2) {
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillOval(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillOval(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 4) {
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillOval(_startPosX+35,_startPosY+10,10,10);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX+35,_startPosY+10,10,10);
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillOval(_startPosX+35,_startPosY+20,10,10);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX+35,_startPosY+20,10,10);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 6) {
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillOval(_startPosX+45,_startPosY+10,10,10);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX+45,_startPosY+10,10,10);
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillOval(_startPosX+45,_startPosY+20,10,10);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX+45,_startPosY+20,10,10);
|
||||
}
|
||||
}
|
||||
}
|
58
src/DrawingTriangleBlocks.java
Normal file
58
src/DrawingTriangleBlocks.java
Normal file
@ -0,0 +1,58 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingTriangleBlocks implements IDrawingObjectBlock{
|
||||
private BlockCount _block;
|
||||
|
||||
public DrawingTriangleBlocks(BlockCount block){
|
||||
_block=block;
|
||||
}
|
||||
@Override
|
||||
public void SetBlockCount(int count) {
|
||||
for (BlockCount temp: BlockCount.values())
|
||||
if (temp.GetBlockCount() == count){
|
||||
_block=temp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawBlock(Graphics2D g, int _startPosX, int _startPosY) {
|
||||
|
||||
int[] x1={_startPosX + 30,_startPosX + 35,_startPosX + 25,_startPosX + 30};
|
||||
int[] y1={_startPosY + 10,_startPosY + 20,_startPosY + 20,_startPosY + 10};
|
||||
int[] x2={_startPosX + 30+10,_startPosX + 35+10,_startPosX + 25+10,_startPosX + 30+10};
|
||||
int[] y2={_startPosY + 10+10,_startPosY + 20+10,_startPosY + 20+10,_startPosY + 10+10};
|
||||
int[] x3={_startPosX + 30+10+10,_startPosX + 35+10+10,_startPosX + 25+10+10,_startPosX + 30+10+10};
|
||||
|
||||
if (_block.GetBlockCount() >= 2) {
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillPolygon(x1,y1,4);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(x1,y1,4);
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillPolygon(x1,y2,4);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(x1,y2,4);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 4) {
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillPolygon(x2,y1,4);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(x2,y1,4);
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillPolygon(x2,y2,4);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(x2,y2,4);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 6) {
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillPolygon(x3,y1,4);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(x3,y1,4);
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillPolygon(x3,y2,4);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(x3,y2,4);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +1,56 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingWarship {
|
||||
private EntityWarship Warship;
|
||||
protected EntityWarship Warship;
|
||||
public EntityWarship GetWarship(){
|
||||
return Warship;
|
||||
}
|
||||
public DrawingBlock Blocks;
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
protected IDrawingObjectBlock Blocks;
|
||||
private BlockCount _block;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
private final int _warshipWidth = 120;
|
||||
private final int _warshipHeight = 40;
|
||||
private int _warshipWidth = 120;
|
||||
private int _warshipHeight = 40;
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawingWarship(int speed, float weight, Color bodyColor, int blockForm)
|
||||
{
|
||||
Warship = new EntityWarship();
|
||||
Warship.Init(speed, weight, bodyColor);
|
||||
Blocks= new DrawingBlock();
|
||||
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||
Blocks= GetFormOfBlock(blockForm);
|
||||
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
||||
}
|
||||
|
||||
public IDrawingObjectBlock GetFormOfBlock(int FormOfBlock){
|
||||
BlockForm temp = null;
|
||||
for (BlockForm form:BlockForm.values()) {
|
||||
if(form.Value==FormOfBlock){
|
||||
temp = form;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(temp==null)
|
||||
return null;
|
||||
switch (temp){
|
||||
case Rect:
|
||||
return new DrawingBlock(_block);
|
||||
case Round:
|
||||
return new DrawingRoundBlocks(_block);
|
||||
case Triangle:
|
||||
return new DrawingTriangleBlocks(_block);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected DrawingWarship(int speed, float weight, Color bodyColor,int warshipWidth, int warshipHeight)
|
||||
{
|
||||
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||
Blocks= new DrawingBlock(_block);
|
||||
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
||||
_warshipWidth=warshipWidth;
|
||||
_pictureHeight=warshipHeight;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x >= 0 && x+_warshipWidth <= width && y >= 0 && y+_warshipHeight <= height)
|
||||
@ -125,4 +155,12 @@ public class DrawingWarship {
|
||||
_startPosY = _pictureHeight - _warshipHeight;
|
||||
}
|
||||
}
|
||||
public float[] GetCurrentPosition() {
|
||||
float[] dim = new float[4];
|
||||
dim[0] = _startPosX;
|
||||
dim[1] =_startPosY;
|
||||
dim[2] = _startPosX + _warshipWidth;
|
||||
dim[3] = _startPosY + _warshipHeight;
|
||||
return dim;
|
||||
}
|
||||
}
|
||||
|
32
src/EntityAdvancedWarship.java
Normal file
32
src/EntityAdvancedWarship.java
Normal file
@ -0,0 +1,32 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAdvancedWarship extends EntityWarship{
|
||||
|
||||
public Color DopColor;
|
||||
public Color GetDopColor() {
|
||||
return DopColor;
|
||||
}
|
||||
|
||||
public boolean Helipad;
|
||||
public boolean GetHelipad() {
|
||||
return Helipad;
|
||||
}
|
||||
|
||||
public boolean Antenna;
|
||||
public boolean GetAntenna() {
|
||||
return Antenna;
|
||||
}
|
||||
|
||||
public boolean Missile;
|
||||
public boolean GetMissile() {
|
||||
return Missile;
|
||||
}
|
||||
|
||||
public EntityAdvancedWarship(int speed, float weight, Color bodyColor, Color dopColor, boolean helipad, boolean antenna, boolean missile){
|
||||
super(speed,weight,bodyColor);
|
||||
DopColor = dopColor;
|
||||
Helipad = helipad;
|
||||
Antenna = antenna;
|
||||
Missile = missile;
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ public class EntityWarship {
|
||||
|
||||
public int Step;
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityWarship(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
Speed = speed <= 0 ? rnd.nextInt(60)+10 : speed;
|
||||
|
@ -1,32 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarship">
|
||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="824" height="502"/>
|
||||
<xy x="20" y="24" width="816" height="551"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="4a033">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="bfabf">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="eeaaa" binding="BottomPanel" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="73281" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="28bed" class="javax.swing.JLabel" binding="SpeedLabel">
|
||||
<component id="9090d" class="javax.swing.JLabel" binding="SpeedLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@ -34,12 +24,12 @@
|
||||
<text value="Скорость: "/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="580fb">
|
||||
<hspacer id="5a45f">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="34d49" class="javax.swing.JLabel" binding="WeightLabel">
|
||||
<component id="c4bc2" class="javax.swing.JLabel" binding="WeightLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@ -47,7 +37,7 @@
|
||||
<text value="Вес: "/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2ab53" class="javax.swing.JLabel" binding="BodyColorLabel">
|
||||
<component id="74fba" class="javax.swing.JLabel" binding="BodyColorLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@ -57,15 +47,25 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="b692b" binding="CreatePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<hspacer id="6e33b">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="e09c8">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="786ee" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="8a5b" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<component id="92069" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@ -73,17 +73,25 @@
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="82dd2" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Модификация"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="31774" binding="DimentionPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="b99f9" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="9224d" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<component id="ba264" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@ -92,25 +100,7 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="13cf5" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="arrowUp.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e46ed" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="arrowLeft.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e8b93" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<component id="8f6d" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@ -119,38 +109,76 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9d65" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="arrowLeft.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7d46" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="arrowUp.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="99a01" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="7affd" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="925bf">
|
||||
<hspacer id="25">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="9f2b7" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="81336" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="31a5a">
|
||||
<hspacer id="89fd1">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="fd77d" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Простая карта"/>
|
||||
<item value="Вторая карта"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="da53e" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
76
src/FormMap.java
Normal file
76
src/FormMap.java
Normal file
@ -0,0 +1,76 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FormMap extends JFrame {
|
||||
private int Width;
|
||||
private int Height;
|
||||
DrawingMap map = new DrawingMap(this);
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonCreate;
|
||||
private JButton ButtonCreateModif;
|
||||
public JLabel SpeedLabel;
|
||||
public JLabel WeightLabel;
|
||||
public JLabel BodyColorLabel;
|
||||
private JComboBox ComboBoxSelectorMap;
|
||||
private JPanel PictureBox;
|
||||
|
||||
public FormMap(){
|
||||
super("Военный корабль");
|
||||
setContentPane(PictureBox);
|
||||
setSize(1000,700);
|
||||
Width = getWidth();
|
||||
Height = getHeight();
|
||||
ShowWindow();
|
||||
map.setBounds(0,0,Width,Height);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void ShowWindow(){
|
||||
ButtonCreate.addActionListener(e -> {
|
||||
map.CreateButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
ButtonCreateModif.addActionListener(e -> {
|
||||
map.CreateModifButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
ButtonUp.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Up);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonLeft.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Left);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonRight.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Right);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonDown.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Down);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
ComboBoxSelectorMap.addActionListener(e -> {
|
||||
map.ComboBoxSelectorMapAction(Objects.requireNonNull(ComboBoxSelectorMap.getSelectedItem()).toString());
|
||||
ReDraw();
|
||||
});
|
||||
}
|
||||
private void ReDraw()
|
||||
{
|
||||
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
||||
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
PictureBox.paintComponents(graphics);
|
||||
map.DrawMap(graphics);
|
||||
}
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
public class FormWarship extends JFrame{
|
||||
JPanel BottomPanel;
|
||||
JPanel CreatePanel;
|
||||
JPanel DimentionPanel;
|
||||
|
||||
JLabel SpeedLabel;
|
||||
JLabel WeightLabel;
|
||||
JLabel BodyColorLabel;
|
||||
|
||||
private int Width;
|
||||
private int Height;
|
||||
DrawingField field = new DrawingField(this);
|
||||
|
||||
JButton ButtonCreate;
|
||||
JButton ButtonUp;
|
||||
JButton ButtonDown;
|
||||
JButton ButtonRight;
|
||||
JButton ButtonLeft;
|
||||
JPanel PictureBox;
|
||||
|
||||
|
||||
public FormWarship(){
|
||||
super("Военный корабль");
|
||||
setContentPane(PictureBox);
|
||||
setSize(700,400);
|
||||
Width=getWidth();
|
||||
Height=getHeight();
|
||||
ShowWindow();
|
||||
field.setBounds(0,0,Width,Height);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public void ShowWindow(){
|
||||
|
||||
ButtonUp.addActionListener(e->{
|
||||
field.UpButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
ButtonDown.addActionListener(e->{
|
||||
field.DownButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
ButtonRight.addActionListener(e->{
|
||||
field.RightButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
ButtonLeft.addActionListener(e->{
|
||||
field.LeftButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
ButtonCreate.addActionListener(e->{
|
||||
field.CreateButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
super.componentResized(e);
|
||||
Width=getWidth();
|
||||
Height=getHeight();
|
||||
|
||||
field.ResizeField();
|
||||
field.setBounds(0,0,Width,Height);
|
||||
ReDraw();
|
||||
}
|
||||
});
|
||||
}
|
||||
private void ReDraw()
|
||||
{
|
||||
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
||||
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
PictureBox.paintComponents(graphics);
|
||||
field.DrawWarship(graphics);
|
||||
}
|
||||
}
|
||||
|
9
src/IDrawingObject.java
Normal file
9
src/IDrawingObject.java
Normal file
@ -0,0 +1,9 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingObject {
|
||||
public float Step=0;
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
void MoveObject(Direction direction);
|
||||
void DrawingObject(Graphics g);
|
||||
float[] GetCurrentPosition();
|
||||
}
|
6
src/IDrawingObjectBlock.java
Normal file
6
src/IDrawingObjectBlock.java
Normal file
@ -0,0 +1,6 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingObjectBlock {
|
||||
void SetBlockCount(int count);
|
||||
void DrawBlock(Graphics2D g, int _startPosX, int _startPosY);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new FormWarship();
|
||||
new FormMap();
|
||||
}
|
||||
}
|
||||
|
37
src/SecondMap.java
Normal file
37
src/SecondMap.java
Normal file
@ -0,0 +1,37 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SecondMap extends AbstractMap{
|
||||
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
_map = new int[60][60];
|
||||
_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[i].length; ++j) {
|
||||
_map[i][j] = _freeWaterArea;
|
||||
}
|
||||
}
|
||||
while (counter < 20) {
|
||||
int x = _random.nextInt(59);
|
||||
int y = _random.nextInt(59);
|
||||
if (_map[x][y] == _freeWaterArea) {
|
||||
_map[x][y] = _land;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawWaterPart(Graphics gr, int i, int j) {
|
||||
gr.setColor(new Color(0xFFFFFF));
|
||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawLandPart(Graphics gr, int i, int j) {
|
||||
gr.setColor(new Color(0x050303));
|
||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
}
|
36
src/SimpleMap.java
Normal file
36
src/SimpleMap.java
Normal file
@ -0,0 +1,36 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap {
|
||||
@Override
|
||||
protected void DrawWaterPart(Graphics gr, int i, int j) {
|
||||
gr.setColor(new Color(0x5285B6));
|
||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawLandPart(Graphics gr, int i, int j) {
|
||||
gr.setColor(new Color(0x422A1D));
|
||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
_map = new int[100][100];
|
||||
_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[i].length; ++j) {
|
||||
_map[i][j] = _freeWaterArea;
|
||||
}
|
||||
}
|
||||
while (counter < 50) {
|
||||
int x = _random.nextInt(99);
|
||||
int y = _random.nextInt(99);
|
||||
if (_map[x][y] == _freeWaterArea) {
|
||||
_map[x][y] = _land;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user