Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
177823cb79 | |||
a2e5535386 | |||
13eaeb49ed | |||
efbca96f66 | |||
6b1d2f4816 |
@ -3,6 +3,7 @@
|
|||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/Resource" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
|
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),
|
Up(1),
|
||||||
Down(2),
|
Down(2),
|
||||||
Left(3),
|
Left(3),
|
||||||
Right(4);
|
Right(4),
|
||||||
|
None(0);
|
||||||
Direction(int value){}
|
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.*;
|
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){
|
public void SetBlockCount(int count){
|
||||||
for (BlockCount temp: BlockCount.values())
|
for (BlockCount temp: BlockCount.values())
|
||||||
if (temp.GetBlockCount() == count){
|
if (temp.GetBlockCount() == count){
|
||||||
@ -11,7 +16,7 @@ public class DrawingBlock {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void DrawBlock(Graphics2D g,int _startPosX, int _startPosY) {
|
public void DrawBlock(Graphics2D g,int _startPosX, int _startPosY) {
|
||||||
if (_block.GetBlockCount() >= 2) {
|
if (_block.GetBlockCount() >= 2) {
|
||||||
g.setColor(Color.GRAY);
|
g.setColor(Color.GRAY);
|
||||||
|
@ -2,12 +2,13 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DrawingField extends JPanel {
|
public class DrawingField extends JPanel{
|
||||||
private final FormWarship Field;
|
private final FormWarship Field;
|
||||||
DrawingWarship _warship;
|
DrawingWarship _warship=null;
|
||||||
public DrawingField(FormWarship field) {
|
public DrawingField(FormWarship field) {
|
||||||
this.Field = field;
|
Field = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
@ -16,42 +17,38 @@ public class DrawingField extends JPanel {
|
|||||||
_warship.DrawTransport(g2);
|
_warship.DrawTransport(g2);
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
public void UpButtonAction(){
|
public void DirectionButtonAction(Direction side){
|
||||||
if (_warship!=null)
|
if(_warship == null)
|
||||||
_warship.MoveTransport(Direction.Up);
|
|
||||||
else
|
|
||||||
return;
|
return;
|
||||||
|
_warship.MoveTransport(side);
|
||||||
}
|
}
|
||||||
public void DownButtonAction(){
|
private void SetData() {
|
||||||
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();
|
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());
|
_warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||||||
Field.SpeedLabel.setText("Скорость: "+_warship.GetWarship().GetSpeed());
|
Field.SpeedLabel.setText("Скорость: "+_warship.GetWarship().GetSpeed());
|
||||||
Field.WeightLabel.setText("Вес: "+_warship.GetWarship().GetWeight());
|
Field.WeightLabel.setText("Вес: "+_warship.GetWarship().GetWeight());
|
||||||
Field.BodyColorLabel.setText("Цвет: "+Integer.toHexString(_warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
Field.BodyColorLabel.setText("Цвет: "+Integer.toHexString(_warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
||||||
}
|
}
|
||||||
|
public void CreateButtonAction(){
|
||||||
|
Random rand=new Random();
|
||||||
|
_warship=new DrawingWarship(rand.nextInt(50)+10,rand.nextInt(3000)+20000,new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),rand.nextInt(3));
|
||||||
|
SetData();
|
||||||
|
}
|
||||||
|
public void CreateModifButtonAction(){
|
||||||
|
Random rand=new Random();
|
||||||
|
_warship = new DrawingAdvancedWarship(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
|
||||||
|
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)), rand.nextBoolean(), rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
||||||
|
SetData();
|
||||||
|
}
|
||||||
public void ResizeField(){
|
public void ResizeField(){
|
||||||
if (_warship!=null)
|
if (_warship!=null)
|
||||||
_warship.ChangeBorders(getWidth(),getHeight());
|
_warship.ChangeBorders(getWidth(),getHeight());
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Draw(Graphics2D graphics) {
|
||||||
|
if (_warship!=null)
|
||||||
|
_warship.DrawTransport(graphics);
|
||||||
|
else return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
65
src/DrawingMap.java
Normal file
65
src/DrawingMap.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
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=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=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||||
|
Color 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.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingWarship {
|
public class DrawingWarship {
|
||||||
private EntityWarship Warship;
|
protected EntityWarship Warship;
|
||||||
public EntityWarship GetWarship(){
|
public EntityWarship GetWarship(){
|
||||||
return Warship;
|
return Warship;
|
||||||
}
|
}
|
||||||
public DrawingBlock Blocks;
|
protected IDrawingObjectBlock Blocks;
|
||||||
private int _startPosX;
|
private BlockCount _block;
|
||||||
private int _startPosY;
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
private Integer _pictureWidth = null;
|
private Integer _pictureWidth = null;
|
||||||
private Integer _pictureHeight = null;
|
private Integer _pictureHeight = null;
|
||||||
private final int _warshipWidth = 120;
|
private int _warshipWidth = 120;
|
||||||
private final int _warshipHeight = 40;
|
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 = new EntityWarship(speed, weight, bodyColor);
|
||||||
Warship.Init(speed, weight, bodyColor);
|
Blocks= GetFormOfBlock(blockForm);
|
||||||
Blocks= new DrawingBlock();
|
|
||||||
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
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)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
if (x >= 0 && x+_warshipWidth <= width && y >= 0 && y+_warshipHeight <= height)
|
if (x >= 0 && x+_warshipWidth <= width && y >= 0 && y+_warshipHeight <= height)
|
||||||
@ -125,4 +155,12 @@ public class DrawingWarship {
|
|||||||
_startPosY = _pictureHeight - _warshipHeight;
|
_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 int Step;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public EntityWarship(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
Speed = speed <= 0 ? rnd.nextInt(60)+10 : speed;
|
Speed = speed <= 0 ? rnd.nextInt(60)+10 : speed;
|
||||||
|
175
src/FormMap.form
Normal file
175
src/FormMap.form
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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="24" width="816" height="551"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<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="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="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>
|
||||||
|
<properties>
|
||||||
|
<text value="Скорость: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<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="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>
|
||||||
|
<properties>
|
||||||
|
<text value="Вес: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<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>
|
||||||
|
<properties>
|
||||||
|
<text value="Цвет: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<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="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="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>
|
||||||
|
<properties>
|
||||||
|
<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="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="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="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>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowDown.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<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>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowRight.jpg"/>
|
||||||
|
<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="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="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="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="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="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="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>
|
||||||
|
</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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
164
src/FormWarship.form
Normal file
164
src/FormWarship.form
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
<?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">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="637" height="507"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="11e3d" 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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="d468f" 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>
|
||||||
|
<properties>
|
||||||
|
<text value="Скорость: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="321ab">
|
||||||
|
<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="d033b" 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>
|
||||||
|
<properties>
|
||||||
|
<text value="Вес: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ba46a" 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>
|
||||||
|
<properties>
|
||||||
|
<text value="Цвет: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="ba3a6" 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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="f38f9" 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="ab65" 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>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowDown.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ae569" 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>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowRight.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="8e604" 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="98f8a" 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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="6de46" 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>
|
||||||
|
<properties>
|
||||||
|
<text value="Создать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="e329e" 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>
|
||||||
|
<hspacer id="73825">
|
||||||
|
<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="5a84c">
|
||||||
|
<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="e85d9" 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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<hspacer id="e5ed3">
|
||||||
|
<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="a3aed" 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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<hspacer id="c4971">
|
||||||
|
<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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
@ -1,136 +1,80 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
public class FormWarship extends JFrame{
|
public class FormWarship extends JFrame{
|
||||||
private int Width;
|
private int Width;
|
||||||
private int Height;
|
private int Height;
|
||||||
|
|
||||||
JPanel BottomPanel = new JPanel();
|
|
||||||
JPanel CreatePanel = new JPanel();
|
|
||||||
JPanel BottomAndCreatePanel = new JPanel();
|
|
||||||
JPanel DimentionPanel = new JPanel();
|
|
||||||
JPanel UPanel = new JPanel();
|
|
||||||
JPanel DPanel = new JPanel();
|
|
||||||
JPanel LRPanel = new JPanel();
|
|
||||||
|
|
||||||
JLabel SpeedLabel = new JLabel("Скорость: ");
|
|
||||||
JLabel WeightLabel = new JLabel("Вес: ");
|
|
||||||
JLabel BodyColorLabel = new JLabel("Цвет: ");
|
|
||||||
|
|
||||||
DrawingField field = new DrawingField(this);
|
DrawingField field = new DrawingField(this);
|
||||||
|
private JButton ButtonDown;
|
||||||
JButton ButtonCreate=new JButton("Создать");
|
private JButton ButtonRight;
|
||||||
|
private JButton ButtonLeft;
|
||||||
Icon iconUp = new ImageIcon("Resource\\arrowUp.jpg");
|
private JButton ButtonUp;
|
||||||
JButton ButtonUp=new JButton(iconUp);
|
private JButton ButtonCreate;
|
||||||
|
private JButton ButtonCreateModif;
|
||||||
Icon iconDown = new ImageIcon("Resource\\arrowDown.jpg");
|
public JLabel SpeedLabel;
|
||||||
JButton ButtonDown=new JButton(iconDown);
|
public JLabel WeightLabel;
|
||||||
|
public JLabel BodyColorLabel;
|
||||||
Icon iconRight = new ImageIcon("Resource\\arrowRight.jpg");
|
private JPanel PictureBox;
|
||||||
JButton ButtonRight=new JButton(iconRight);
|
|
||||||
|
|
||||||
Icon iconLeft = new ImageIcon("Resource\\arrowLeft.jpg");
|
|
||||||
JButton ButtonLeft=new JButton(iconLeft);
|
|
||||||
|
|
||||||
|
|
||||||
public FormWarship(){
|
public FormWarship(){
|
||||||
super("Военный корабль");
|
super("Военный корабль");
|
||||||
setSize(700,400);
|
setContentPane(PictureBox);
|
||||||
Width=getWidth();
|
setSize(1000,700);
|
||||||
Height=getHeight();
|
Width = getWidth();
|
||||||
|
Height = getHeight();
|
||||||
ShowWindow();
|
ShowWindow();
|
||||||
RefreshWindow();
|
field.setBounds(0,0,Width,Height);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowWindow(){
|
private void ShowWindow(){
|
||||||
|
|
||||||
Dimension dimen=new Dimension(30,30);
|
ButtonCreate.addActionListener(e -> {
|
||||||
|
|
||||||
ButtonUp.setPreferredSize(dimen);
|
|
||||||
ButtonUp.addActionListener(e->{
|
|
||||||
field.UpButtonAction();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonDown.setPreferredSize(dimen);
|
|
||||||
ButtonDown.addActionListener(e->{
|
|
||||||
field.DownButtonAction();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonRight.setPreferredSize(dimen);
|
|
||||||
ButtonRight.addActionListener(e->{
|
|
||||||
field.RightButtonAction();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonLeft.setPreferredSize(dimen);
|
|
||||||
ButtonLeft.addActionListener(e->{
|
|
||||||
field.LeftButtonAction();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
|
||||||
LRPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
LRPanel.add(ButtonLeft);
|
|
||||||
LRPanel.add(ButtonRight);
|
|
||||||
|
|
||||||
UPanel.setLayout(new FlowLayout());
|
|
||||||
UPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
UPanel.add(ButtonUp);
|
|
||||||
|
|
||||||
DPanel.setLayout(new FlowLayout());
|
|
||||||
DPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
DPanel.add(ButtonDown);
|
|
||||||
|
|
||||||
DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS));
|
|
||||||
DimentionPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
DimentionPanel.add(UPanel);
|
|
||||||
DimentionPanel.add(LRPanel);
|
|
||||||
DimentionPanel.add(DPanel);
|
|
||||||
add(DimentionPanel);
|
|
||||||
|
|
||||||
CreatePanel.setLayout(new FlowLayout());
|
|
||||||
CreatePanel.setBackground(new Color(0,0,0,0));
|
|
||||||
CreatePanel.add(ButtonCreate);
|
|
||||||
ButtonCreate.addActionListener(e->{
|
|
||||||
field.CreateButtonAction();
|
field.CreateButtonAction();
|
||||||
repaint();
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonCreateModif.addActionListener(e -> {
|
||||||
|
field.CreateModifButtonAction();
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonUp.addActionListener(e -> {
|
||||||
|
field.DirectionButtonAction(Direction.Up);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonLeft.addActionListener(e -> {
|
||||||
|
field.DirectionButtonAction(Direction.Left);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonRight.addActionListener(e -> {
|
||||||
|
field.DirectionButtonAction(Direction.Right);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonDown.addActionListener(e -> {
|
||||||
|
field.DirectionButtonAction(Direction.Down);
|
||||||
|
ReDraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
BottomPanel.setLayout(new FlowLayout());
|
|
||||||
BottomPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
BottomPanel.add(SpeedLabel);
|
|
||||||
BottomPanel.add(WeightLabel);
|
|
||||||
BottomPanel.add(BodyColorLabel);
|
|
||||||
|
|
||||||
BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS));
|
|
||||||
BottomAndCreatePanel.setBackground(new Color(0,0,0,0));
|
|
||||||
BottomAndCreatePanel.add(CreatePanel);
|
|
||||||
BottomAndCreatePanel.add(BottomPanel);
|
|
||||||
|
|
||||||
add(BottomAndCreatePanel);
|
|
||||||
add(field);
|
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
addComponentListener(new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e){
|
||||||
super.componentResized(e);
|
super.componentResized(e);
|
||||||
Width=getWidth();
|
Width=getWidth();
|
||||||
Height=getHeight();
|
Height=getHeight();
|
||||||
|
|
||||||
field.ResizeField();
|
field.ResizeField();
|
||||||
repaint();
|
ReDraw();
|
||||||
RefreshWindow();
|
field.setBounds(0,0,Width,Height);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void RefreshWindow(){
|
private void ReDraw()
|
||||||
field.setBounds(0,0,Width,Height);
|
{
|
||||||
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
||||||
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
PictureBox.paintComponents(graphics);
|
||||||
|
field.Draw(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,6 +1,5 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
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