Compare commits
25 Commits
master
...
83e4d9574f
Author | SHA1 | Date | |
---|---|---|---|
83e4d9574f | |||
76c34b75ae | |||
6a8da78193 | |||
2049d2222b | |||
a42103499a | |||
b25aaeb081 | |||
|
c1dbdd80ed | ||
66371369da | |||
5ffa496f6f | |||
8894238c90 | |||
f803dc89dd | |||
ccd57fad9b | |||
5965acca14 | |||
d8c763c582 | |||
a0ffa4e205 | |||
396df2c24c | |||
ceea6b5010 | |||
5de212b434 | |||
a97a85a7a2 | |||
e84730b951 | |||
cf030e5d6b | |||
0b3de31bdb | |||
fbd570c22d | |||
40820059a5 | |||
d9e184ca89 |
126
SelfPropelledArtilleryUnit/AbstractMap.cs
Normal file
126
SelfPropelledArtilleryUnit/AbstractMap.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
{
|
||||
private IDrawingObject _drawingObject = null;
|
||||
protected int[,] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected readonly Random _random = new Random();
|
||||
protected readonly int _freeRoad = 0;
|
||||
protected readonly int _barrier = 1;
|
||||
|
||||
public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawingObject = drawingObject;
|
||||
do
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
while (!SetObjectOnMap());
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
_drawingObject.MoveObject(direction);
|
||||
if (ObjectIntersects())
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Left:
|
||||
_drawingObject.MoveObject(Direction.Right);
|
||||
break;
|
||||
case Direction.Right:
|
||||
_drawingObject.MoveObject(Direction.Left);
|
||||
break;
|
||||
case Direction.Up:
|
||||
_drawingObject.MoveObject(Direction.Down);
|
||||
break;
|
||||
case Direction.Down:
|
||||
_drawingObject.MoveObject(Direction.Up);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 2; i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 2; j < _map.GetLength(1); j++)
|
||||
{
|
||||
_drawingObject.SetObject((int) (i * _size_x), (int) (j * _size_y), _width, _height);
|
||||
if (!ObjectIntersects()) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ObjectIntersects()
|
||||
{
|
||||
var location = _drawingObject.GetCurrentPosition();
|
||||
for (int i = 0; i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
if (i * _size_x >= location.Left && (i + 1) * _size_x <= location.Right && j * _size_y >= location.Top && (j + 1) * _size_y <= location.Bottom)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Bitmap DrawMapWithObject()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(_width, _height);
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics g = Graphics.FromImage(bmp);
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++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(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
||||
}
|
@ -6,11 +6,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4
|
||||
Right = 4,
|
||||
None
|
||||
}
|
||||
}
|
||||
|
42
SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs
Normal file
42
SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class DrawingAdvancedArtillery : DrawingArtillery
|
||||
{
|
||||
public DrawingAdvancedArtillery(int speed, float weight, Color bodyColor, Color dopColor, bool weapon, bool salvoBattery) : base(speed, weight, bodyColor, 80, 50)
|
||||
{
|
||||
Artillery = new EntityAdvancedArtillery(speed, weight, bodyColor, dopColor, weapon, salvoBattery);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Artillery is not EntityAdvancedArtillery advancedArtillery)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(advancedArtillery.DopColor, 8);
|
||||
Brush brush = new SolidBrush(advancedArtillery.DopColor);
|
||||
|
||||
if (advancedArtillery.Weapon)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX + _artilleryWidth / 2, _startPosY + _artilleryHeight / 10, _startPosX + _artilleryWidth, _startPosY);
|
||||
}
|
||||
pen.Width = 6;
|
||||
if (advancedArtillery.SalvoBattery)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX + _artilleryWidth / 4, _startPosY + _artilleryHeight / 4, _startPosX + _artilleryWidth / 4 + _artilleryHeight / 4, _startPosY - 5);
|
||||
g.DrawLine(pen, _startPosX + _artilleryWidth / 4 - _artilleryHeight / 4, _startPosY + _artilleryHeight / 4, _startPosX + _artilleryWidth / 4, _startPosY - 5);
|
||||
g.DrawLine(pen, _startPosX + _artilleryWidth / 4 - _artilleryHeight / 2, _startPosY + _artilleryHeight / 4, _startPosX + _artilleryWidth / 4 - _artilleryHeight / 4, _startPosY - 5);
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class DrawingArtillery
|
||||
public class DrawingArtillery
|
||||
{
|
||||
public EntityArtillery Artillery { private set; get; }
|
||||
private float _startPosX;
|
||||
private float _startPosY;
|
||||
public EntityArtillery Artillery { protected set; get; }
|
||||
protected float _startPosX;
|
||||
protected float _startPosY;
|
||||
private int? _pictureWidth = null;
|
||||
private int? _pictureHeight = null;
|
||||
private readonly int _artilleryWidth = 80;
|
||||
private readonly int _artilleryHeight = 50;
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
protected readonly int _artilleryWidth = 80;
|
||||
protected readonly int _artilleryHeight = 50;
|
||||
|
||||
public DrawingArtillery(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Artillery = new EntityArtillery();
|
||||
Artillery.Init(speed, weight, bodyColor);
|
||||
Artillery = new EntityArtillery(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
protected DrawingArtillery(int speed, float weight, Color bodyColor, int artilleryWidth, int artilleryHeight) : this(speed, weight, bodyColor)
|
||||
{
|
||||
_artilleryWidth = artilleryWidth;
|
||||
_artilleryHeight = artilleryHeight;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x < 0 || x + _artilleryWidth >= width)
|
||||
@ -74,14 +83,14 @@ namespace Artilleries
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Brush brush = new SolidBrush(Artillery?.BodyColor ?? Color.Black);
|
||||
g.FillRectangle(brush, _startPosX + _artilleryWidth / 8 * 2, _startPosY, _artilleryWidth / 8 * 4, _artilleryWidth / 5);
|
||||
g.FillRectangle(brush, _startPosX + _artilleryWidth / 8 * 2, _startPosY, _artilleryWidth / 8 * 4, _artilleryHeight / 5);
|
||||
g.FillRectangle(brush, _startPosX, _startPosY + _artilleryHeight / 5, _artilleryWidth, _artilleryHeight / 3);
|
||||
|
||||
Brush blackBrush = new SolidBrush(Color.Black);
|
||||
@ -114,5 +123,10 @@ namespace Artilleries
|
||||
_startPosY = _pictureHeight.Value - _artilleryHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosX + _artilleryWidth - 1, _startPosY, _startPosY + _artilleryHeight - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs
Normal file
40
SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class DrawingObjectArtillery : IDrawingObject
|
||||
{
|
||||
private DrawingArtillery _artillery = null;
|
||||
|
||||
public DrawingObjectArtillery(DrawingArtillery artillery)
|
||||
{
|
||||
_artillery = artillery;
|
||||
}
|
||||
|
||||
public float Step => _artillery?.Artillery?.Step ?? 0;
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _artillery?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_artillery?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_artillery.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
public void DrawingObject(Graphics g)
|
||||
{
|
||||
_artillery.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
21
SelfPropelledArtilleryUnit/EntityAdvancedArtillery.cs
Normal file
21
SelfPropelledArtilleryUnit/EntityAdvancedArtillery.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class EntityAdvancedArtillery : EntityArtillery
|
||||
{
|
||||
public Color DopColor { get; private set; }
|
||||
public bool Weapon { get; private set; }
|
||||
public bool SalvoBattery { get; private set; }
|
||||
public EntityAdvancedArtillery(int speed, float weight, Color bodyColor, Color dopColor, bool weapon, bool salvoBattery) : base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Weapon = weapon;
|
||||
SalvoBattery = salvoBattery;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,13 +6,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class EntityArtillery
|
||||
public class EntityArtillery
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public float Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public float Step => Speed * 100 / Weight;
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityArtillery(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
|
53
SelfPropelledArtilleryUnit/ForestMap.cs
Normal file
53
SelfPropelledArtilleryUnit/ForestMap.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class ForestMap : AbstractMap
|
||||
{
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Green);
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Brown);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[50, 50];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 20)
|
||||
{
|
||||
int x = _random.Next(2, 49);
|
||||
int y = _random.Next(3, 50);
|
||||
var points = new int[] { _map[x, y], _map[x, y - 1], _map[x, y - 2], _map[x - 1, y - 2], _map[x + 1, y - 2], _map[x, y - 3] };
|
||||
var forComparison = new int[] { _freeRoad, _freeRoad, _freeRoad, _freeRoad, _freeRoad, _freeRoad };
|
||||
if (points.SequenceEqual(forComparison))
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
_map[x, y - 1] = _barrier;
|
||||
_map[x, y - 2] = _barrier;
|
||||
_map[x - 1, y - 2] = _barrier;
|
||||
_map[x + 1, y - 2] = _barrier;
|
||||
_map[x, y - 3] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
28
SelfPropelledArtilleryUnit/FormArtillery.Designer.cs
generated
28
SelfPropelledArtilleryUnit/FormArtillery.Designer.cs
generated
@ -39,6 +39,8 @@
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.createAdvancedButton = new System.Windows.Forms.Button();
|
||||
this.selectArtilleryButton = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -147,11 +149,35 @@
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// createAdvancedButton
|
||||
//
|
||||
this.createAdvancedButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.createAdvancedButton.Location = new System.Drawing.Point(106, 382);
|
||||
this.createAdvancedButton.Name = "createAdvancedButton";
|
||||
this.createAdvancedButton.Size = new System.Drawing.Size(113, 23);
|
||||
this.createAdvancedButton.TabIndex = 7;
|
||||
this.createAdvancedButton.Text = "Модифицировать";
|
||||
this.createAdvancedButton.UseVisualStyleBackColor = true;
|
||||
this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_Click);
|
||||
//
|
||||
// selectArtilleryButton
|
||||
//
|
||||
this.selectArtilleryButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.selectArtilleryButton.Location = new System.Drawing.Point(410, 379);
|
||||
this.selectArtilleryButton.Name = "selectArtilleryButton";
|
||||
this.selectArtilleryButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.selectArtilleryButton.TabIndex = 8;
|
||||
this.selectArtilleryButton.Text = "Выбрать";
|
||||
this.selectArtilleryButton.UseVisualStyleBackColor = true;
|
||||
this.selectArtilleryButton.Click += new System.EventHandler(this.selectArtilleryButton_Click);
|
||||
//
|
||||
// FormArtillery
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(624, 441);
|
||||
this.Controls.Add(this.selectArtilleryButton);
|
||||
this.Controls.Add(this.createAdvancedButton);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
@ -183,5 +209,7 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button createAdvancedButton;
|
||||
private Button selectArtilleryButton;
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ namespace Artilleries
|
||||
{
|
||||
private DrawingArtillery _artillery;
|
||||
|
||||
public DrawingArtillery SelectedArtillery { get; private set; }
|
||||
|
||||
public FormArtillery()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -17,15 +19,53 @@ namespace Artilleries
|
||||
pictureBoxArtilleries.Image = bmp;
|
||||
}
|
||||
|
||||
private void SetData(DrawingArtillery artillery)
|
||||
{
|
||||
Random rnd = new();
|
||||
artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
|
||||
SpeedStatusLabel.Text = $"Ñêîðîñòü: {artillery.Artillery.Speed}";
|
||||
WeightStatusLabel.Text = $"Âåñ: {artillery.Artillery.Weight}";
|
||||
ColorStatusLabel.Text = $"Öâåò: {artillery.Artillery.BodyColor.Name}";
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_artillery = new DrawingArtillery();
|
||||
_artillery.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_artillery.SetPosition(rnd.Next(pictureBoxArtilleries.Width - 161, pictureBoxArtilleries.Width - 81), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
|
||||
SpeedStatusLabel.Text = $"Скорость: {_artillery.Artillery.Speed}";
|
||||
WeightStatusLabel.Text = $"Вес: {_artillery.Artillery.Weight}";
|
||||
ColorStatusLabel.Text = $"Цвет: {_artillery.Artillery.BodyColor.Name}";
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_artillery = new DrawingArtillery(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||
SetData(_artillery);
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void createAdvancedButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialogDop = new();
|
||||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialogDop.Color;
|
||||
}
|
||||
_artillery = new DrawingAdvancedArtillery(
|
||||
rnd.Next(100, 300),
|
||||
rnd.Next(1000, 2000),
|
||||
color,
|
||||
dopColor,
|
||||
rnd.Next(0, 2) == 1, rnd.Next(0, 2) == 1
|
||||
);
|
||||
SetData(_artillery);
|
||||
Draw();
|
||||
}
|
||||
|
||||
@ -55,5 +95,11 @@ namespace Artilleries
|
||||
_artillery?.ChangeBorders(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void selectArtilleryButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedArtillery = _artillery;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
279
SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.Designer.cs
generated
Normal file
279
SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.Designer.cs
generated
Normal file
@ -0,0 +1,279 @@
|
||||
namespace Artilleries
|
||||
{
|
||||
partial class FormMapWithSetArtilleries
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.toolsGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.mapsGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonRemoveArtillery = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonAddArtillery = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.pictureBoxArtilleries = new System.Windows.Forms.PictureBox();
|
||||
this.toolsGroupBox.SuspendLayout();
|
||||
this.mapsGroupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// toolsGroupBox
|
||||
//
|
||||
this.toolsGroupBox.Controls.Add(this.mapsGroupBox);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonShowOnMap);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonShowStorage);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonRemoveArtillery);
|
||||
this.toolsGroupBox.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonAddArtillery);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonRight);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonDown);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonUp);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonLeft);
|
||||
this.toolsGroupBox.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.toolsGroupBox.Location = new System.Drawing.Point(600, 0);
|
||||
this.toolsGroupBox.Name = "toolsGroupBox";
|
||||
this.toolsGroupBox.Size = new System.Drawing.Size(200, 596);
|
||||
this.toolsGroupBox.TabIndex = 0;
|
||||
this.toolsGroupBox.TabStop = false;
|
||||
this.toolsGroupBox.Text = "Инструменты";
|
||||
//
|
||||
// mapsGroupBox
|
||||
//
|
||||
this.mapsGroupBox.Controls.Add(this.buttonDeleteMap);
|
||||
this.mapsGroupBox.Controls.Add(this.listBoxMaps);
|
||||
this.mapsGroupBox.Controls.Add(this.buttonAddMap);
|
||||
this.mapsGroupBox.Controls.Add(this.textBoxNewMapName);
|
||||
this.mapsGroupBox.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.mapsGroupBox.Location = new System.Drawing.Point(6, 22);
|
||||
this.mapsGroupBox.Name = "mapsGroupBox";
|
||||
this.mapsGroupBox.Size = new System.Drawing.Size(188, 258);
|
||||
this.mapsGroupBox.TabIndex = 25;
|
||||
this.mapsGroupBox.TabStop = false;
|
||||
this.mapsGroupBox.Text = "Карты";
|
||||
//
|
||||
// buttonDeleteMap
|
||||
//
|
||||
this.buttonDeleteMap.Location = new System.Drawing.Point(12, 218);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(170, 32);
|
||||
this.buttonDeleteMap.TabIndex = 26;
|
||||
this.buttonDeleteMap.Text = "Удалить карту";
|
||||
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.ItemHeight = 15;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(12, 118);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(170, 94);
|
||||
this.listBoxMaps.TabIndex = 27;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// buttonAddMap
|
||||
//
|
||||
this.buttonAddMap.Location = new System.Drawing.Point(12, 80);
|
||||
this.buttonAddMap.Name = "buttonAddMap";
|
||||
this.buttonAddMap.Size = new System.Drawing.Size(170, 32);
|
||||
this.buttonAddMap.TabIndex = 26;
|
||||
this.buttonAddMap.Text = "Добавить карту";
|
||||
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(12, 22);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(170, 23);
|
||||
this.textBoxNewMapName.TabIndex = 0;
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Лесная карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 51);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(170, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 19;
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(13, 470);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 32);
|
||||
this.buttonShowOnMap.TabIndex = 24;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(13, 423);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 32);
|
||||
this.buttonShowStorage.TabIndex = 23;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
|
||||
//
|
||||
// buttonRemoveArtillery
|
||||
//
|
||||
this.buttonRemoveArtillery.Location = new System.Drawing.Point(13, 376);
|
||||
this.buttonRemoveArtillery.Name = "buttonRemoveArtillery";
|
||||
this.buttonRemoveArtillery.Size = new System.Drawing.Size(175, 32);
|
||||
this.buttonRemoveArtillery.TabIndex = 22;
|
||||
this.buttonRemoveArtillery.Text = "Удалить артиллерию";
|
||||
this.buttonRemoveArtillery.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveArtillery.Click += new System.EventHandler(this.buttonRemoveArtillery_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(13, 347);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
||||
this.maskedTextBoxPosition.TabIndex = 21;
|
||||
//
|
||||
// buttonAddArtillery
|
||||
//
|
||||
this.buttonAddArtillery.Location = new System.Drawing.Point(13, 309);
|
||||
this.buttonAddArtillery.Name = "buttonAddArtillery";
|
||||
this.buttonAddArtillery.Size = new System.Drawing.Size(175, 32);
|
||||
this.buttonAddArtillery.TabIndex = 20;
|
||||
this.buttonAddArtillery.Text = "Добавить артиллерию";
|
||||
this.buttonAddArtillery.UseVisualStyleBackColor = true;
|
||||
this.buttonAddArtillery.Click += new System.EventHandler(this.buttonAddArtillery_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(124, 545);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 18;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(88, 545);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 17;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(88, 512);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 16;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(54, 545);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 15;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// pictureBoxArtilleries
|
||||
//
|
||||
this.pictureBoxArtilleries.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxArtilleries.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxArtilleries.Name = "pictureBoxArtilleries";
|
||||
this.pictureBoxArtilleries.Size = new System.Drawing.Size(600, 596);
|
||||
this.pictureBoxArtilleries.TabIndex = 1;
|
||||
this.pictureBoxArtilleries.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetArtilleries
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 596);
|
||||
this.Controls.Add(this.pictureBoxArtilleries);
|
||||
this.Controls.Add(this.toolsGroupBox);
|
||||
this.Name = "FormMapWithSetArtilleries";
|
||||
this.Text = "Artillery";
|
||||
this.toolsGroupBox.ResumeLayout(false);
|
||||
this.toolsGroupBox.PerformLayout();
|
||||
this.mapsGroupBox.ResumeLayout(false);
|
||||
this.mapsGroupBox.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox toolsGroupBox;
|
||||
private PictureBox pictureBoxArtilleries;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private Button buttonShowOnMap;
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonRemoveArtillery;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonAddArtillery;
|
||||
private GroupBox mapsGroupBox;
|
||||
private Button buttonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private Button buttonAddMap;
|
||||
private TextBox textBoxNewMapName;
|
||||
}
|
||||
}
|
183
SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs
Normal file
183
SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs
Normal file
@ -0,0 +1,183 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.DataFormats;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
public partial class FormMapWithSetArtilleries : Form
|
||||
{
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Простая карта", new SimpleMap() },
|
||||
{ "Лесная карта", new ForestMap() }
|
||||
};
|
||||
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
|
||||
public FormMapWithSetArtilleries()
|
||||
{
|
||||
InitializeComponent();
|
||||
_mapsCollection = new MapsCollection(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
foreach(var element in _mapsDict)
|
||||
{
|
||||
comboBoxSelectorMap.Items.Add(element.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReloadMaps()
|
||||
{
|
||||
int index = listBoxMaps.SelectedIndex;
|
||||
|
||||
listBoxMaps.Items.Clear();
|
||||
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||
{
|
||||
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||
}
|
||||
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||
{
|
||||
listBoxMaps.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||
{
|
||||
listBoxMaps.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAddMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||
{
|
||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||
ReloadMaps();
|
||||
}
|
||||
|
||||
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void buttonDeleteMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAddArtillery_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormArtillery form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawingObjectArtillery artillery = new(form.SelectedArtillery);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + artillery != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonRemoveArtillery_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void buttonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
60
SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.resx
Normal file
60
SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
17
SelfPropelledArtilleryUnit/IDrawingObject.cs
Normal file
17
SelfPropelledArtilleryUnit/IDrawingObject.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal interface IDrawingObject
|
||||
{
|
||||
public float Step { get; }
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
void MoveObject(Direction direction);
|
||||
void DrawingObject(Graphics g);
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
}
|
||||
}
|
128
SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs
Normal file
128
SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class MapWithSetArtilleriesGeneric<T, U>
|
||||
where T : class, IDrawingObject
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
private readonly SetArtilleriesGeneric<T> _setArtilleries;
|
||||
private readonly U _map;
|
||||
|
||||
public MapWithSetArtilleriesGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setArtilleries = new SetArtilleriesGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public static int operator +(MapWithSetArtilleriesGeneric<T, U> map, T artillery)
|
||||
{
|
||||
return map._setArtilleries.Insert(artillery);
|
||||
}
|
||||
|
||||
public static T operator -(MapWithSetArtilleriesGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setArtilleries.Remove(position);
|
||||
}
|
||||
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawArtilleries(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
foreach (var artillery in _setArtilleries.GetArtilleries())
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, artillery);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setArtilleries.Count - 1;
|
||||
for (int i = 0; i < _setArtilleries.Count; i++)
|
||||
{
|
||||
if (_setArtilleries[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setArtilleries[j];
|
||||
if (car != null)
|
||||
{
|
||||
_setArtilleries.Insert(car, i);
|
||||
_setArtilleries.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
Brush boxBrush = new SolidBrush(Color.DarkGreen);
|
||||
Pen thinPen = new Pen(Color.Black, 2);
|
||||
Brush flagBrush = new SolidBrush(Color.Red);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
g.FillRectangle(boxBrush, i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5, _placeSizeWidth / 3 - 5, _placeSizeHeight / 3 - 5);
|
||||
g.DrawLine(thinPen, i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 + _placeSizeHeight / 3 - 10);
|
||||
g.DrawLine(thinPen, i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 + _placeSizeHeight / 3 - 10, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5);
|
||||
g.FillRectangle(flagBrush, i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight * 5 / 8 - 5, _placeSizeWidth / 5, _placeSizeHeight / 5);
|
||||
g.DrawLine(thinPen, i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight - 5, i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight * 5 / 8 - 5);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawArtilleries(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int index = 0;
|
||||
foreach (var artillery in _setArtilleries.GetArtilleries())
|
||||
{
|
||||
artillery.SetObject(index % width * _placeSizeWidth + 10, (height - 1 - index / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
artillery.DrawingObject(g);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
SelfPropelledArtilleryUnit/MapsCollection.cs
Normal file
48
SelfPropelledArtilleryUnit/MapsCollection.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
readonly Dictionary<string, MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap>> _mapsStorage;
|
||||
public List<string> Keys => _mapsStorage.Keys.ToList();
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapsStorage = new Dictionary<string, MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (!_mapsStorage.ContainsKey(name))
|
||||
{
|
||||
_mapsStorage.Add(name, new MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
}
|
||||
|
||||
public void DelMap(string name)
|
||||
{
|
||||
if (_mapsStorage.ContainsKey(name))
|
||||
{
|
||||
_mapsStorage.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap> this[string index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mapsStorage.ContainsKey(index) ? _mapsStorage[index] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ namespace Artilleries
|
||||
static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormArtillery());
|
||||
Application.Run(new FormMapWithSetArtilleries());
|
||||
}
|
||||
}
|
||||
}
|
87
SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs
Normal file
87
SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class SetArtilleriesGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly List<T> _places;
|
||||
public int Count => _places.Count;
|
||||
private readonly int _maxCount;
|
||||
|
||||
public SetArtilleriesGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
|
||||
public int Insert(T artillery)
|
||||
{
|
||||
return Insert(artillery, 0);
|
||||
}
|
||||
|
||||
public int Insert(T artillery, int position)
|
||||
{
|
||||
if (position < 0 || position > Count || Count == _maxCount)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
_places.Insert(position, artillery);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var result = _places[position];
|
||||
|
||||
_places.RemoveAt(position);
|
||||
return result;
|
||||
}
|
||||
|
||||
public T this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position >= 0 && position < Count)
|
||||
{
|
||||
Insert(value, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetArtilleries()
|
||||
{
|
||||
foreach (var artillery in _places)
|
||||
{
|
||||
if (artillery != null)
|
||||
{
|
||||
yield return artillery;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
46
SelfPropelledArtilleryUnit/SimpleMap.cs
Normal file
46
SelfPropelledArtilleryUnit/SimpleMap.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class SimpleMap : AbstractMap
|
||||
{
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user