Presnyakova V.V Lab_2 #2
115
AbstractMap.java
Normal file
115
AbstractMap.java
Normal file
@ -0,0 +1,115 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AbstractMap {
|
||||
private IDrawningObject _drawningObject = 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 _freeRoad = 0;
|
||||
protected final int _barrier = 1;
|
||||
|
||||
public BufferedImage CreateMap(int width, int height, IDrawningObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawningObject = drawningObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private boolean CheckBarriers(float topOffset, float rightOffset, float leftOffset, float bottomOffset)
|
||||
{
|
||||
float[] arrayPossition = _drawningObject.GetCurrentPosition();
|
||||
int top = (int)((arrayPossition[1] + topOffset) / _size_y);
|
||||
int right = (int)((arrayPossition[2] + rightOffset) / _size_x);
|
||||
int left = (int)((arrayPossition[0] + leftOffset) / _size_x);
|
||||
int bottom = (int)((arrayPossition[3] + bottomOffset) / _size_y);
|
||||
if (top < 0 || left < 0 || right >= _map[0].length || bottom >= _map.length) return false;
|
||||
for (int i = top; i <= bottom; i++)
|
||||
{
|
||||
for (int j = left; j <= right; j++)
|
||||
{
|
||||
if (_map[j][i] == _barrier) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
if (_drawningObject == null) return DrawMapWithObject();
|
||||
boolean isTrue = true;
|
||||
switch (direction)
|
||||
{
|
||||
case Left:
|
||||
if (!CheckBarriers(0, -1 * _drawningObject.Step(), -1 * _drawningObject.Step(), 0)) isTrue = false;
|
||||
break;
|
||||
case Right:
|
||||
if (!CheckBarriers(0, _drawningObject.Step(), _drawningObject.Step(), 0)) isTrue = false;
|
||||
break;
|
||||
case Up:
|
||||
if (!CheckBarriers(-1 * _drawningObject.Step(), 0, 0, -1 * _drawningObject.Step())) isTrue = false;
|
||||
break;
|
||||
case Down:
|
||||
if (!CheckBarriers(_drawningObject.Step(), 0, 0, _drawningObject.Step())) isTrue = false;
|
||||
break;
|
||||
}
|
||||
if (isTrue)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.nextInt(0, 10);
|
||||
int y = _random.nextInt(0, 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
if (!CheckBarriers(0, 0, 0, 0)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private BufferedImage DrawMapWithObject()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB);
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics gr = bmp.getGraphics();
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
if (_map[i][j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart((Graphics2D) gr, i, j);
|
||||
}
|
||||
else if (_map[i][j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart((Graphics2D) gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawningObject.DrawningObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics2D g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics2D g, int i, int j);
|
||||
}
|
@ -2,6 +2,7 @@ public enum Direction {
|
||||
Up(1),
|
||||
Down(2),
|
||||
Left(3),
|
||||
Right(4);
|
||||
Right(4),
|
||||
None(0);
|
||||
Direction(int value){}
|
||||
}
|
||||
|
@ -4,18 +4,18 @@ import java.util.Random;
|
||||
|
||||
public class DrawningBoat extends JPanel {
|
||||
|
||||
private EntityBoat Boat;
|
||||
EntityBoat Boat;
|
||||
public EntityBoat GetBoat(){
|
||||
return Boat;
|
||||
}
|
||||
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
public DrawningOars OarsDraw;
|
||||
int _startPosX;
|
||||
int _startPosY;
|
||||
public IDrawningOars OarsDraw;
|
||||
public Integer _pictureWidth = null;
|
||||
public Integer _pictureHeight = null;
|
||||
private final int _BoatWidth = 80;
|
||||
private final int _BoatHeight = 50;
|
||||
private int _BoatWidth = 80;
|
||||
private int _BoatHeight = 50;
|
||||
|
||||
public void SetOars() {
|
||||
Random r = new Random();
|
||||
@ -23,11 +23,21 @@ public class DrawningBoat extends JPanel {
|
||||
OarsDraw.SetOarsCount(numIllum);
|
||||
}
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawningBoat(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Boat = new EntityBoat();
|
||||
Boat.Init(speed, weight, bodyColor);
|
||||
OarsDraw = new DrawningOars();
|
||||
Boat = new EntityBoat(speed, weight, bodyColor);
|
||||
Random random = new Random();
|
||||
switch (random.nextInt(3)){
|
||||
case 0:
|
||||
OarsDraw = new DrawningOars();
|
||||
break;
|
||||
case 1:
|
||||
OarsDraw = new DrawningSqareOars();
|
||||
break;
|
||||
case 2:
|
||||
OarsDraw = new DrawningOvalOars();
|
||||
break;
|
||||
}
|
||||
SetOars();
|
||||
}
|
||||
|
||||
@ -76,21 +86,22 @@ public class DrawningBoat extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport() {
|
||||
protected DrawningBoat(int speed, float weight, Color bodyColor, int boatWidth, int boatHeight)
|
||||
{
|
||||
this(speed, weight, bodyColor);
|
||||
_BoatWidth = boatWidth;
|
||||
_BoatHeight = boatHeight;
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g) {
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) {
|
||||
return;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
if (GetBoat() == null) {
|
||||
return;
|
||||
}
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponent(g);
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
g2d.setColor(Color.BLACK);
|
||||
@ -115,6 +126,8 @@ public class DrawningBoat extends JPanel {
|
||||
g2d.fillOval(_startPosX + 5, _startPosY + 5, _BoatWidth - 15, _BoatHeight - 11);
|
||||
|
||||
OarsDraw.DrawOars(g, _startPosX, _startPosY);
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
@ -136,4 +149,13 @@ public class DrawningBoat extends JPanel {
|
||||
_startPosY = _pictureHeight - _BoatHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public float[] GetCurrentPosition() {
|
||||
float[] dim = new float[4];
|
||||
dim[0] = _startPosX;
|
||||
dim[1] =_startPosY;
|
||||
dim[2] = _startPosX + _BoatWidth;
|
||||
dim[3] = _startPosY + _BoatHeight;
|
||||
return dim;
|
||||
}
|
||||
}
|
||||
|
42
DrawningCatamaran.java
Normal file
42
DrawningCatamaran.java
Normal file
@ -0,0 +1,42 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningCatamaran extends DrawningBoat{
|
||||
|
||||
public DrawningCatamaran(int speed, float weight, Color bodyColor, Color dopColor, boolean sail, boolean floats)
|
||||
{
|
||||
super(speed, weight, bodyColor, 140, 70);
|
||||
Boat = new EntityCatamaran(speed, weight, bodyColor, dopColor, sail, floats);
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (! (Boat instanceof EntityCatamaran Catamaran))
|
||||
{
|
||||
return;
|
||||
}
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(Color.BLACK);
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
super.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
int _catamaranWidth = 80;
|
||||
int _catamaranHeight = 50;
|
||||
if (Catamaran.Sail)
|
||||
{
|
||||
g2d.setPaint(Catamaran.DopColor);
|
||||
int[] p_x = {(int)(_startPosX + _catamaranWidth * 2 / 4), (int)(_startPosX + _catamaranWidth), (int)(_startPosX + _catamaranWidth * 2 / 4)};
|
||||
int[] p_y = {(int)_startPosY + 5, (int)(_startPosY + _catamaranHeight / 2), (int)(_startPosY + _catamaranHeight)};
|
||||
g.fillPolygon(p_x, p_y, 3);
|
||||
}
|
||||
if (Catamaran.Floats)
|
||||
{
|
||||
g2d.setPaint(Catamaran.DopColor);
|
||||
g.fillOval(_startPosX, _startPosY, (int)(_catamaranWidth / 2), (int)(_catamaranHeight / 2));
|
||||
g.fillOval(_startPosX, 27 + _startPosY + (int)(_catamaranHeight / 2), (int)(_catamaranWidth / 2), (int)(_catamaranHeight / 2));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningOars extends JComponent {
|
||||
public class DrawningOars implements IDrawningOars {
|
||||
private OarsCount _Oars;
|
||||
|
||||
@Override
|
||||
public void SetOarsCount(int numOfOars) {
|
||||
_Oars = OarsCount.GetOarsCount(numOfOars);
|
||||
}
|
||||
|
||||
public void DrawOars(Graphics g, int _startPosX, int _startPosY) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(Color.BLACK);
|
||||
int numOfIlluminator = 0;
|
||||
@ -29,9 +29,7 @@ public class DrawningOars extends JComponent {
|
||||
for(int i = numOfIlluminator; i >= 1; --i){
|
||||
g2d.setColor(Color.CYAN);
|
||||
g2d.fillRect(_startPosX + (10 * (i + 1)), _startPosY -15, 5, 15);
|
||||
//g2d.fillOval(_startPosX + 105 - 3 * i, _startPosY + 35, 3, 3);
|
||||
g2d.setColor(Color.BLACK);
|
||||
//g2d.drawOval(_startPosX + 105 - 3 * i, _startPosY + 35, 3, 3);
|
||||
g2d.drawRect(_startPosX + (10 * (i + 1)), _startPosY - 15, 5, 15);
|
||||
|
||||
}
|
||||
|
39
DrawningObjectBoat.java
Normal file
39
DrawningObjectBoat.java
Normal file
@ -0,0 +1,39 @@
|
||||
import java.awt.*;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class DrawningObjectBoat implements IDrawningObject {
|
||||
private DrawningBoat _boat = null;
|
||||
|
||||
public DrawningObjectBoat(DrawningBoat boat)
|
||||
{
|
||||
_boat = boat;
|
||||
}
|
||||
@Override
|
||||
public float Step() {
|
||||
if(_boat != null && _boat.Boat != null)
|
||||
return _boat.Boat.GetStep();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height) {
|
||||
_boat.SetPosition(x,y,width,height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void MoveObject(Direction direction) {
|
||||
_boat.MoveTransport(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawningObject(Graphics g) {
|
||||
_boat.DrawTransport(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] GetCurrentPosition() {
|
||||
if(_boat!=null)
|
||||
return _boat.GetCurrentPosition();
|
||||
return null;
|
||||
}
|
||||
}
|
36
DrawningOvalOars.java
Normal file
36
DrawningOvalOars.java
Normal file
@ -0,0 +1,36 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningOvalOars implements IDrawningOars{
|
||||
private OarsCount _Oars;
|
||||
|
||||
@Override
|
||||
public void SetOarsCount(int numOfOars) {
|
||||
_Oars = OarsCount.GetOarsCount(numOfOars);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawOars(Graphics g, int _startPosX, int _startPosY) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(Color.BLACK);
|
||||
int numOfOars = 0;
|
||||
switch (_Oars)
|
||||
{
|
||||
case One:
|
||||
numOfOars = 1;
|
||||
break;
|
||||
case Two:
|
||||
numOfOars = 2;
|
||||
break;
|
||||
case Three:
|
||||
numOfOars = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
for(int i = numOfOars; i >= 1; --i){
|
||||
g2d.setColor(Color.CYAN);
|
||||
g2d.fillOval(_startPosX + (15 * (i + 1)), _startPosY -15, 15, 15);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(_startPosX + (15 * (i + 1)), _startPosY - 15, 15, 15);
|
||||
}
|
||||
}
|
||||
}
|
33
DrawningSqareOars.java
Normal file
33
DrawningSqareOars.java
Normal file
@ -0,0 +1,33 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningSqareOars implements IDrawningOars{
|
||||
private OarsCount _Oars;
|
||||
@Override
|
||||
public void SetOarsCount(int numOfOars) {_Oars = OarsCount.GetOarsCount(numOfOars); }
|
||||
|
||||
@Override
|
||||
public void DrawOars(Graphics g, int _startPosX, int _startPosY) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(Color.BLACK);
|
||||
int numOfOars = 0;
|
||||
switch (_Oars)
|
||||
{
|
||||
case One:
|
||||
numOfOars = 1;
|
||||
break;
|
||||
case Two:
|
||||
numOfOars = 2;
|
||||
break;
|
||||
case Three:
|
||||
numOfOars = 3;
|
||||
break;
|
||||
}
|
||||
for(int i = numOfOars; i >= 1; --i){
|
||||
g2d.setColor(Color.CYAN);
|
||||
g2d.fillRect(_startPosX + (15 * (i + 1)), _startPosY -15, 15, 15);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(_startPosX + (15 * (i + 1)), _startPosY - 15, 15, 15);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -16,9 +16,12 @@ public class EntityBoat {
|
||||
public Color GetBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
public float Step;
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public float Step;
|
||||
public float GetStep(){return Step;}
|
||||
|
||||
|
||||
public EntityBoat(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
Speed = speed <= 0 ? rnd.nextInt(10,30) : speed;
|
||||
|
17
EntityCatamaran.java
Normal file
17
EntityCatamaran.java
Normal file
@ -0,0 +1,17 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityCatamaran extends EntityBoat{
|
||||
|
||||
public Color DopColor;
|
||||
|
||||
public boolean Sail;
|
||||
|
||||
public boolean Floats;
|
||||
|
||||
public EntityCatamaran(int speed, float weight, Color bodyColor, Color dopColor, boolean sail, boolean floats) {
|
||||
super(speed, weight, bodyColor);
|
||||
DopColor = dopColor;
|
||||
Sail = sail;
|
||||
Floats = floats;
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormBoat">
|
||||
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" 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="500" height="400"/>
|
||||
<xy x="20" y="20" width="513" height="406"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<opaque value="true"/>
|
||||
@ -13,7 +13,7 @@
|
||||
<children>
|
||||
<component id="2ea16" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -25,7 +25,7 @@
|
||||
</component>
|
||||
<component id="4f60a" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -37,7 +37,7 @@
|
||||
</component>
|
||||
<component id="4eb88" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -48,27 +48,9 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9f55" class="DrawningBoat" binding="PictureBoxBoat">
|
||||
<constraints>
|
||||
<grid row="0" 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/>
|
||||
</component>
|
||||
<component id="fb937" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<toolbar id="e747d" binding="StatusStrip">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="3" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="20"/>
|
||||
<preferred-size width="-1" height="20"/>
|
||||
<maximum-size width="-1" height="20"/>
|
||||
@ -80,16 +62,6 @@
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</toolbar>
|
||||
<hspacer id="d6bea">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<hspacer id="d86ff">
|
||||
<constraints>
|
||||
<grid row="2" column="1" 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="9e2ce" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
@ -98,6 +70,39 @@
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="febd4" binding="PictureBox" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="fb937" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="44b75" class="javax.swing.JButton" binding="ButtonModif">
|
||||
<constraints>
|
||||
<grid row="2" 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>
|
||||
<hspacer id="dd0eb">
|
||||
<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>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
@ -3,24 +3,45 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
public class FormBoat {
|
||||
|
||||
public class FormBoat extends JFrame{
|
||||
public JPanel Mainpanel;
|
||||
private JButton ButtonCreate;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
protected DrawningBoat PictureBoxBoat;
|
||||
protected DrawningBoat _boat;
|
||||
private JPanel PictureBox;
|
||||
private JToolBar StatusStrip;
|
||||
private JLabel JLabelSpeed = new JLabel();
|
||||
private JLabel JLabelWeight = new JLabel();
|
||||
private JLabel JLabelColor = new JLabel();
|
||||
private JButton ButtonModif;
|
||||
private final JLabel JLabelSpeed = new JLabel();
|
||||
private final JLabel JLabelWeight = new JLabel();
|
||||
private final JLabel JLabelColor = new JLabel();
|
||||
public void Draw() {
|
||||
if (PictureBoxBoat.GetBoat() == null) {
|
||||
return;
|
||||
PictureBox.removeAll();
|
||||
BufferedImage bmp = new BufferedImage(PictureBox.getWidth(), PictureBox.getHeight(),BufferedImage.TYPE_INT_RGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
gr.setColor(new Color(238, 238, 238));
|
||||
gr.fillRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
if (_boat != null) {
|
||||
_boat.DrawTransport(gr);
|
||||
JLabel imageOfPlane = new JLabel();
|
||||
imageOfPlane.setPreferredSize(PictureBox.getSize());
|
||||
imageOfPlane.setMinimumSize(new Dimension(1, 1));
|
||||
imageOfPlane.setIcon(new ImageIcon(bmp));
|
||||
PictureBox.add(imageOfPlane,BorderLayout.CENTER);
|
||||
}
|
||||
PictureBoxBoat.DrawTransport();
|
||||
validate();
|
||||
}
|
||||
private void SetData(){
|
||||
Random random = new Random();
|
||||
_boat.SetPosition(random.nextInt(10, 100), random.nextInt(30, 100), PictureBox.getWidth(), PictureBox.getHeight());
|
||||
JLabelSpeed.setText("Cкорость: " + _boat.GetBoat().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _boat.GetBoat().GetWeight() + " ");
|
||||
JLabelColor.setText(("Цвет: " + _boat.GetBoat().GetBodyColor() + " "));
|
||||
}
|
||||
public FormBoat() {
|
||||
Box LabelBox = Box.createHorizontalBox();
|
||||
@ -43,35 +64,44 @@ public class FormBoat {
|
||||
}
|
||||
ButtonCreate.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
PictureBoxBoat.Init(random.nextInt(10, 30), random.nextInt(10, 20), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
PictureBoxBoat.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), PictureBoxBoat.getWidth(), PictureBoxBoat.getHeight());
|
||||
JLabelSpeed.setText("Cкорость: " + PictureBoxBoat.GetBoat().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + PictureBoxBoat.GetBoat().GetWeight() + " ");
|
||||
JLabelColor.setText(("Цвет: " + PictureBoxBoat.GetBoat().GetBodyColor() + " "));
|
||||
_boat = new DrawningBoat(random.nextInt(100, 300),random.nextInt(1000, 2000),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
SetData();
|
||||
Draw();
|
||||
});
|
||||
PictureBoxBoat.addComponentListener(new ComponentAdapter() {
|
||||
ButtonModif.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
_boat = new DrawningCatamaran(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), random.nextBoolean(), random.nextBoolean());
|
||||
SetData();
|
||||
Draw();
|
||||
});
|
||||
PictureBox.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
if(_boat == null || _boat.GetBoat() == null) return;
|
||||
super.componentResized(e);
|
||||
PictureBoxBoat.ChangeBorders(PictureBoxBoat.getWidth(), PictureBoxBoat.getHeight());
|
||||
_boat.ChangeBorders(PictureBox.getWidth(), PictureBox.getHeight());
|
||||
PictureBox.revalidate();
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
ButtonUp.addActionListener(e -> {
|
||||
PictureBoxBoat.MoveTransport(Direction.Up);
|
||||
_boat.MoveTransport(Direction.Up);
|
||||
PictureBox.revalidate();
|
||||
Draw();
|
||||
});
|
||||
ButtonDown.addActionListener(e -> {
|
||||
PictureBoxBoat.MoveTransport(Direction.Down);
|
||||
_boat.MoveTransport(Direction.Down);
|
||||
PictureBox.revalidate();
|
||||
Draw();
|
||||
});
|
||||
ButtonRight.addActionListener(e -> {
|
||||
PictureBoxBoat.MoveTransport(Direction.Right);
|
||||
_boat.MoveTransport(Direction.Right);
|
||||
PictureBox.revalidate();
|
||||
Draw();
|
||||
});
|
||||
ButtonLeft.addActionListener(e -> {
|
||||
PictureBoxBoat.MoveTransport(Direction.Left);
|
||||
_boat.MoveTransport(Direction.Left);
|
||||
PictureBox.revalidate();
|
||||
Draw();
|
||||
});
|
||||
}
|
||||
|
121
FormMap.form
Normal file
121
FormMap.form
Normal file
@ -0,0 +1,121 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
||||
<grid id="27dc6" 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>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="b59ef" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<opaque value="true"/>
|
||||
<preferredSize width="800" height="600"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="64b3e" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d18ed" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f1131" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<toolbar id="ca5d0" binding="StatusStrip">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="7" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="20"/>
|
||||
<preferred-size width="-1" height="20"/>
|
||||
<maximum-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</toolbar>
|
||||
<component id="ac7fe" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="bf993" binding="PictureBox" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="2202b" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="4b50c" class="javax.swing.JButton" binding="ButtonModif">
|
||||
<constraints>
|
||||
<grid row="2" 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>
|
||||
<component id="db7c6" class="javax.swing.JComboBox" binding="comboBoxSelector">
|
||||
<constraints>
|
||||
<grid row="2" 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>
|
||||
<toolTipText value="Простая карта"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
128
FormMap.java
Normal file
128
FormMap.java
Normal file
@ -0,0 +1,128 @@
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormMap extends JFrame{
|
||||
public JPanel Mainpanel;
|
||||
private JButton ButtonCreate;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JPanel PictureBox;
|
||||
private JToolBar StatusStrip;
|
||||
private JButton ButtonModif;
|
||||
private JComboBox comboBoxSelector;
|
||||
private final JLabel JLabelSpeed = new JLabel();
|
||||
private final JLabel JLabelWeight = new JLabel();
|
||||
private final JLabel JLabelColor = new JLabel();
|
||||
private AbstractMap _abstractMap;
|
||||
|
||||
private void ButtonMove_Click(String name)
|
||||
{
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
}
|
||||
PictureBox.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(PictureBox.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(dir)));
|
||||
PictureBox.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
PictureBox.revalidate();
|
||||
PictureBox.repaint();
|
||||
}
|
||||
|
||||
private void SetData(DrawningBoat _boat){
|
||||
PictureBox.removeAll();
|
||||
JLabelSpeed.setText("Cкорость: " + _boat.GetBoat().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _boat.GetBoat().GetWeight() + " ");
|
||||
JLabelColor.setText(("Цвет: " + _boat.GetBoat().GetBodyColor() + " "));
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(PictureBox.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.CreateMap(PictureBox.getWidth(),PictureBox.getHeight(), new DrawningObjectBoat(_boat))));
|
||||
PictureBox.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
PictureBox.revalidate();
|
||||
}
|
||||
public FormMap() {
|
||||
comboBoxSelector.addItem("Простая карта");
|
||||
comboBoxSelector.addItem("Вторая карта");
|
||||
_abstractMap = new SimpleMap();
|
||||
Box LabelBox = Box.createHorizontalBox();
|
||||
LabelBox.setMinimumSize(new Dimension(1, 20));
|
||||
LabelBox.add(JLabelSpeed);
|
||||
LabelBox.add(JLabelWeight);
|
||||
LabelBox.add(JLabelColor);
|
||||
StatusStrip.add(LabelBox);
|
||||
try {
|
||||
Image img = ImageIO.read(FormMap.class.getResource("/Resource/arrowUp.jpg"));
|
||||
ButtonUp.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormMap.class.getResource("/Resource/arrowDown.jpg"));
|
||||
ButtonDown.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormMap.class.getResource("/Resource/arrowLeft.jpg"));
|
||||
ButtonLeft.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormMap.class.getResource("/Resource/arrowRight.jpg"));
|
||||
ButtonRight.setIcon(new ImageIcon(img));
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
ButtonCreate.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
var _boat = new DrawningBoat(random.nextInt(100, 300),random.nextInt(1000, 2000),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
SetData(_boat);
|
||||
});
|
||||
ButtonModif.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
var _boat = new DrawningCatamaran(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), random.nextBoolean(), random.nextBoolean());
|
||||
SetData(_boat);
|
||||
});
|
||||
ButtonUp.addActionListener(e -> {
|
||||
ButtonMove_Click("buttonUp");
|
||||
});
|
||||
ButtonDown.addActionListener(e -> {
|
||||
ButtonMove_Click("buttonDown");
|
||||
});
|
||||
ButtonLeft.addActionListener(e -> {
|
||||
ButtonMove_Click("buttonLeft");
|
||||
});
|
||||
ButtonRight.addActionListener(e -> {
|
||||
ButtonMove_Click("buttonRight");
|
||||
});
|
||||
comboBoxSelector.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
comboBoxSelector = (JComboBox)e.getSource();
|
||||
String item = (String)comboBoxSelector.getSelectedItem();
|
||||
switch (item) {
|
||||
case "Простая карта" -> {
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
}
|
||||
case "Вторая карта" -> {
|
||||
_abstractMap = new MyMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
7
IDrawningOars.java
Normal file
7
IDrawningOars.java
Normal file
@ -0,0 +1,7 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawningOars {
|
||||
|
||||
void SetOarsCount(int numOfOars);
|
||||
void DrawOars(Graphics g, int _startPosX, int _startPosY);
|
||||
}
|
7
IDrawningOarsjava
Normal file
7
IDrawningOarsjava
Normal file
@ -0,0 +1,7 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawningIlluminator {
|
||||
|
||||
void SetIlluminatorCount(int numOfIllum);
|
||||
void DrawIlluminator(Graphics g, int _startPosX, int _startPosY);
|
||||
}
|
13
IDrawningObject.java
Normal file
13
IDrawningObject.java
Normal file
@ -0,0 +1,13 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawningObject {
|
||||
float Step();
|
||||
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
|
||||
void MoveObject(Direction direction);
|
||||
|
||||
void DrawningObject(Graphics g);
|
||||
|
||||
float[] GetCurrentPosition();
|
||||
}
|
@ -4,7 +4,7 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame("Лодка");
|
||||
frame.setContentPane(new FormBoat().Mainpanel);
|
||||
frame.setContentPane(new FormMap().Mainpanel);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(500, 200);
|
||||
frame.pack();
|
||||
|
44
MyMap.java
Normal file
44
MyMap.java
Normal file
@ -0,0 +1,44 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class MyMap extends AbstractMap{
|
||||
private Color barrierColor = Color.WHITE;
|
||||
private Color roadColor = Color.CYAN;
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics2D g, int i, int j)
|
||||
{
|
||||
g.setPaint(barrierColor);
|
||||
g.fillRect((int)Math.floor(i * _size_x), (int)Math.floor(j * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics2D g, int i, int j)
|
||||
{
|
||||
g.setPaint(roadColor);
|
||||
g.fillRect((int)Math.floor(i * _size_x), (int)Math.floor(j * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
||||
}
|
||||
@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[0].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 25)
|
||||
{
|
||||
int x = _random.nextInt(0, 100);
|
||||
int y = _random.nextInt(0, 100);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
45
SimpleMap.java
Normal file
45
SimpleMap.java
Normal file
@ -0,0 +1,45 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap{
|
||||
|
||||
private Color barrierColor = Color.BLACK;
|
||||
private Color roadColor = Color.GRAY;
|
||||
|
||||
@Override
|
||||
protected void GenerateMap()
|
||||
{
|
||||
_map = new int[100][100];
|
||||
_size_x = (float)_width / _map.length;
|
||||
_size_y = (float)_height / _map[0].length;
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.nextInt(0, 100);
|
||||
int y = _random.nextInt(0, 100);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics2D g, int i, int j)
|
||||
{
|
||||
g.setPaint(roadColor);
|
||||
g.fillRect((int)Math.floor(i * _size_x), (int)Math.floor(j * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
||||
}
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics2D g, int i, int j)
|
||||
{
|
||||
g.setPaint(barrierColor);
|
||||
g.fillRect((int)Math.floor(i * _size_x), (int)Math.floor(j * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user