Compare commits

..

1 Commits

18 changed files with 22 additions and 1078 deletions

View File

@ -1,126 +0,0 @@
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);
}
}

View File

@ -6,12 +6,11 @@ using System.Threading.Tasks;
namespace Artilleries namespace Artilleries
{ {
public enum Direction internal enum Direction
{ {
Up = 1, Up = 1,
Down = 2, Down = 2,
Left = 3, Left = 3,
Right = 4, Right = 4
None
} }
} }

View File

@ -1,42 +0,0 @@
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);
}
}
}

View File

@ -1,34 +1,25 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Artilleries namespace Artilleries
{ {
public class DrawingArtillery internal class DrawingArtillery
{ {
public EntityArtillery Artillery { protected set; get; } public EntityArtillery Artillery { private set; get; }
protected float _startPosX; private float _startPosX;
protected float _startPosY; private float _startPosY;
private int? _pictureWidth = null; private int? _pictureWidth = null;
private int? _pictureHeight = null; private int? _pictureHeight = null;
protected readonly int _artilleryWidth = 80; private readonly int _artilleryWidth = 80;
protected readonly int _artilleryHeight = 50; private readonly int _artilleryHeight = 50;
public void Init(int speed, float weight, Color bodyColor)
public DrawingArtillery(int speed, float weight, Color bodyColor)
{ {
Artillery = new EntityArtillery(speed, weight, bodyColor); Artillery = new EntityArtillery();
Artillery.Init(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) public void SetPosition(int x, int y, int width, int height)
{ {
if (x < 0 || x + _artilleryWidth >= width) if (x < 0 || x + _artilleryWidth >= width)
@ -83,14 +74,14 @@ namespace Artilleries
} }
} }
public virtual void DrawTransport(Graphics g) public void DrawTransport(Graphics g)
{ {
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{ {
return; return;
} }
Brush brush = new SolidBrush(Artillery?.BodyColor ?? Color.Black); Brush brush = new SolidBrush(Artillery?.BodyColor ?? Color.Black);
g.FillRectangle(brush, _startPosX + _artilleryWidth / 8 * 2, _startPosY, _artilleryWidth / 8 * 4, _artilleryHeight / 5); g.FillRectangle(brush, _startPosX + _artilleryWidth / 8 * 2, _startPosY, _artilleryWidth / 8 * 4, _artilleryWidth / 5);
g.FillRectangle(brush, _startPosX, _startPosY + _artilleryHeight / 5, _artilleryWidth, _artilleryHeight / 3); g.FillRectangle(brush, _startPosX, _startPosY + _artilleryHeight / 5, _artilleryWidth, _artilleryHeight / 3);
Brush blackBrush = new SolidBrush(Color.Black); Brush blackBrush = new SolidBrush(Color.Black);
@ -123,10 +114,5 @@ namespace Artilleries
_startPosY = _pictureHeight.Value - _artilleryHeight; _startPosY = _pictureHeight.Value - _artilleryHeight;
} }
} }
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosX + _artilleryWidth - 1, _startPosY, _startPosY + _artilleryHeight - 1);
}
} }
} }

View File

@ -1,40 +0,0 @@
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);
}
}
}

View File

@ -1,21 +0,0 @@
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;
}
}
}

View File

@ -6,13 +6,13 @@ using System.Threading.Tasks;
namespace Artilleries namespace Artilleries
{ {
public class EntityArtillery internal class EntityArtillery
{ {
public int Speed { get; private set; } public int Speed { get; private set; }
public float Weight { get; private set; } public float Weight { get; private set; }
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
public float Step => Speed * 100 / Weight; public float Step => Speed * 100 / Weight;
public EntityArtillery(int speed, float weight, Color bodyColor) public void Init(int speed, float weight, Color bodyColor)
{ {
Random rnd = new(); Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed; Speed = speed <= 0 ? rnd.Next(50, 150) : speed;

View File

@ -1,53 +0,0 @@
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++;
}
}
}
}
}

View File

@ -39,8 +39,6 @@
this.buttonUp = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = 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(); this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -149,35 +147,11 @@
this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); 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 // FormArtillery
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(624, 441); 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.buttonRight);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonUp);
@ -209,7 +183,5 @@
private Button buttonUp; private Button buttonUp;
private Button buttonDown; private Button buttonDown;
private Button buttonRight; private Button buttonRight;
private Button createAdvancedButton;
private Button selectArtilleryButton;
} }
} }

View File

@ -4,8 +4,6 @@ namespace Artilleries
{ {
private DrawingArtillery _artillery; private DrawingArtillery _artillery;
public DrawingArtillery SelectedArtillery { get; private set; }
public FormArtillery() public FormArtillery()
{ {
InitializeComponent(); InitializeComponent();
@ -19,53 +17,15 @@ namespace Artilleries
pictureBoxArtilleries.Image = bmp; 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) private void buttonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); _artillery = new DrawingArtillery();
ColorDialog dialog = new(); _artillery.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
if (dialog.ShowDialog() == DialogResult.OK) _artillery.SetPosition(rnd.Next(pictureBoxArtilleries.Width - 161, pictureBoxArtilleries.Width - 81), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
{ SpeedStatusLabel.Text = $"Скорость: {_artillery.Artillery.Speed}";
color = dialog.Color; WeightStatusLabel.Text = $"Вес: {_artillery.Artillery.Weight}";
} ColorStatusLabel.Text = $"Цвет: {_artillery.Artillery.BodyColor.Name}";
_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(); Draw();
} }
@ -95,11 +55,5 @@ namespace Artilleries
_artillery?.ChangeBorders(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); _artillery?.ChangeBorders(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
Draw(); Draw();
} }
private void selectArtilleryButton_Click(object sender, EventArgs e)
{
SelectedArtillery = _artillery;
DialogResult = DialogResult.OK;
}
} }
} }

View File

@ -1,216 +0,0 @@
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.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.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
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();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit();
this.SuspendLayout();
//
// toolsGroupBox
//
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.comboBoxSelectorMap);
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, 450);
this.toolsGroupBox.TabIndex = 0;
this.toolsGroupBox.TabStop = false;
this.toolsGroupBox.Text = "Инструменты";
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(13, 315);
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, 249);
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, 177);
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, 148);
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, 83);
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);
//
// 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(13, 22);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
this.comboBoxSelectorMap.TabIndex = 19;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged);
//
// 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, 399);
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, 399);
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, 366);
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, 399);
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, 450);
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, 450);
this.Controls.Add(this.pictureBoxArtilleries);
this.Controls.Add(this.toolsGroupBox);
this.Name = "FormMapWithSetArtilleries";
this.Text = "Artillery";
this.toolsGroupBox.ResumeLayout(false);
this.toolsGroupBox.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;
}
}

View File

@ -1,134 +0,0 @@
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 MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap> _mapArtilleriesCollectionGeneric;
public FormMapWithSetArtilleries()
{
InitializeComponent();
}
private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Лесная карта":
map = new ForestMap();
break;
}
if (map != null)
{
_mapArtilleriesCollectionGeneric = new MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap>(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height, map);
}
else
{
_mapArtilleriesCollectionGeneric = null;
}
}
private void buttonAddArtillery_Click(object sender, EventArgs e)
{
if (_mapArtilleriesCollectionGeneric == null)
{
return;
}
FormArtillery form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectArtillery car = new(form.SelectedArtillery);
if (_mapArtilleriesCollectionGeneric + car)
{
MessageBox.Show("Объект добавлен");
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void buttonRemoveArtillery_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapArtilleriesCollectionGeneric - pos)
{
MessageBox.Show("Объект удален");
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void buttonShowStorage_Click(object sender, EventArgs e)
{
if (_mapArtilleriesCollectionGeneric == null)
{
return;
}
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
}
private void buttonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapArtilleriesCollectionGeneric == null)
{
return;
}
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowOnMap();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_mapArtilleriesCollectionGeneric == null)
{
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 = _mapArtilleriesCollectionGeneric.MoveObject(dir);
}
}
}

View File

@ -1,60 +0,0 @@
<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>

View File

@ -1,17 +0,0 @@
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();
}
}

View File

@ -1,128 +0,0 @@
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 bool operator +(MapWithSetArtilleriesGeneric<T, U> map, T artillery)
{
return map._setArtilleries.Insert(artillery); // TODO
}
public static bool operator -(MapWithSetArtilleriesGeneric<T, U> map, int position)
{
return map._setArtilleries.Remove(position); // TODO
}
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawArtilleries(gr);
return bmp;
}
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setArtilleries.Count; i++)
{
var car = _setArtilleries.Get(i);
if (car != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
}
}
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.Get(i) == null)
{
for (; j > i; j--)
{
var car = _setArtilleries.Get(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);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{// TODO
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i *
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
private void DrawArtilleries(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _setArtilleries.Count; i++)
{
var artillery = _setArtilleries.Get(i);
if (artillery != null)
{
artillery.SetObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
artillery.DrawingObject(g);
}
}
}
}
}

View File

@ -6,7 +6,7 @@ namespace Artilleries
static void Main() static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormMapWithSetArtilleries()); Application.Run(new FormArtillery());
} }
} }
} }

View File

@ -1,84 +0,0 @@
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 T[] _places;
public int Count => _places.Length;
public SetArtilleriesGeneric(int count)
{
_places = new T[count];
}
public bool Insert(T artillery)
{
return Insert(artillery, 0);
}
public bool Insert(T artillery, int position)
{
if (position < 0 || position >= Count)
{
return false;
}
if (_places[position] == null)
{
_places[position] = artillery;
return true;
}
int firstNull = -1;
for (int i = position + 1; i < Count; i++)
{
if (_places[i] == null)
{
firstNull = i;
break;
}
}
if (firstNull == -1)
{
return false;
}
for (int i = firstNull; i > position; i--)
{
(_places[i], _places[i - 1]) = (_places[i - 1], _places[i]);
}
_places[position] = artillery;
return true;
}
public bool Remove(int position)
{
if (position < 0 || position >= Count || _places[position] == null)
{
return false;
}
_places[position] = null;
return true;
}
public T Get(int position)
{
if (position < 0 || position >= Count)
{
return null;
}
return _places[position];
}
}
}

View File

@ -1,46 +0,0 @@
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++;
}
}
}
}
}