Compare commits

...

13 Commits

23 changed files with 2248 additions and 22 deletions

View File

@ -0,0 +1,158 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal abstract class AbstractMap
{
private IDrawningObject _drawningObject = null;
protected int[,] _map = null;
protected int _width;
protected int _height;
protected float _size_x;
protected float _size_y;
protected readonly Random _random = new();
protected readonly int _freeRoad = 0;
protected readonly int _barrier = 1;
public Bitmap CreateMap(int width, int height, IDrawningObject
drawningObject)
{
_width = width;
_height = height;
_drawningObject = drawningObject;
GenerateMap();
while (!SetObjectOnMap())
{
GenerateMap();
}
return DrawMapWithObject();
}
public Bitmap MoveObject(Direction direction)
{
int LefTopX = Convert.ToInt32(_drawningObject.GetCurrentPosition().Left / _size_x);
int LefTopY = Convert.ToInt32(_drawningObject.GetCurrentPosition().Top / _size_y);
int objwidth = Convert.ToInt32(_drawningObject.GetCurrentPosition().Right / _size_x);
int objheigh = Convert.ToInt32(_drawningObject.GetCurrentPosition().Bottom / _size_y);
bool CanStep = true;
switch (direction)
{
case Direction.Left:
for (int i = LefTopX; i >= Math.Abs(LefTopX - Convert.ToInt32(_drawningObject.Step / _size_x)); i--)
{
for (int j = LefTopY; j <= objheigh && j<_map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
CanStep = false;
break;
}
}
}
break;
case Direction.Right:
for (int i = objwidth; i <= objwidth + Convert.ToInt32(_drawningObject.Step / _size_x) && i < _map.GetLength(0); i++)
{
for (int j = LefTopY; j <= objheigh && j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
CanStep = false;
break;
}
}
}
break;
case Direction.Down:
for (int i = LefTopX; i <= objwidth && i < _map.GetLength(0); i++)
{
for (int j = objheigh; j <= objheigh + Convert.ToInt32(_drawningObject.Step / _size_y) && j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
CanStep = false;
break;
}
}
}
break;
case Direction.Up:
for (int i = LefTopX; i <= objwidth && i<_map.GetLength(0); i++)
{
for (int j = LefTopY; j >= Math.Abs(LefTopY - Convert.ToInt32(_drawningObject.Step / _size_y)) ; j--)
{
if (_map[i, j] == _barrier)
{
CanStep = false;
break;
}
}
}
break;
}
if (CanStep)
{
_drawningObject.MoveObject(direction);
}
return DrawMapWithObject();
}
private bool SetObjectOnMap()
{
if (_drawningObject == null || _map == null)
{
return false;
}
int x = _random.Next(0, 150);
int y = _random.Next(100, 300);
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
if (i * _size_x >= x && j * _size_y <= y &&
i * _size_x <= x + _drawningObject.GetCurrentPosition().Right &&
j * _size_y >= j - _drawningObject.GetCurrentPosition().Bottom && _map[i, j] == _barrier)
{
return false;
}
}
}
_drawningObject.SetObject(x, y, _width, _height);
return true;
}
private Bitmap DrawMapWithObject()
{
Bitmap bmp = new(_width, _height);
if (_drawningObject == null || _map == null)
{
return bmp;
}
Graphics gr = Graphics.FromImage(bmp);
for (int i = 0; i < _map.GetLength(0); ++i)
for (int j = 0; j < _map.GetLength(1); ++j)
DrawRoadPart(gr, i, j);
for (int i = 0; i < _map.GetLength(0); ++i)
for (int j = 0; j < _map.GetLength(1); ++j)
if (_map[i, j] == 1) DrawBarrierPart(gr, i, j);
_drawningObject.DrawningObject(gr);
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

@ -9,8 +9,9 @@ namespace Stormtrooper
/// <summary>
/// Направление перемещения
/// </summary>
internal enum Direction
public enum Direction
{
None = 0,
Up = 1,
Down = 2,
Left = 3,

View File

@ -12,17 +12,17 @@ namespace Stormtrooper
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
internal class Drawning
public class Drawning
{
public EntityStormtrooper Storm { get; private set; }
public EntityStormtrooper Storm { get; protected set; }
/// <summary>
/// Левая координата отрисовки самолёта
/// </summary>
private float _startPosX;
protected float _startPosX;
/// <summary>
/// Нижняя кооридната отрисовки самолёта
/// </summary>
private float _startPosY;
protected float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -45,10 +45,23 @@ namespace Stormtrooper
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес самолёта</param>
/// <param name="bodyColor">Цвет кузова</param>
public void Init(int speed, float weight, Color bodyColor)
public Drawning(int speed, float weight, Color bodyColor)
{
Storm = new EntityStormtrooper();
Storm.Init(speed, weight, bodyColor);
Storm = new EntityStormtrooper(speed, weight, bodyColor);
}
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес самолёта</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="carWidth">Ширина отрисовки самолёта</param>
/// <param name="carHeight">Высота отрисовки самолёта</param>
protected Drawning(int speed, float weight, Color bodyColor, int stormWidth, int stormHeight) :
this(speed, weight, bodyColor)
{
_StormWidth = stormWidth;
_StormHeight = stormHeight;
}
/// <summary>
/// Установка позиции самолёта
@ -117,7 +130,7 @@ namespace Stormtrooper
/// Отрисовка штурмовика
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@ -162,7 +175,7 @@ namespace Stormtrooper
g.FillPolygon(brBl, N);
//фюзеляж
Brush brGr = new SolidBrush(Color.Gray);
Brush brGr = new SolidBrush(Color.White);
g.FillRectangle(brGr, _startPosX + 20, _startPosY - 60, 100, 20);
//крыло и стаб
@ -171,6 +184,7 @@ namespace Stormtrooper
g.FillPolygon(br, S);
}
/// <summary>
/// Смена границ формы отрисовки
/// </summary>
@ -195,5 +209,13 @@ namespace Stormtrooper
_startPosY = _pictureHeight.Value - _StormHeight;
}
}
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosX + _StormWidth, _startPosY - _StormHeight, _startPosY);
}
}
}

View File

@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class DrawningMilitary : Drawning
{
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес самолёта</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="rocket">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public void SetDopColor(Color color)
{
((EntityMilitaryStormtrooper)Storm).DopColor = color;
}
public DrawningMilitary(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool rocket, bool sportLine) :
base(speed, weight, bodyColor, 135, 100)
{
Storm = new EntityMilitaryStormtrooper(speed, weight, bodyColor, dopColor, bodyKit, rocket, sportLine);
}
public override void DrawTransport(Graphics g)
{
if (Storm is not EntityMilitaryStormtrooper militaryTrop)
{
return;
}
Pen pen = new(Color.Black);
Brush dopBrush = new SolidBrush(militaryTrop.DopColor);
if (militaryTrop.BodyKit)
{
g.DrawEllipse(pen, _startPosX - 2, _startPosY - 70, 5, 20);
g.DrawEllipse(pen, _startPosX - 2, _startPosY - 50, 5, 20);
g.FillEllipse(dopBrush, _startPosX - 2, _startPosY - 70, 5, 20);
g.FillEllipse(dopBrush, _startPosX - 2, _startPosY - 50, 5, 20);
}
_startPosX += 2;
base.DrawTransport(g);
_startPosX -= 2;
if (militaryTrop.Rocket)
{
g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 70, 40, 3);
g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 90, 40, 3);
g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 30, 40, 3);
g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 10, 40, 3);
}
if (militaryTrop.SportLine)
{
g.FillRectangle(dopBrush, _startPosX + 30, _startPosY - 60, 8, 20);
g.FillRectangle(dopBrush, _startPosX + 100, _startPosY - 60, 8, 20);
}
}
}
}

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class DrawningObjectStorm : IDrawningObject
{
private Drawning _storm = null;
public DrawningObjectStorm(Drawning storm)
{
_storm = storm;
}
public float Step => _storm?.Storm?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _storm?.GetCurrentPosition() ?? default;
}
public void MoveObject(Direction direction)
{
_storm?.MoveTransport(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_storm.SetPosition(x, y, width, height);
}
void IDrawningObject.DrawningObject(Graphics g)
{
if (_storm is DrawningMilitary)
((DrawningMilitary)_storm).DrawTransport(g);
_storm.DrawTransport(g);
}
}
}

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class EntityMilitaryStormtrooper : EntityStormtrooper
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; set; }
/// <summary>
/// Признак наличия обвеса
/// </summary>
public bool BodyKit { get; private set; }
/// <summary>
/// Признак наличия рокет
/// </summary>
public bool Rocket { get; private set; }
/// <summary>
/// Признак наличия полосы
/// </summary>
public bool SportLine { get; private set; }
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес самолёта</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="rocket">Признак наличия рокет</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public EntityMilitaryStormtrooper(int speed, float weight, Color bodyColor, Color
dopColor, bool bodyKit, bool rocket, bool sportLine) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
BodyKit = bodyKit;
Rocket = rocket;
SportLine = sportLine;
}
}
}

View File

@ -9,7 +9,7 @@ namespace Stormtrooper
/// <summary>
/// Класс-сущность "Штурмовик"
/// </summary>
internal class EntityStormtrooper
public class EntityStormtrooper
{
/// <summary>
/// Скорость
@ -22,7 +22,7 @@ namespace Stormtrooper
/// <summary>
/// Цвет корпуса
/// </summary>
public Color BodyColor { get; private set; }
public Color BodyColor { get; set; }
/// <summary>
/// Шаг перемещения
/// </summary>
@ -34,7 +34,7 @@ namespace Stormtrooper
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <returns></returns>
public void Init(int speed, float weight, Color bodyColor)
public EntityStormtrooper(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;

View File

@ -0,0 +1,296 @@
namespace Stormtrooper
{
partial class FormMapWithSetStormtroopers
{
/// <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.groupBoxTools = new System.Windows.Forms.GroupBox();
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRemoveCar = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonAddCar = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBoxTools
//
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonRemoveCar);
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.groupBoxTools.Controls.Add(this.buttonDown);
this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.buttonLeft);
this.groupBoxTools.Controls.Add(this.buttonUp);
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.groupBoxTools.Controls.Add(this.buttonAddCar);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(927, 0);
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxTools.Size = new System.Drawing.Size(233, 884);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты";
//
// groupBoxMaps
//
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Location = new System.Drawing.Point(14, 28);
this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxMaps.Size = new System.Drawing.Size(213, 360);
this.groupBoxMaps.TabIndex = 11;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты";
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 20;
this.listBoxMaps.Location = new System.Drawing.Point(7, 160);
this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(198, 144);
this.listBoxMaps.TabIndex = 4;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(7, 313);
this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(199, 39);
this.buttonDeleteMap.TabIndex = 3;
this.buttonDeleteMap.Text = "Удалить карту";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(6, 115);
this.buttonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(200, 37);
this.buttonAddMap.TabIndex = 2;
this.buttonAddMap.Text = "Добавить карту";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(7, 37);
this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(198, 27);
this.textBoxNewMapName.TabIndex = 1;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 76);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(198, 28);
this.comboBoxSelectorMap.TabIndex = 0;
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(21, 511);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(199, 27);
this.maskedTextBoxPosition.TabIndex = 2;
this.maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonRemoveCar
//
this.buttonRemoveCar.Location = new System.Drawing.Point(21, 565);
this.buttonRemoveCar.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRemoveCar.Name = "buttonRemoveCar";
this.buttonRemoveCar.Size = new System.Drawing.Size(200, 47);
this.buttonRemoveCar.TabIndex = 3;
this.buttonRemoveCar.Text = "Удалить самолёт";
this.buttonRemoveCar.UseVisualStyleBackColor = true;
this.buttonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveStorm_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(21, 633);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(104, 817);
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(34, 40);
this.buttonDown.TabIndex = 10;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(145, 817);
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(34, 40);
this.buttonRight.TabIndex = 9;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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::Stormtrooper.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(63, 817);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(34, 40);
this.buttonLeft.TabIndex = 8;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.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::Stormtrooper.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(104, 769);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(34, 40);
this.buttonUp.TabIndex = 7;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(21, 700);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonAddCar
//
this.buttonAddCar.Location = new System.Drawing.Point(21, 443);
this.buttonAddCar.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddCar.Name = "buttonAddCar";
this.buttonAddCar.Size = new System.Drawing.Size(200, 47);
this.buttonAddCar.TabIndex = 1;
this.buttonAddCar.Text = "Добавить самолёт";
this.buttonAddCar.UseVisualStyleBackColor = true;
this.buttonAddCar.Click += new System.EventHandler(this.ButtonAddStorm_Click);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(927, 884);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetStormtroopers
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1160, 884);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMapWithSetStormtroopers";
this.Text = "Карта с набором объектов";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private PictureBox pictureBox;
private ComboBox comboBoxSelectorMap;
private Button buttonShowOnMap;
private Button buttonAddCar;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private Button buttonUp;
private Button buttonShowStorage;
private Button buttonRemoveCar;
private MaskedTextBox maskedTextBoxPosition;
private GroupBox groupBoxMaps;
private ListBox listBoxMaps;
private Button buttonDeleteMap;
private Button buttonAddMap;
private TextBox textBoxNewMapName;
}
}

View File

@ -0,0 +1,211 @@
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;
namespace Stormtrooper
{
public partial class FormMapWithSetStormtroopers : Form
{
/// <summary>
/// Словарь для выпадающего списка
/// </summary>
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{"Ясное небо", new SecondMap() },
{"Пасмурное небо", new ThirdMap() }
};
/// <summary>
/// Объект от коллекции карт
/// </summary>
private readonly MapsCollection _mapsCollection;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetStormtroopers()
{
InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddStorm_Click(object sender, EventArgs e)
{
var formStormConfig = new FormStormtrooperConfig();
formStormConfig.AddEvent(AddStormtrooper);
formStormConfig.Show();
}
private void AddStormtrooper (Drawning storm)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
DrawningObjectStorm st = new(storm);
{
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + st != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveStorm_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("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
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;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
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)
{
pictureBox.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();
}
}
}
}

View 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>

View File

@ -38,6 +38,8 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.buttonSelectStorm = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxStormtrooper)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@ -147,11 +149,34 @@
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonCreateModif
//
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateModif.Location = new System.Drawing.Point(125, 396);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(120, 29);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// buttonSelectStorm
//
this.buttonSelectStorm.Location = new System.Drawing.Point(260, 396);
this.buttonSelectStorm.Name = "buttonSelectStorm";
this.buttonSelectStorm.Size = new System.Drawing.Size(94, 29);
this.buttonSelectStorm.TabIndex = 8;
this.buttonSelectStorm.Text = "Выбрать";
this.buttonSelectStorm.UseVisualStyleBackColor = true;
this.buttonSelectStorm.Click += new System.EventHandler(this.ButtonSelectStorm_Click);
//
// FormStormtrooper
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(831, 461);
this.Controls.Add(this.buttonSelectStorm);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
@ -181,5 +206,7 @@
private Button buttonLeft;
private Button buttonDown;
private Button buttonUp;
private Button buttonCreateModif;
private Button buttonSelectStorm;
}
}

View File

@ -3,12 +3,16 @@ namespace Stormtrooper
public partial class FormStormtrooper : Form
{
private Drawning _storm;
/// <summary>
/// Âûáðàííûé îáúåêò
/// </summary>
public Drawning SelectedStormtrooper { get; private set; }
public FormStormtrooper()
{
InitializeComponent();
}
//private EntityStormtrooper Storm;
/// <summary>
/// Ìåòîä ïðîðèñîâêè ñàìîë¸òà
/// </summary>
@ -19,6 +23,18 @@ namespace Stormtrooper
_storm?.DrawTransport(gr);
pictureBoxStormtrooper.Image = bmp;
}
/// <summary>
/// Ìåòîä óñòàíîâêè äàííûõ
/// </summary>
private void SetData()
{
Random rnd = new();
_storm.SetPosition(rnd.Next(0, 150), rnd.Next(0, 300), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_storm.Storm.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_storm.Storm.Weight}";
toolStripStatusLabelColor.Text = $"Öâåò: {_storm.Storm.BodyColor.Name}";
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
/// </summary>
@ -27,12 +43,14 @@ namespace Stormtrooper
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_storm = new Drawning();
_storm.Init(rnd.Next(100,300), rnd.Next(1000,2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_storm.SetPosition(rnd.Next(0, 150), rnd.Next(0, 300), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_storm.Storm.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_storm.Storm.Weight}";
toolStripStatusLabelColor.Text = $"Öâåò: {_storm.Storm.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;
}
_storm = new Drawning(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
/// <summary>
@ -71,5 +89,27 @@ namespace Stormtrooper
_storm?.ChangeBorders(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
Draw();
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_storm = new DrawningMilitary(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
private void ButtonSelectStorm_Click(object sender, EventArgs e)
{
SelectedStormtrooper = _storm;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -0,0 +1,423 @@
namespace Stormtrooper
{
partial class FormStormtrooperConfig
{
/// <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.groupBoxConfig = new System.Windows.Forms.GroupBox();
this.labelModifiedObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.checkBoxSportLine = new System.Windows.Forms.CheckBox();
this.checkBoxRocket = new System.Windows.Forms.CheckBox();
this.checkBoxBodyKit = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.labelWeight = new System.Windows.Forms.Label();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelSpeed = new System.Windows.Forms.Label();
this.panelObject = new System.Windows.Forms.Panel();
this.labelDopColor = new System.Windows.Forms.Label();
this.labelBaseColor = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOk = new System.Windows.Forms.Button();
this.groupBoxConfig.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.panelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.SuspendLayout();
//
// groupBoxConfig
//
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
this.groupBoxConfig.Controls.Add(this.checkBoxSportLine);
this.groupBoxConfig.Controls.Add(this.checkBoxRocket);
this.groupBoxConfig.Controls.Add(this.checkBoxBodyKit);
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
this.groupBoxConfig.Controls.Add(this.labelWeight);
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
this.groupBoxConfig.Controls.Add(this.labelSpeed);
this.groupBoxConfig.Location = new System.Drawing.Point(14, 16);
this.groupBoxConfig.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxConfig.Size = new System.Drawing.Size(594, 293);
this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Параметры";
//
// labelModifiedObject
//
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifiedObject.Location = new System.Drawing.Point(450, 216);
this.labelModifiedObject.Name = "labelModifiedObject";
this.labelModifiedObject.Size = new System.Drawing.Size(111, 50);
this.labelModifiedObject.TabIndex = 16;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(322, 216);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(111, 50);
this.labelSimpleObject.TabIndex = 15;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.panelPurple);
this.groupBoxColors.Controls.Add(this.panelYellow);
this.groupBoxColors.Controls.Add(this.panelBlack);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelGray);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelWhite);
this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Location = new System.Drawing.Point(305, 29);
this.groupBoxColors.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxColors.Size = new System.Drawing.Size(275, 169);
this.groupBoxColors.TabIndex = 14;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(210, 97);
this.panelPurple.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(46, 53);
this.panelPurple.TabIndex = 3;
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(210, 29);
this.panelYellow.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(46, 53);
this.panelYellow.TabIndex = 1;
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(145, 97);
this.panelBlack.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(46, 53);
this.panelBlack.TabIndex = 4;
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(145, 29);
this.panelBlue.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(46, 53);
this.panelBlue.TabIndex = 1;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGray
//
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(82, 97);
this.panelGray.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(46, 53);
this.panelGray.TabIndex = 5;
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(82, 29);
this.panelGreen.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(46, 53);
this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(17, 97);
this.panelWhite.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(46, 53);
this.panelWhite.TabIndex = 2;
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(17, 29);
this.panelRed.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(46, 53);
this.panelRed.TabIndex = 0;
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// checkBoxSportLine
//
this.checkBoxSportLine.AutoSize = true;
this.checkBoxSportLine.Location = new System.Drawing.Point(25, 247);
this.checkBoxSportLine.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.checkBoxSportLine.Name = "checkBoxSportLine";
this.checkBoxSportLine.Size = new System.Drawing.Size(283, 24);
this.checkBoxSportLine.TabIndex = 13;
this.checkBoxSportLine.Text = "Признак наличия гоночной полосы";
this.checkBoxSportLine.UseVisualStyleBackColor = true;
//
// checkBoxRocket
//
this.checkBoxRocket.AutoSize = true;
this.checkBoxRocket.Location = new System.Drawing.Point(25, 199);
this.checkBoxRocket.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.checkBoxRocket.Name = "checkBoxRocket";
this.checkBoxRocket.Size = new System.Drawing.Size(196, 24);
this.checkBoxRocket.TabIndex = 12;
this.checkBoxRocket.Text = "Признак наличия ракет";
this.checkBoxRocket.UseVisualStyleBackColor = true;
//
// checkBoxBodyKit
//
this.checkBoxBodyKit.AutoSize = true;
this.checkBoxBodyKit.Location = new System.Drawing.Point(25, 153);
this.checkBoxBodyKit.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.checkBoxBodyKit.Name = "checkBoxBodyKit";
this.checkBoxBodyKit.Size = new System.Drawing.Size(198, 24);
this.checkBoxBodyKit.TabIndex = 11;
this.checkBoxBodyKit.Text = "Признак наличия винта";
this.checkBoxBodyKit.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(103, 96);
this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(90, 27);
this.numericUpDownWeight.TabIndex = 10;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(25, 99);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(36, 20);
this.labelWeight.TabIndex = 9;
this.labelWeight.Text = "Вес:";
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(103, 40);
this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(90, 27);
this.numericUpDownSpeed.TabIndex = 8;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(25, 43);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(76, 20);
this.labelSpeed.TabIndex = 7;
this.labelSpeed.Text = "Скорость:";
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.labelDopColor);
this.panelObject.Controls.Add(this.labelBaseColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(615, 16);
this.panelObject.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(299, 245);
this.panelObject.TabIndex = 2;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// labelDopColor
//
this.labelDopColor.AllowDrop = true;
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelDopColor.Location = new System.Drawing.Point(161, 12);
this.labelDopColor.Name = "labelDopColor";
this.labelDopColor.Size = new System.Drawing.Size(119, 42);
this.labelDopColor.TabIndex = 2;
this.labelDopColor.Text = "Доп. цвет";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
//
// labelBaseColor
//
this.labelBaseColor.AllowDrop = true;
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelBaseColor.Location = new System.Drawing.Point(23, 12);
this.labelBaseColor.Name = "labelBaseColor";
this.labelBaseColor.Size = new System.Drawing.Size(119, 42);
this.labelBaseColor.TabIndex = 1;
this.labelBaseColor.Text = "Цвет";
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(23, 59);
this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(257, 167);
this.pictureBoxObject.TabIndex = 0;
this.pictureBoxObject.TabStop = false;
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(776, 269);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(119, 40);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(638, 269);
this.buttonOk.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(119, 40);
this.buttonOk.TabIndex = 4;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// FormStormtrooperConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(926, 323);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxConfig);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormStormtrooperConfig";
this.Text = "Создание объекта";
this.groupBoxConfig.ResumeLayout(false);
this.groupBoxConfig.PerformLayout();
this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.panelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private CheckBox checkBoxSportLine;
private CheckBox checkBoxRocket;
private CheckBox checkBoxBodyKit;
private NumericUpDown numericUpDownWeight;
private Label labelWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelSpeed;
private Label labelModifiedObject;
private Label labelSimpleObject;
private GroupBox groupBoxColors;
private Panel panelPurple;
private Panel panelYellow;
private Panel panelBlack;
private Panel panelBlue;
private Panel panelGray;
private Panel panelGreen;
private Panel panelWhite;
private Panel panelRed;
private Panel panelObject;
private Label labelDopColor;
private Label labelBaseColor;
private PictureBox pictureBoxObject;
private Button buttonCancel;
private Button buttonOk;
}
}

View File

@ -0,0 +1,194 @@
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;
namespace Stormtrooper
{
/// <summary>
/// Форма создания объекта
/// </summary>
public partial class FormStormtrooperConfig : Form
{
/// <summary>
/// Переменная-выбранный самолёт
/// </summary>
Drawning _storm = null;
/// <summary>
/// Делегат
/// </summary>
public delegate void Action (Drawning storm);
/// <summary>
/// Событие
/// </summary>
private event Action EventAddStorm;
/// <summary>
/// Конструктор
/// </summary>
public FormStormtrooperConfig()
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (object sender, EventArgs a) => Close();
}
/// <summary>
/// Отрисовать машину
/// </summary>
private void DrawStorm()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_storm?.SetPosition(5, 105, pictureBoxObject.Width, pictureBoxObject.Height);
_storm?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev"></param>
public void AddEvent(Action ev)
{
if (EventAddStorm == null)
{
EventAddStorm = new Action(ev);
}
else
{
EventAddStorm += ev;
}
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_storm = new Drawning((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
break;
case "labelModifiedObject":
_storm = new DrawningMilitary((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxBodyKit.Checked, checkBoxRocket.Checked, checkBoxSportLine.Checked);
break;
}
DrawStorm();
}
/// <summary>
/// Отправляем цвет с панели
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Принимаем основной цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
var color = e.Data.GetData(typeof(Color));
if (color != null)
{
(sender as Label).BackColor = (Color)color;
}
if (_storm != null)
{
_storm.Storm.BodyColor = (Color)color;
DrawStorm();
}
}
/// <summary>
/// Принимаем дополнительный цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
var color = e.Data.GetData(typeof(Color));
if (color != null)
{
(sender as Label).BackColor = (Color)color;
}
if (_storm != null)
{
if (_storm is DrawningMilitary storm)
{
storm.SetDopColor((Color)color);
DrawStorm();
}
DrawStorm();
}
}
/// <summary>
/// Добавление самолёта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddStorm?.Invoke(_storm);
Close();
}
}
}

View 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>

View File

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
/// <summary>
/// Интерфейс для работы с объектом, прорисовываемым на форме
/// </summary>
internal interface IDrawningObject
{
/// <summary>
/// Шаг перемещения объекта
/// </summary>
public float Step { get; }
/// <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>
void MoveObject(Direction direction);
/// <summary>
/// Отрисовка объекта
/// </summary>
/// <param name="g"></param>
void DrawningObject(Graphics g);
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
}
}

View File

@ -0,0 +1,181 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
/// <summary>
/// Карта с набром объектов под нее
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class MapWithSetStormtroopersGeneric<T, U>
where T : class, IDrawningObject
where U : AbstractMap
{
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 135;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 100;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetStormtroopersGeneric<T> _setStormtroopers;
/// <summary>
/// Карта
/// </summary>
private readonly U _map;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="map"></param>
public MapWithSetStormtroopersGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
_setStormtroopers = new SetStormtroopersGeneric<T>(width * height);
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="map"></param>
/// <param name="car"></param>
/// <returns></returns>
public static int operator +(MapWithSetStormtroopersGeneric<T, U> map, T stormtrooper)
{
return map._setStormtroopers.Insert(stormtrooper);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="map"></param>
/// <param name="position"></param>
/// <returns></returns>
public static T operator -(MapWithSetStormtroopersGeneric<T, U> map, int position)
{
return map._setStormtroopers.Remove(position);
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawStormtroopers(gr);
return bmp;
}
/// <summary>
/// Просмотр объекта на карте
/// </summary>
/// <returns></returns>
public Bitmap ShowOnMap()
{
Shaking();
foreach (var storm in _setStormtroopers.GetStormtroopers())
{
return _map.CreateMap(_pictureWidth, _pictureHeight, storm);
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// Перемещение объекта по крате
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary>
private void Shaking()
{
int j = _setStormtroopers.Count - 1;
for (int i = 0; i < _setStormtroopers.Count; i++)
{
if (_setStormtroopers[i] == null)
{
for (; j > i; j--)
{
var car = _setStormtroopers[i];
if (car != null)
{
_setStormtroopers.Insert(car, i);
_setStormtroopers.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Brush br = new SolidBrush(Color.Gray);
g.FillRectangle(br, new Rectangle(0, 0, _pictureWidth, _pictureHeight));
Pen pen = new(Color.White, 3);
pen.DashStyle = DashStyle.Dash;
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.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawStormtroopers(Graphics g)
{
int numOfObjectsInRow = _pictureWidth / _placeSizeWidth;
int i = 0;
foreach (var storm in _setStormtroopers.GetStormtroopers())
{
storm.SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight + _placeSizeHeight, _pictureWidth, _pictureHeight);
storm.DrawningObject(g);
i++;
}
}
}
}

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class MapsCollection
{
/// <summary>
/// Словарь (хранилище) с картами
/// </summary>
readonly Dictionary<string, MapWithSetStormtroopersGeneric<DrawningObjectStorm, AbstractMap>> _mapStorages;
/// <summary>
/// Возвращение списка названий карт
/// </summary>
public List<string> Keys => _mapStorages.Keys.ToList();
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetStormtroopersGeneric<DrawningObjectStorm, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="name">Название карты</param>
/// <param name="map">Карта</param>
public void AddMap(string name, AbstractMap map)
{
if (_mapStorages.ContainsKey(name))
{
MessageBox.Show("Карта с таким названием уже существует!");
return;
}
_mapStorages.Add(name, new MapWithSetStormtroopersGeneric<DrawningObjectStorm, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="name">Название карты</param>
public void DelMap(string name)
{
if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name);
}
/// <summary>
/// Доступ к парковке
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public MapWithSetStormtroopersGeneric<DrawningObjectStorm, AbstractMap> this[string ind]
{
get
{
if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind];
return null;
}
}
}
}

View File

@ -11,7 +11,7 @@ namespace Stormtrooper
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormStormtrooper());
Application.Run(new FormMapWithSetStormtroopers());
}
}
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class SecondMap:AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.White);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.LightBlue);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillEllipse(barrierColor, i * _size_x, j * _size_y, _size_x+3, _size_y+3);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
}
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 < 30)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
}
}
}
}

View File

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T"></typeparam>
internal class SetStormtroopersGeneric<T>
where T : class
{
/// <summary>
/// Список объектов, которые храним
/// </summary>
private readonly List<T> _places;
/// <summary>
/// Количество объектов в списке
/// </summary>
public int Count => _places.Count;
private readonly int _maxCount;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetStormtroopersGeneric(int count)
{
_maxCount = count;
_places = new List<T>();
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="stormtrooper">Добавляемый штурмовик</param>
/// <returns></returns>
public int Insert(T stormtrooper)
{
if (_places.Count + 1 >= _maxCount) return -1;
return Insert(stormtrooper, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="stormtrooper">Добавляемый штурмовик</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public int Insert(T stormtrooper, int position)
{
if (position < 0 || position >= _maxCount) return -1;
if (_places.Count + 1 >= _maxCount) return -1;
_places.Insert(position, stormtrooper);
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Remove(int position)
{
if (position < 0 || position >= _maxCount) return null;
T saveStorm = _places[position];
_places.RemoveAt(position);
return saveStorm;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T this[int position]
{
get
{
if (position < 0 || position >= _maxCount) return null;
return _places[position];
}
set
{
if (position < 0 || position >= _maxCount) Insert(value, position);
}
}
/// <summary>
/// Проход по набору до первого пустого
/// </summary>
/// <returns></returns>
public IEnumerable<T> GetStormtroopers()
{
foreach (var storm in _places)
{
if (storm != null)
{
yield return storm;
}
else
{
yield break;
}
}
}
}
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class SimpleMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Black);
/// <summary>
/// Цвет участка открытого
/// </summary>
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, _size_x, _size_y);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
}
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++;
}
}
}
}
}

View File

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class ThirdMap:AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Gray);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.LightGray);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillEllipse(barrierColor, i * _size_x, j * _size_y, _size_x + 3, _size_y + 3);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
}
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 < 30)
{
int x = _random.Next(0, 30);
int y = _random.Next(0, 30);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
x = _random.Next(70, 100);
y = _random.Next(0, 30);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
x = _random.Next(40, 60);
y = _random.Next(50, 90);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
}
}
}
}