secondLabWork EndVersion

This commit is contained in:
Zara28 2022-11-05 10:53:11 +04:00
parent a9acdf4239
commit c16145c8f8
21 changed files with 1290 additions and 136 deletions

3
.vs/ProjectSettings.json Normal file
View File

@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}

BIN
.vs/slnx.sqlite Normal file

Binary file not shown.

View File

@ -71,7 +71,7 @@ jlink.additionalmodules=
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=ArmoredVehicle
main.class=
main.class=MapForm
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false

View File

@ -0,0 +1,191 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Random;
public abstract class AbstractMap {
private IDrawingObject drawingObject;
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 Image CreateMap(int width, int height, IDrawingObject drawingObject)
{
this.width = width;
this.height = height;
this.drawingObject = drawingObject;
GenerateMap();
while (!SetObjectOnMap())
{
GenerateMap();
}
return DrawMapWithObject();
}
public Image MoveObject(Direction direction)
{
if (drawingObject == null)
return null;
boolean flag = true;
float step = drawingObject.getStep();
HashMap<String, Float> hashMap = drawingObject.GetCurrentPosition();
float left = hashMap.get("Left");
float right = hashMap.get("Right");
float top = hashMap.get("Top");
float bottom = hashMap.get("Bottom");
int x1 = (int)((left - step) / size_x);
int y1 = (int)((top - step) / size_y);
int x2 = (int)((right + step) / size_x);
int y2 = (int)((bottom + step) / size_y);
int x1_current = (int)(left / size_x);
int y1_current = (int)(top / size_y);
int x2_current = (int)(right / size_x);
int y2_current = (int)(bottom / size_y);
switch (direction)
{
case Left:
{
if (x1 < 0)
flag = false;
else
{
for (int i = x1; i <= x1_current; i++)
{
for (int j = y1_current; j <= y2_current; j++)
{
if (map[i][j] == _barrier)
flag = false;
}
}
}
break;
}
case Right:
{
if (x2 >= map.length)
flag = false;
else
{
for (int i = x2_current; i <= x2; i++)
{
for (int j = y1_current; j <= y2_current; j++)
{
if (map[i][j] == _barrier)
flag = false;
}
}
}
break;
}
case Up:
{
if (y1 < 0)
flag = false;
else
{
for (int i = x1_current; i <= x2_current; i++)
{
for (int j = y1; j <= y1_current; j++)
{
if (map[i][j] == _barrier)
flag = false;
}
}
}
break;
}
case Down:
{
if (y2 >= map.length)
flag = false;
else
{
for (int i = x1_current; i <= x2_current; i++)
{
for (int j = y2_current; j <= y2; j++)
{
if (map[i][j] == _barrier)
flag = false;
}
}
}
break;
}
}
if (flag)
{
drawingObject.MoveObject(direction);
}
return DrawMapWithObject();
}
private boolean SetObjectOnMap()
{
if (drawingObject == null || map == null)
{
return false;
}
int x = random.nextInt(0, 10);
int y = random.nextInt(0, 10);
drawingObject.SetObject(x, y, width, height);
HashMap<String, Float> hashMap = drawingObject.GetCurrentPosition();
float left = hashMap.get("Left");
float right = hashMap.get("Right");
float top = hashMap.get("Top");
float bottom = hashMap.get("Bottom");
for (int i = (int)(x / size_x); i <= (int) (right / size_x); i++)
{
for (int j = (int)(y / size_y); j <= (int) (bottom / size_y); j++)
{
if (map[i][j] == _barrier)
{
return false;
}
}
}
return true;
}
private Image DrawMapWithObject()
{
BufferedImage bmp = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
if(drawingObject == null || map == null)
{
return bmp;
}
Graphics gr = bmp.getGraphics();
Graphics2D g = (Graphics2D)gr;
for(int i = 0; i < map.length; ++i)
{
for(int j = 0; j < map[i].length; ++j)
{
if (map[i][j] == _freeRoad)
{
DrawRoadPart(g, i, j);
}
else if (map[i][j] == _barrier)
{
DrawBarrierPart(g, i, j);
}
}
}
drawingObject.DrawingObject(g);
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);
}

View File

@ -25,7 +25,7 @@ class ArmoredVehicleEntity {
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <returns></returns>
public void Init(int speed, float weight, Color bodyColor)
public ArmoredVehicleEntity(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;

View File

@ -2,10 +2,11 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import static java.lang.Math.random;
import java.util.HashMap;
import java.util.Random;
import javax.swing.JPanel;
public class DrawingArmoredVehicle extends JPanel{
public class DrawingArmoredVehicle{
/// <summary>
/// Класс-сущность
@ -14,45 +15,65 @@ public class DrawingArmoredVehicle extends JPanel{
/// <summary>
/// Левая координата отрисовки
/// </summary>
private float _startPosX;
protected float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки
/// </summary>
private float _startPosY;
protected float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private int _pictureWidth = 0;
protected int _pictureWidth = 0;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private int _pictureHeight = 0;
protected int _pictureHeight = 0;
/// <summary>
/// Ширина отрисовки
/// </summary>
private int _ArmoredVehicleWidth = 210;
protected int _ArmoredVehicleWidth = 210;
/// <summary>
/// Высота отрисовки
/// </summary>
private int _ArmoredVehicleHeight = 50;
protected int _ArmoredVehicleHeight = 60;
/// <summary>
/// Инициализация свойств
/// </summary>
private Roller rolls = new Roller();;
private IDrawingRoller roller;
Random rnd = new Random();
public int Count;
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес </param>
/// <param name="bodyColor">Цвет</param>
public void Init(int speed, float weight, Color bodyColor)
public DrawingArmoredVehicle(int speed, float weight, Color bodyColor)
{
ArmoredVehicle = new ArmoredVehicleEntity();
ArmoredVehicle.Init(speed, weight, bodyColor);
Random r = new Random();
ArmoredVehicle = new ArmoredVehicleEntity(speed, weight, bodyColor);
int variant = r.nextInt(3);
switch(variant)
{
case 0:
this.roller = new Roller(bodyColor);
break;
case 1:
this.roller = new DrawingFirstRoller(bodyColor);
break;
case 2:
this.roller = new DrawingSecondRoller(bodyColor);
break;
}
Count = 6 - rnd.nextInt(0, 3);
}
public DrawingArmoredVehicle(int speed, float weight, Color bodyColor, int ArmoredVehicleWidth,
int ArmoredVehicleHeight)
{
this(speed, weight, bodyColor);
_ArmoredVehicleHeight = ArmoredVehicleHeight + 50;
_ArmoredVehicleWidth = ArmoredVehicleWidth + 50;
}
/// <summary>
/// Установка позиции
/// </summary>
@ -88,7 +109,6 @@ public class DrawingArmoredVehicle extends JPanel{
_pictureHeight = height;
}
repaint();
}
/// <summary>
/// Изменение направления пермещения
@ -118,7 +138,7 @@ public class DrawingArmoredVehicle extends JPanel{
break;
//вверх
case Up:
if (_startPosY - ArmoredVehicle.Step > 0)
if (_startPosY - ArmoredVehicle.Step > 20)
{
_startPosY -= ArmoredVehicle.Step;
}
@ -131,45 +151,34 @@ public class DrawingArmoredVehicle extends JPanel{
}
break;
}
super.repaint();
}
/// <summary>
/// Отрисовка
/// </summary>
/// <param name="g"></param>
@Override
public void paint(Graphics gr) {
if (_startPosX < 0 || _startPosY < 0
public void DrawTransport(Graphics2D gr)
{
if (_startPosX < 0 || _startPosY < 0
|| _pictureHeight==0 || _pictureWidth==0)
{
return;
}
gr.clearRect(0, 0, _pictureHeight+500, _pictureWidth+500);
super.paintComponent(gr);
Graphics2D g = (Graphics2D) gr;
Color color = ArmoredVehicle.BodyColor != null ?
ArmoredVehicle.BodyColor : Color.BLACK;
g.setColor(color);
g.fillRect((int)_startPosX + 50, (int)_startPosY, 100, 40);
g.fillRect((int)_startPosX + 15, (int)_startPosY+20, 200, 20);
//контур
g.drawRect((int)_startPosX + 50, (int)_startPosY, 100, 20);
g.drawRect((int)_startPosX + 15, (int)_startPosY+20, 200, 20);
g.drawOval((int)_startPosX + 15, (int)_startPosY + 25, 200, 35);
rolls.Init(Count, color, _startPosX, _startPosY, _ArmoredVehicleWidth);
rolls.paint(gr);
super.repaint();
g.dispose();
}
roller.DrawRoller(gr, (int)_startPosX, (int)_startPosY, 210, Count);
}
//
/// <summary>
/// Смена границ формы отрисовки
/// </summary>
@ -193,6 +202,15 @@ public class DrawingArmoredVehicle extends JPanel{
{
_startPosY = _pictureHeight - _ArmoredVehicleHeight;
}
super.repaint();
}
public HashMap<String, Float> GetCurrentPosition()
{
HashMap<String, Float> hashMap = new HashMap<String, Float>();
hashMap.put("Left", _startPosX);
hashMap.put("Right", _startPosX + _ArmoredVehicleWidth);
hashMap.put("Top", _startPosY);
hashMap.put("Bottom", _startPosY + _ArmoredVehicleHeight);
return hashMap;
}
}

View File

@ -0,0 +1,49 @@
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
public class DrawingFirstRoller implements IDrawingRoller{
private Color color;
private CountRollers Count;
public DrawingFirstRoller(Color color) {
this.color = color;
}
@Override
public void setCount(int n) {
switch (n) {
case 4 -> Count = CountRollers.Four;
case 5 -> Count = CountRollers.Five;
case 6 -> Count = CountRollers.Six;
default -> {
break;
}
}
}
@Override
public void DrawRoller(Graphics2D g, int startPosX, int startPosY, int Width, int count) {
color = color != null ?
color : Color.BLACK;
g.setColor(color);
setCount(count);
switch (Count)
{
case Four -> count = 4;
case Five -> count = 5;
case Six -> count = 6;
}
int ras = (int)Width /count;
for (int i = 0; i < count; i += 1)
{
g.drawOval((int)startPosX+ i*ras + 15, (int)startPosY + 35, 20, 20);
g.fillOval((int)startPosX+ i*ras + 20, (int)startPosY + 40, 15, 15);
}
}
}

View File

@ -0,0 +1,41 @@
import java.awt.Graphics2D;
import java.util.HashMap;
public class DrawingObject implements IDrawingObject{
private DrawingArmoredVehicle _machine = null;
public DrawingObject(DrawingArmoredVehicle machine) {
this._machine = machine;
}
@Override
public float getStep() {
if (_machine != null)
return _machine.ArmoredVehicle.Step;
return 0;
}
@Override
public void SetObject(int x, int y, int width, int height) {
if (_machine != null)
_machine.SetPosition(x, y, width, height);
}
@Override
public void MoveObject(Direction direction) {
if (_machine != null)
_machine.MoveTransport(direction);
}
@Override
public void DrawingObject(Graphics2D g) {
if (_machine != null)
_machine.DrawTransport(g);
}
@Override
public HashMap<String, Float> GetCurrentPosition() {
return _machine.GetCurrentPosition();
}
}

View File

@ -0,0 +1,49 @@
import java.awt.Color;
import java.awt.Graphics2D;
public class DrawingSecondRoller implements IDrawingRoller{
private Color color;
private CountRollers Count;
public DrawingSecondRoller(Color color) {
this.color = color;
}
@Override
public void setCount(int n) {
switch (n) {
case 4 -> Count = CountRollers.Four;
case 5 -> Count = CountRollers.Five;
case 6 -> Count = CountRollers.Six;
default -> {
break;
}
}
}
@Override
public void DrawRoller(Graphics2D g, int startPosX, int startPosY, int Width, int count) {
color = color != null ?
color : Color.BLACK;
g.setColor(color);
setCount(count);
switch (Count)
{
case Four -> count = 4;
case Five -> count = 5;
case Six -> count = 6;
}
int ras = (int)Width /count;
for (int i = 0; i < count; i += 1)
{
g.drawOval((int)startPosX+ i*ras + 15, (int)startPosY + 35, 20, 20);
g.drawRect((int)startPosX+ i*ras + 20, (int)startPosY + 40, 10, 10);
}
}
}

View File

@ -0,0 +1,40 @@
import java.awt.Color;
import java.awt.Graphics2D;
public class DrawingTank extends DrawingArmoredVehicle{
public DrawingTank(int speed, float weight, Color bodyColor, Color dopColor, boolean machineGun, boolean tower)
{
super(speed, weight, bodyColor, 200, 60);
ArmoredVehicle = new TankEntity(speed, weight, bodyColor, dopColor, machineGun, tower);
}
@Override
public void DrawTransport(Graphics2D g)
{
if (!"TankEntity".equals(ArmoredVehicle.getClass().getName()))
{
return;
}
TankEntity machine = (TankEntity) ArmoredVehicle;
_startPosY += 40;
super.DrawTransport(g);
_startPosY -= 40;
g.setColor(machine.DopColor);
if (machine.Tower)
{
g.fillRect((int)_startPosX + 60, (int)_startPosY + 10, 80, 30);
g.drawLine((int)_startPosX + 90, (int)_startPosY +20, (int)_startPosX + 250, (int)_startPosY + 20);
if (machine.MachineGun)
{
g.drawLine((int) _startPosX + 90, (int)_startPosY, (int)_startPosX + 90, (int)_startPosY + 10);
g.drawLine((int)_startPosX + 85, (int)_startPosY + 5, (int)_startPosX + 120,(int) _startPosY + 5);
}
}
}
}

View File

@ -0,0 +1,54 @@
import java.awt.Color;
import java.awt.Graphics2D;
public class HorizontalMap extends AbstractMap{
private final Color barrierColor = Color.RED;
private final Color roadColor = Color.WHITE;
@Override
protected void GenerateMap() {
map = new int[50][50];
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 < 7)
{
int x1 = random.nextInt(12);
int x2 = random.nextInt(12, map[0].length);
int y1 = random.nextInt(12, map[1].length);
for (int i = x1; i < x2; i++)
{
if (map[i][y1] == _freeRoad)
{
map[i][y1] = _barrier;
}
}
counter++;
}
}
@Override
protected void DrawRoadPart(Graphics2D gc, int i, int j) {
gc.setColor(roadColor);
gc.fillRect(i * (int)size_x, j * (int)size_y, i * ((int)size_x + 1), j * ((int)size_y + 1));
}
@Override
protected void DrawBarrierPart(Graphics2D gc, int i, int j) {
gc.setColor( barrierColor);
gc.fillRect(i * (int)size_x, j * (int)size_y, i * ((int)size_x + 1), j * ((int)size_y + 1));
}
}

View File

@ -0,0 +1,33 @@
import java.awt.Graphics2D;
import java.util.HashMap;
public interface IDrawingObject {
/// <summary>
/// Шаг перемещения объекта
/// </summary>
float getStep();
/// <summary>
/// Установка позиции объекта
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина полотна</param>
/// <param name="height">Высота полотна</param>
void SetObject(int x, int y, int width, int height);
/// <summary>
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
/// <returns></returns>
void MoveObject(Direction direction);
/// <summary>
/// Отрисовка объекта
/// </summary>
/// <param name="g"></param>
void DrawingObject(Graphics2D g);
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
HashMap<String, Float> GetCurrentPosition();
}

View File

@ -0,0 +1,8 @@
import java.awt.Graphics2D;
public interface IDrawingRoller {
void setCount(int n);
void DrawRoller(Graphics2D g2d, int startPosX, int startPosY, int Width, int count);
}

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" value="jButton1"/>
</Properties>
</Component>
</NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
@ -27,11 +34,11 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="444" max="32767" attributes="0"/>
<EmptySpace min="0" pref="451" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="DrawPanel" pref="438" max="32767" attributes="0"/>
<Component id="DrawPanel" pref="445" max="32767" attributes="0"/>
</Group>
</Group>
</Group>

View File

@ -2,20 +2,23 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class MainForm extends javax.swing.JFrame {
private DrawingArmoredVehicle _ArmoredVehicle = new DrawingArmoredVehicle();;
private Image img;
private DrawingArmoredVehicle _ArmoredVehicle;
private DrawingArmoredVehicle SelectedMachine;
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
jButton1 = new javax.swing.JButton();
DrawPanel = new javax.swing.JPanel(){
Graphics2D g2;};
PropertyText = new java.awt.TextField();
@ -26,6 +29,8 @@ public class MainForm extends javax.swing.JFrame {
DownButton = new java.awt.Button();
RightButton = new java.awt.Button();
jButton1.setText("jButton1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(444, 303));
setName("MainFrame"); // NOI18N
@ -61,7 +66,6 @@ public class MainForm extends javax.swing.JFrame {
UpButton.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
UpButton.setLabel("");
UpButton.setMinimumSize(new java.awt.Dimension(30, 30));
UpButton.setPreferredSize(new java.awt.Dimension(30, 30));
UpButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
UpButtonMouseClicked(evt);
@ -77,7 +81,6 @@ public class MainForm extends javax.swing.JFrame {
LeftButton.setActionCommand("Left");
LeftButton.setMinimumSize(new java.awt.Dimension(30, 30));
LeftButton.setName("LeftButton"); // NOI18N
LeftButton.setPreferredSize(new java.awt.Dimension(30, 30));
LeftButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
LeftButtonMouseClicked(evt);
@ -95,7 +98,6 @@ public class MainForm extends javax.swing.JFrame {
DownButton.setLabel("");
DownButton.setMinimumSize(new java.awt.Dimension(30, 30));
DownButton.setName("LeftButton"); // NOI18N
DownButton.setPreferredSize(new java.awt.Dimension(30, 30));
DownButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
DownButtonMouseClicked(evt);
@ -111,7 +113,6 @@ public class MainForm extends javax.swing.JFrame {
RightButton.setLabel("");
RightButton.setMinimumSize(new java.awt.Dimension(30, 30));
RightButton.setName("RightButton"); // NOI18N
RightButton.setPreferredSize(new java.awt.Dimension(30, 30));
RightButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RightButtonMouseClicked(evt);
@ -128,11 +129,11 @@ public class MainForm extends javax.swing.JFrame {
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 444, Short.MAX_VALUE)
.addGap(0, 451, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(DrawPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)))
.addComponent(DrawPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -156,7 +157,7 @@ public class MainForm extends javax.swing.JFrame {
}
private void CreateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateButtonMouseClicked
Random rnd = new Random();
_ArmoredVehicle.Init(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
_ArmoredVehicle = new DrawingArmoredVehicle(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
_ArmoredVehicle.SetPosition(rnd.nextInt(0, 100), rnd.nextInt(25, 200),
DrawPanel.getWidth(), DrawPanel.getHeight());
@ -179,6 +180,9 @@ public class MainForm extends javax.swing.JFrame {
}
Draw();
}
public DrawingArmoredVehicle getSelectedCar() {
return SelectedMachine;
}
private void UpButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UpButtonMouseClicked
Move("UpButton");
@ -196,43 +200,21 @@ public class MainForm extends javax.swing.JFrame {
Move("DownButton");
}//GEN-LAST:event_DownButtonMouseClicked
public static void main(String args[]) {
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainForm().setVisible(true);
}
});
}
private void Draw()
private void Draw()
{
Graphics gr = getGraphics();
_ArmoredVehicle.paint(gr);
gr.dispose();
Graphics g = DrawPanel.getGraphics();
g.drawImage(img, 0, 0, this);
}
private void createUIComponents() {
DrawPanel = new JPanel() {
@Override
public void paintComponent(Graphics g) {
Draw();
}
};
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Button CreateButton;
@ -242,6 +224,7 @@ public class MainForm extends javax.swing.JFrame {
private java.awt.TextField PropertyText;
private java.awt.Button RightButton;
private java.awt.Button UpButton;
private javax.swing.JButton jButton1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,232 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="&#x41a;&#x430;&#x440;&#x442;&#x430;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[444, 303]"/>
</Property>
<Property name="name" type="java.lang.String" value="MainFrame" noResource="true"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="482" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Component id="DrawPanel" alignment="1" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="312" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Component id="DrawPanel" alignment="1" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="DrawPanel">
<Events>
<EventHandler event="componentResized" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="DrawPanelComponentResized"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JPanel(){&#xa; Graphics2D g2;}"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="19" pref="19" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="MapComboBox" min="-2" pref="152" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="UpButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="76" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="PropertyText" min="-2" pref="330" max="-2" attributes="0"/>
<EmptySpace min="74" pref="133" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="CreateButton" min="-2" pref="83" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="CreateTankButton" min="-2" pref="132" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="RightButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="49" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="LeftButton" min="-2" pref="22" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
<Component id="DownButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="78" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace pref="210" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="UpButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="MapComboBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="CreateButton" alignment="1" pref="30" max="32767" attributes="0"/>
<Component id="LeftButton" alignment="1" max="32767" attributes="0"/>
<Component id="RightButton" alignment="1" max="32767" attributes="0"/>
<Component id="CreateTankButton" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="PropertyText" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="DownButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="java.awt.TextField" name="PropertyText">
</Component>
<Component class="java.awt.Button" name="CreateButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Create"/>
<Property name="label" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="&quot;&#x421;&#x43e;&#x437;&#x434;&#x430;&#x442;&#x44c;&quot;" type="code"/>
</Property>
<Property name="name" type="java.lang.String" value="CreateButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="CreateButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="UpButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Up"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
</Property>
<Property name="label" type="java.lang.String" value="&#x2191;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="UpButtonMouseClicked"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new java.awt.Button()"/>
<AuxValue name="JavaCodeGenerator_CreateCodePre" type="java.lang.String" value="ImageIcon arrowUp = new ImageIcon(&quot;C:\\Users\\Alena\\Desktop\\New Folder\\JavaApplication4\\src\\Resources\\arrowUp.jpg&quot;);"/>
</AuxValues>
</Component>
<Component class="java.awt.Button" name="LeftButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Left"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="LeftButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="LeftButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="DownButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Left"/>
<Property name="label" type="java.lang.String" value="&#x2193;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="LeftButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="DownButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="RightButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Right"/>
<Property name="label" type="java.lang.String" value="&#x2192;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="RightButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="RightButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="CreateTankButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Create"/>
<Property name="label" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="&quot;&#x41c;&#x43e;&#x434;&#x438;&#x444;&#x438;&#x43a;&#x430;&#x446;&#x438;&#x44f;&quot;" type="code"/>
</Property>
<Property name="name" type="java.lang.String" value="CreateTankButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="CreateTankButtonMouseClicked"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="MapComboBox">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="3">
<StringItem index="0" value="&#x41f;&#x440;&#x43e;&#x441;&#x442;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
<StringItem index="1" value="&#x412;&#x435;&#x440;&#x442;&#x438;&#x43a;&#x430;&#x43b;&#x44c;&#x43d;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
<StringItem index="2" value="&#x413;&#x43e;&#x440;&#x438;&#x437;&#x43e;&#x43d;&#x442;&#x430;&#x43b;&#x44c;&#x43d;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="MapComboBoxActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@ -0,0 +1,337 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MapForm extends JFrame{
private DrawingArmoredVehicle _ArmoredVehicle;
private DrawingArmoredVehicle SelectedMachine;
private AbstractMap abstractMap;
private Image img;
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
DrawPanel = new javax.swing.JPanel(){
Graphics2D g2;};
PropertyText = new java.awt.TextField();
CreateButton = new java.awt.Button();
ImageIcon arrowUp = new ImageIcon("C:\\Users\\Alena\\Desktop\\New Folder\\JavaApplication4\\src\\Resources\\arrowUp.jpg");
UpButton = new java.awt.Button();
LeftButton = new java.awt.Button();
DownButton = new java.awt.Button();
RightButton = new java.awt.Button();
CreateTankButton = new java.awt.Button();
MapComboBox = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Карта");
setMinimumSize(new java.awt.Dimension(444, 303));
setName("MainFrame"); // NOI18N
DrawPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
DrawPanelComponentResized(evt);
}
});
CreateButton.setActionCommand("Create");
CreateButton.setLabel("Создать");
CreateButton.setName("CreateButton"); // NOI18N
CreateButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
CreateButtonMouseClicked(evt);
}
});
UpButton.setActionCommand("Up");
UpButton.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
UpButton.setLabel("");
UpButton.setMinimumSize(new java.awt.Dimension(30, 30));
UpButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
UpButtonMouseClicked(evt);
}
});
LeftButton.setActionCommand("Left");
LeftButton.setMinimumSize(new java.awt.Dimension(30, 30));
LeftButton.setName("LeftButton"); // NOI18N
LeftButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
LeftButtonMouseClicked(evt);
}
});
DownButton.setActionCommand("Left");
DownButton.setLabel("");
DownButton.setMinimumSize(new java.awt.Dimension(30, 30));
DownButton.setName("LeftButton"); // NOI18N
DownButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
DownButtonMouseClicked(evt);
}
});
RightButton.setActionCommand("Right");
RightButton.setLabel("");
RightButton.setMinimumSize(new java.awt.Dimension(30, 30));
RightButton.setName("RightButton"); // NOI18N
RightButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RightButtonMouseClicked(evt);
}
});
CreateTankButton.setActionCommand("Create");
CreateTankButton.setLabel("Модификация");
CreateTankButton.setName("CreateTankButton"); // NOI18N
CreateTankButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
CreateTankButtonMouseClicked(evt);
}
});
MapComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Простая карта", "Вертикальная карта", "Горизонтальная карта" }));
MapComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MapComboBoxActionPerformed(evt);
}
});
javax.swing.GroupLayout DrawPanelLayout = new javax.swing.GroupLayout(DrawPanel);
DrawPanel.setLayout(DrawPanelLayout);
DrawPanelLayout.setHorizontalGroup(
DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(DrawPanelLayout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(DrawPanelLayout.createSequentialGroup()
.addComponent(MapComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(UpButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(76, 76, 76))
.addGroup(DrawPanelLayout.createSequentialGroup()
.addComponent(PropertyText, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(74, 133, Short.MAX_VALUE))
.addGroup(DrawPanelLayout.createSequentialGroup()
.addComponent(CreateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(CreateTankButton, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addComponent(RightButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(49, 49, 49))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addComponent(LeftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1)
.addComponent(DownButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(78, 78, 78))))))
);
DrawPanelLayout.setVerticalGroup(
DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(DrawPanelLayout.createSequentialGroup()
.addContainerGap(210, Short.MAX_VALUE)
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addComponent(UpButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addComponent(MapComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(CreateButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
.addComponent(LeftButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(RightButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(CreateTankButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(PropertyText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addComponent(DownButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(19, 19, 19))))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 482, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(DrawPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 312, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(DrawPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
public MapForm() {
initComponents();
LeftButton.setLabel("<");
RightButton.setLabel(">");
UpButton.setLabel("/\\");
DownButton.setLabel("\\/");
abstractMap = new SimpleMap();
}
private void CreateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateButtonMouseClicked
Random rnd = new Random();
_ArmoredVehicle = new DrawingArmoredVehicle(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
SetData(_ArmoredVehicle);
Draw();
}//GEN-LAST:event_CreateButtonMouseClicked
public void SetData(DrawingArmoredVehicle machine)
{
if (abstractMap != null)
img = abstractMap.CreateMap(DrawPanel.getWidth(), DrawPanel.getHeight(),
new DrawingObject(machine));
Random rnd = new Random();
_ArmoredVehicle.SetPosition((int)_ArmoredVehicle._startPosX, (int)_ArmoredVehicle._startPosY,
DrawPanel.getWidth(), DrawPanel.getHeight());
PropertyText.setText("Скорость: " + _ArmoredVehicle.ArmoredVehicle.Speed +
" Вес: "+_ArmoredVehicle.ArmoredVehicle.Weight +
" Цвет: "+_ArmoredVehicle.ArmoredVehicle.BodyColor.getRGB()+
" Катков: "+_ArmoredVehicle.Count);
}
public DrawingArmoredVehicle getSelectedCar() {
return SelectedMachine;
}
public void Move(String name)
{
switch (name)
{
case "UpButton" -> img = abstractMap.MoveObject(Direction.Up);
case "DownButton" -> img = abstractMap.MoveObject(Direction.Down);
case "LeftButton" -> img = abstractMap.MoveObject(Direction.Left);
case "RightButton" -> img = abstractMap.MoveObject(Direction.Right);
}
Draw();
}
private void UpButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UpButtonMouseClicked
Move("UpButton");
}//GEN-LAST:event_UpButtonMouseClicked
private void LeftButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_LeftButtonMouseClicked
Move("LeftButton");
}//GEN-LAST:event_LeftButtonMouseClicked
private void RightButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RightButtonMouseClicked
Move("RightButton");
}//GEN-LAST:event_RightButtonMouseClicked
private void DownButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DownButtonMouseClicked
Move("DownButton");
}//GEN-LAST:event_DownButtonMouseClicked
private void DrawPanelComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_DrawPanelComponentResized
if (_ArmoredVehicle != null) {
_ArmoredVehicle.ChangeBorders(DrawPanel.getWidth(), DrawPanel.getHeight());
DrawPanel.repaint();
}
}//GEN-LAST:event_DrawPanelComponentResized
private void CreateTankButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateTankButtonMouseClicked
Random rnd = new Random();
_ArmoredVehicle = new DrawingTank(rnd.nextInt(100, 300),
rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
new Color(rnd.nextInt(50, 256), rnd.nextInt(0, 256), rnd.nextInt(20, 256)),
1==rnd.nextInt(0, 2), 1==rnd.nextInt(0, 2));
SetData(_ArmoredVehicle);
Draw();
}//GEN-LAST:event_CreateTankButtonMouseClicked
private void MapComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MapComboBoxActionPerformed
String name = (String) MapComboBox.getSelectedItem();
switch (name)
{
case "Простая карта":
abstractMap = new SimpleMap();
break;
case "Горизонтальная карта":
abstractMap = new HorizontalMap();
break;
case "Вертикальная карта":
abstractMap = new VerticalMap();
break;
}
}//GEN-LAST:event_MapComboBoxActionPerformed
private void Draw()
{
Graphics g = DrawPanel.getGraphics();
g.drawImage(img, 0, 0, this);
}
private void createUIComponents() {
DrawPanel = new JPanel() {
@Override
public void paintComponent(Graphics g) {
Draw();
}
};
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MapForm().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Button CreateButton;
private java.awt.Button CreateTankButton;
private java.awt.Button DownButton;
private javax.swing.JPanel DrawPanel;
private java.awt.Button LeftButton;
private javax.swing.JComboBox<String> MapComboBox;
private java.awt.TextField PropertyText;
private java.awt.Button RightButton;
private java.awt.Button UpButton;
// End of variables declaration//GEN-END:variables
}

View File

@ -2,73 +2,47 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
public class Roller extends JPanel{
/// <summary>
/// Количество катоков
/// </summary>
public int _count;
/// <summary>
/// Цвет
/// </summary>
private Color _color;
/// <summary>
/// Левая координата отрисовки
/// </summary>
private float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки
/// </summary>
private float _startPosY;
/// <summary>
/// Ширина поля под катки
/// </summary>
private float _Width;
/// <summary>
/// Перечисление
/// </summary>
private CountRollers rolls;
public void Init(int Count, Color color, float startPosX, float startPosY, float Width)
public class Roller implements IDrawingRoller {
private Color color;
private CountRollers rolls;
public Roller(Color bodyColor)
{
color = bodyColor;
}
@Override
public void setCount(int c)
{
switch (c)
{
_count = Count;
_color = color;
_startPosX = startPosX;
_startPosY = startPosY;
_Width = Width;
Count(_count);
}
private void Count(int c)
{
switch (c)
{
case 4 -> rolls = CountRollers.Four;
case 5 -> rolls = CountRollers.Five;
case 6 -> rolls = CountRollers.Six;
}
}
public void paint(Graphics gr)
case 4 -> rolls = CountRollers.Four;
case 5 -> rolls = CountRollers.Five;
case 6 -> rolls = CountRollers.Six;
default -> {
break;
}
}
}
@Override
public void DrawRoller(Graphics2D gr, int startPosX, int startPosY, int Width, int count)
{
setCount(count);
Graphics2D g = (Graphics2D) gr;
Color color = _color != null ?
_color : Color.BLACK;
color = color != null ? color : Color.BLACK;
g.setColor(color);
//g.setColor(Color.BLUE);
int count = 0;
switch (rolls)
{
case Four -> count = 4;
case Five -> count = 5;
case Six -> count = 6;
}
int ras = (int)_Width /count;
int ras = (int)Width /count;
for (int i = 0; i < count; i += 1)
{
g.drawOval((int)_startPosX+ i*ras + 15, (int)_startPosY + 35, 20, 20);
g.drawOval((int)startPosX+ i*ras + 15, (int)startPosY + 35, 20, 20);
}
g.dispose();
}
}

View File

@ -0,0 +1,43 @@
import java.awt.*;
public class SimpleMap extends AbstractMap{
private final Color barrierColor = Color.RED;
private final Color roadColor = Color.WHITE;
@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(100);
int y = random.nextInt(100);
if (map[x][y] == _freeRoad)
{
map[x][y] = _barrier;
counter++;
}
}
}
@Override
protected void DrawRoadPart(Graphics2D gc, int i, int j) {
gc.setColor(Color.GRAY);
gc.fillRect(i * (int)size_x, j * (int)size_y, i * ((int)size_x + 1), j * ((int)size_y + 1));
}
@Override
protected void DrawBarrierPart(Graphics2D gc, int i, int j) {
gc.setColor(Color.BLACK);
gc.fillRect(i * (int)size_x, j * (int)size_y, i * ((int)size_x + 1), j * ((int)size_y + 1));
}
}

View File

@ -0,0 +1,37 @@
import java.awt.Color;
public class TankEntity extends ArmoredVehicleEntity {
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="MachineGun">Признак наличия пулемета</param>
/// <param name="Tower">Признак наличия башни</param>
/// <param name="Gun">Признак наличия орудия</param>
public TankEntity(int speed, float weight, Color bodyColor, Color dopColor,
boolean machineGun, boolean tower)
{
super(speed, weight, bodyColor);
DopColor = dopColor;
MachineGun = machineGun;
Tower = tower;
}
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor;
/// <summary>
/// Признак наличия пулемета
/// </summary>
public boolean MachineGun;
/// <summary>
/// Признак наличия башни
/// </summary>
public boolean Tower;
}

View File

@ -0,0 +1,55 @@
import java.awt.Color;
import java.awt.Graphics2D;
public class VerticalMap extends AbstractMap{
private final Color barrierColor = Color.BLUE;
private final Color roadColor = Color.WHITE;
@Override
protected void GenerateMap() {
map = new int[50][50];
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 < 7)
{
int x1 = random.nextInt(12);
int x2 = random.nextInt(12, map[0].length);
int y1 = random.nextInt(12, map[1].length);
for (int i = x1; i < x2; i++)
{
if (map[y1][i] == _freeRoad)
{
map[y1][i] = _barrier;
}
}
counter++;
}
}
@Override
protected void DrawRoadPart(Graphics2D gc, int i, int j) {
gc.setColor(roadColor);
gc.fillRect(i * (int)size_x, j * (int)size_y, i * ((int)size_x + 1), j * ((int)size_y + 1));
}
@Override
protected void DrawBarrierPart(Graphics2D gc, int i, int j) {
gc.setColor(barrierColor);
gc.fillRect(i * (int)size_x, j * (int)size_y, i * ((int)size_x + 1), j * ((int)size_y + 1));
}
}