17 Commits
lab_6 ... lab6

Author SHA1 Message Date
Alenka
be33c0e4bc Done 2023-11-22 23:31:07 +04:00
Alenka
62a7064012 fix 2023-11-10 10:59:30 +04:00
Alenka
8c293b6d5c fix 2023-11-09 19:10:08 +04:00
Alenka
71fca0840e start 2023-11-09 16:42:28 +04:00
Alenka
735492bfe2 Чуть пофиксила 2023-10-27 08:32:54 +04:00
Alenka
842e5a8ca4 почти done 2023-10-26 23:10:37 +04:00
Alenka
f5d9e89692 почти done 2023-10-26 16:46:27 +04:00
Alenka
1bacab8f18 start 2023-10-26 00:36:02 +04:00
Alenka
f08466a718 без доп 2023-10-13 11:21:23 +04:00
Alenka
065b937d2c no 2023-10-13 10:29:00 +04:00
Alenka
db85af0a99 Замена кнопок 2023-10-13 08:40:42 +04:00
Alenka
feeea2ef58 result 2023-10-12 22:22:08 +04:00
Alenka
5309de6c2f Почти готово 2023-10-12 19:01:51 +04:00
Alenka
5543d1951e 1 2023-10-12 18:50:26 +04:00
Alenka
929e314196 Лаба2 2023-10-12 18:30:16 +04:00
Alenka
4d583a149b Process 2023-10-12 00:51:50 +04:00
Alenka
3f9f29c8b8 Пробный класс 2023-10-12 00:40:22 +04:00
34 changed files with 1797 additions and 1466 deletions

View File

@@ -1,22 +1,20 @@
using Cruiser;
using Cruiser.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Monorail.DrawningObjects;
namespace Cruiser.MovementStrategy
namespace Monorail.MovementStrategy
{
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
private Status _state = Status.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int
height)
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
{
@@ -28,6 +26,7 @@ namespace Cruiser.MovementStrategy
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != Status.InProgress)
@@ -41,12 +40,18 @@ namespace Cruiser.MovementStrategy
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(Direction.Left);
protected bool MoveRight() => MoveTo(Direction.Right);
protected bool MoveUp() => MoveTo(Direction.Up);
protected bool MoveDown() => MoveTo(Direction.Down);
protected bool MoveLeft() => MoveTo(DirectionType.Left);
protected bool MoveRight() => MoveTo(DirectionType.Right);
protected bool MoveUp() => MoveTo(DirectionType.Up);
protected bool MoveDown() => MoveTo(DirectionType.Down);
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
_moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != Status.InProgress)
@@ -55,20 +60,25 @@ namespace Cruiser.MovementStrategy
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion();
private bool MoveTo(Direction direction)
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(direction) ?? false)
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(direction);
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,14 @@
using Monorail.DrawningObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser
{
/// <summary>
/// Делегат для передачи объекта
/// </summary>
public delegate void PlaneDelegate(DrawingPlane plane);
}

View File

@@ -1,18 +1,23 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.Entities
namespace Monorail.Entities
{
public class EntityCruiser
public class EntityPlane
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public Color BodyColor { get; set; }
public double Step => (double)Speed * 100 / Weight;
public EntityCruiser(int speed, double weight, Color bodyColor)
public EntityPlane(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
@@ -22,5 +27,6 @@ namespace Cruiser.Entities
{
BodyColor = color;
}
}
}

View File

@@ -1,167 +0,0 @@
namespace Cruiser
{
partial class CruiserForm
{
private System.ComponentModel.IContainer components = null;
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.ButtonDown = new System.Windows.Forms.Button();
this.ButtonLeft = new System.Windows.Forms.Button();
this.ButtonRight = new System.Windows.Forms.Button();
this.ButtonUp = new System.Windows.Forms.Button();
this.buttonAdvancedCreate = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.comboBoxCruiser = new System.Windows.Forms.ComboBox();
this.ButtonStep = new System.Windows.Forms.Button();
this.ButtonSelected = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
this.SuspendLayout();
//
// pictureBoxCruiser
//
this.pictureBoxCruiser.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCruiser.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCruiser.Name = "pictureBoxCruiser";
this.pictureBoxCruiser.Size = new System.Drawing.Size(667, 358);
this.pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCruiser.TabIndex = 0;
this.pictureBoxCruiser.TabStop = false;
this.pictureBoxCruiser.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::Cruiser.Properties.Resources.вниз;
this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.ButtonDown.Location = new System.Drawing.Point(543, 306);
this.ButtonDown.Name = "ButtonDown";
this.ButtonDown.Size = new System.Drawing.Size(30, 30);
this.ButtonDown.TabIndex = 1;
this.ButtonDown.UseVisualStyleBackColor = true;
this.ButtonDown.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::Cruiser.Properties.Resources.влево;
this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.ButtonLeft.Location = new System.Drawing.Point(517, 306);
this.ButtonLeft.Name = "ButtonLeft";
this.ButtonLeft.Size = new System.Drawing.Size(30, 30);
this.ButtonLeft.TabIndex = 2;
this.ButtonLeft.UseVisualStyleBackColor = true;
this.ButtonLeft.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::Cruiser.Properties.Resources.вправо;
this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.ButtonRight.Location = new System.Drawing.Point(567, 306);
this.ButtonRight.Name = "ButtonRight";
this.ButtonRight.Size = new System.Drawing.Size(30, 30);
this.ButtonRight.TabIndex = 3;
this.ButtonRight.UseVisualStyleBackColor = true;
this.ButtonRight.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::Cruiser.Properties.Resources.вверх;
this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.ButtonUp.Location = new System.Drawing.Point(543, 284);
this.ButtonUp.Name = "ButtonUp";
this.ButtonUp.Size = new System.Drawing.Size(30, 30);
this.ButtonUp.TabIndex = 4;
this.ButtonUp.UseVisualStyleBackColor = true;
this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonAdvancedCreate
//
this.buttonAdvancedCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonAdvancedCreate.Location = new System.Drawing.Point(12, 267);
this.buttonAdvancedCreate.Name = "buttonAdvancedCreate";
this.buttonAdvancedCreate.Size = new System.Drawing.Size(210, 69);
this.buttonAdvancedCreate.TabIndex = 5;
this.buttonAdvancedCreate.Text = "Создать продвинутую версию";
this.buttonAdvancedCreate.UseVisualStyleBackColor = true;
this.buttonAdvancedCreate.Click += new System.EventHandler(this.ButtonAdvancedCreate_Click);
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(240, 267);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(242, 69);
this.buttonCreate.TabIndex = 6;
this.buttonCreate.Text = "Создать простую версию";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// comboBoxCruiser
//
this.comboBoxCruiser.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxCruiser.FormattingEnabled = true;
this.comboBoxCruiser.Items.AddRange(new object[] {
"Центр",
"Угол"});
this.comboBoxCruiser.Location = new System.Drawing.Point(415, 22);
this.comboBoxCruiser.Name = "comboBoxCruiser";
this.comboBoxCruiser.Size = new System.Drawing.Size(182, 33);
this.comboBoxCruiser.TabIndex = 7;
//
// ButtonStep
//
this.ButtonStep.Location = new System.Drawing.Point(485, 70);
this.ButtonStep.Name = "ButtonStep";
this.ButtonStep.Size = new System.Drawing.Size(112, 34);
this.ButtonStep.TabIndex = 8;
this.ButtonStep.Text = "Шаг";
this.ButtonStep.UseVisualStyleBackColor = true;
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
//
// ButtonSelected
//
this.ButtonSelected.Location = new System.Drawing.Point(180, 215);
this.ButtonSelected.Name = "ButtonSelected";
this.ButtonSelected.Size = new System.Drawing.Size(105, 34);
this.ButtonSelected.TabIndex = 9;
this.ButtonSelected.Text = "Выбрать";
this.ButtonSelected.UseVisualStyleBackColor = true;
this.ButtonSelected.Click += new System.EventHandler(this.ButtonSelectedCruiser_Click);
//
// CruiserForm
//
this.ClientSize = new System.Drawing.Size(667, 358);
this.Controls.Add(this.ButtonSelected);
this.Controls.Add(this.ButtonStep);
this.Controls.Add(this.comboBoxCruiser);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.buttonAdvancedCreate);
this.Controls.Add(this.ButtonUp);
this.Controls.Add(this.ButtonRight);
this.Controls.Add(this.ButtonLeft);
this.Controls.Add(this.ButtonDown);
this.Controls.Add(this.pictureBoxCruiser);
this.Name = "CruiserForm";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxCruiser;
private Button ButtonDown;
private Button ButtonLeft;
private Button ButtonRight;
private Button ButtonUp;
private Button buttonAdvancedCreate;
private Button buttonCreate;
private ComboBox comboBoxCruiser;
private Button ButtonStep;
private Button ButtonSelected;
}
}

View File

@@ -1,135 +0,0 @@
using System.Windows.Forms;
using Cruiser.DrawningObjects;
using Cruiser.MovementStrategy;
namespace Cruiser
{
public partial class CruiserForm : Form
{
private DrawningCruiser? _drawningCruiser;
private AbstractStrategy? _abstractStrategy;
public DrawningCruiser? SelectedCruiser { get; private set; }
public CruiserForm()
{
InitializeComponent();
_abstractStrategy = null;
SelectedCruiser = null;
}
private void Draw()
{
if (_drawningCruiser == null)
{
return;
}
Bitmap bmp = new Bitmap(pictureBoxCruiser.Width, pictureBoxCruiser.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningCruiser.DrawTransport(gr);
pictureBoxCruiser.Image = bmp;
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningCruiser == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningCruiser.MoveTransport(Direction.Up);
break;
case "buttonDown":
_drawningCruiser.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_drawningCruiser.MoveTransport(Direction.Left);
break;
case "buttonRight":
_drawningCruiser.MoveTransport(Direction.Right);
break;
}
Draw();
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogColor = new();
if (dialogColor.ShowDialog() == DialogResult.OK)
{
color = dialogColor.Color;
}
_drawningCruiser = new DrawningCruiser(random.Next(100, 300), random.Next(1000, 3000),
color, pictureBoxCruiser.Width, pictureBoxCruiser.Height);
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawningCruiser == null)
{
return;
}
if (comboBoxCruiser.Enabled)
{
_abstractStrategy = comboBoxCruiser.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new DrawningObjectCruiser(_drawningCruiser), pictureBoxCruiser.Width,
pictureBoxCruiser.Height);
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxCruiser.Enabled = true;
_abstractStrategy = null;
}
}
private void ButtonAdvancedCreate_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogColor = new();
if (dialogColor.ShowDialog() == DialogResult.OK)
{
color = dialogColor.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogDopColor = new();
if (dialogDopColor.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDopColor.Color;
}
_drawningCruiser = new DrawningAdvancedCruiser(random.Next(100, 300),
random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxCruiser.Width, pictureBoxCruiser.Height);
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonSelectedCruiser_Click(object sender, EventArgs e)
{
SelectedCruiser = _drawningCruiser;
DialogResult = DialogResult.OK;
}
}
}

View File

@@ -1,26 +1,46 @@
using System;
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.Generics;
using Cruiser.DrawningObjects;
using Cruiser.Entities;
using Cruiser.MovementStrategy;
using Monorail.DrawningObjects;
using System.Drawing;
namespace Cruiser.Generics
namespace Monorail.Generics
{
internal class CruiserGenericCollection<T, U>
where T : DrawningCruiser
internal class PlanesGenericCollection<T, U>
where T : DrawingPlane
where U : IMoveableObject
{
public IEnumerable<T?> GetCruiser => _collection.GetCruiser();
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
public CruiserGenericCollection(int picWidth, int picHeight)
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public PlanesGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
@@ -28,31 +48,45 @@ namespace Cruiser.Generics
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static bool operator +(CruiserGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(PlanesGenericCollection<T, U>? collect, T? obj)
{
if (obj == null || collect == null)
return false;
return collect._collection.Insert(obj);
}
return collect?._collection.Insert(obj) ?? false;
}
public static T? operator -(CruiserGenericCollection<T, U> collect, int pos)
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(PlanesGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
public Bitmap ShowCruisers()
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowPlanes()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
@@ -60,6 +94,10 @@ namespace Cruiser.Generics
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
@@ -67,7 +105,7 @@ namespace Cruiser.Generics
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{
{//линия разметки места
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
@@ -76,21 +114,24 @@ namespace Cruiser.Generics
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
int i = 0;
foreach (var cruiser in _collection.GetCruiser())
foreach (var plane in _collection.GetPlanes())
{
if (cruiser != null)
if (plane != null)
{
int inRow = _pictureWidth / _placeSizeWidth;
cruiser.SetPosition((i % inRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / inRow) + _placeSizeHeight / 10);
cruiser.DrawTransport(g);
plane.SetPosition((i % inRow) * (_placeSizeWidth) + _placeSizeWidth / 20, _placeSizeHeight * (i / inRow) + _placeSizeHeight / 20);
plane.DrawTransport(g);
}
i++;
}
}
}
}

View File

@@ -1,53 +1,31 @@
using System;
using Cruiser;
using Monorail.DrawningObjects;
using Monorail.Generics;
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.DrawningObjects;
using Cruiser.MovementStrategy;
namespace Cruiser.Generics
namespace Monorail.Generics
{
internal class CruiserGenericStorage
internal class PlanesGenericStorage
{
readonly Dictionary<string, CruiserGenericCollection<DrawningCruiser,
DrawningObjectCruiser>> _cruiserStorages;
public List<string> Keys => _cruiserStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private static readonly char _separatorForKeyValue = '|';
/// <summary>
/// Разделитель для записей коллекции данных в файл
/// </summary>
private readonly char _separatorRecords = ';';
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly char _separatorForObject = ':';
public CruiserGenericStorage(int pictureWidth, int pictureHeight)
{
_cruiserStorages = new Dictionary<string, CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
_cruiserStorages.Add(name, new CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>(_pictureWidth, _pictureHeight));
}
public void DelSet(string name)
{
if (!_cruiserStorages.ContainsKey(name))
{
return;
}
_cruiserStorages.Remove(name);
}
public CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>? this[string ind]
{
get
{
if (_cruiserStorages.ContainsKey(ind))
{
return _cruiserStorages[ind];
}
return null;
}
}
/// <summary>
/// Сохранение информации по самолетам в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка сохранении данных</returns>
public bool SaveData(string filename)
{
if (File.Exists(filename))
@@ -55,33 +33,30 @@ namespace Cruiser.Generics
File.Delete(filename);
}
StringBuilder data = new();
foreach (KeyValuePair<string, CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>> record in _cruiserStorages)
foreach (KeyValuePair<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> record in _planeStorage)
{
StringBuilder records = new();
foreach (DrawningCruiser? elem in record.Value.GetCruiser)
foreach (DrawingPlane? elem in record.Value.GetPlanes)
{
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
}
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
}
if (data.Length == 0)
{
return false;
}
string toWrite = $"CruiserStorage{Environment.NewLine}{data}";
var strs = toWrite.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
using (StreamWriter sw = new(filename))
{
foreach (var str in strs)
{
sw.WriteLine(str);
}
sw.WriteLine($"PlaneStorage{Environment.NewLine}{data}");
}
return true;
}
/// <summary>
/// Загрузка информации по автомобилям в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
public bool LoadData(string filename)
{
if (!File.Exists(filename))
@@ -96,11 +71,11 @@ namespace Cruiser.Generics
{
return false;
}
if (!strs[0].StartsWith("CruiserStorage"))
if (!strs[0].StartsWith("PlaneStorage"))
{
return false;
}
_cruiserStorages.Clear();
_planeStorage.Clear();
do
{
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
@@ -109,26 +84,64 @@ namespace Cruiser.Generics
str = sr.ReadLine();
continue;
}
CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords,
StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawningCruiser? cruiser =
elem?.CreateDrawningCruiser(_separatorForObject, _pictureWidth, _pictureHeight);
if (cruiser != null)
DrawingPlane? plane =
elem?.CreateDrawingPlane(_separatorForObject, _pictureWidth, _pictureHeight);
if (plane != null)
{
if (!(collection + cruiser))
if (!(collection + plane))
{
return false;
}
}
}
_cruiserStorages.Add(record[0], collection);
_planeStorage.Add(record[0], collection);
str = sr.ReadLine();
} while (str != null);
}
return true;
}
readonly Dictionary<string, PlanesGenericCollection<DrawingPlane,
DrawingObjectPlane>> _planeStorage;
public List<string> Keys => _planeStorage.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
{
_planeStorage = new Dictionary<string, PlanesGenericCollection<DrawingPlane,
DrawingObjectPlane>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
_planeStorage.Add(name,
new PlanesGenericCollection<DrawingPlane,
DrawingObjectPlane>(_pictureWidth, _pictureHeight));
}
public void DelSet(string name)
{
if (!_planeStorage.ContainsKey(name))
return;
_planeStorage.Remove(name);
}
public PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>? this[string ind]
{
get
{
if (_planeStorage.ContainsKey(ind))
return _planeStorage[ind];
return null;
}
}
}
}

View File

@@ -4,13 +4,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser
namespace Monorail
{
public enum Direction
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@@ -1,58 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cruiser.Entities;
namespace Cruiser.DrawningObjects
{
public class DrawningAdvancedCruiser : DrawningCruiser
{
public DrawningAdvancedCruiser(int speed, double weight, Color bodyColor, Color additionalColor, bool helicopterPad, bool coating, int width, int height) : base(speed, weight, bodyColor, width, height, 110, 60)
{
if (EntityCruiser != null)
{
EntityCruiser = new EntityAdvancedCruiser(speed, weight, bodyColor, additionalColor, helicopterPad, coating);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityCruiser is not EntityAdvancedCruiser cruiser)
{
return;
}
Brush addBrush = new SolidBrush(cruiser.AdditionalColor);
base.DrawTransport(g);
if (cruiser.HelicopterPad)
{
Point[] trianglePoints1 =
{
new Point(_startPosX + 20, _startPosY + 5),
new Point(_startPosX + 40, _startPosY + 25),
new Point(_startPosX + 60, _startPosY + 5)
};
Point[] trianglePoints2 =
{
new Point(_startPosX + 20, _startPosY + 55),
new Point(_startPosX + 40, _startPosY + 35),
new Point(_startPosX + 60, _startPosY + 55)
};
g.FillPolygon(addBrush, trianglePoints1);
g.FillPolygon(addBrush, trianglePoints2);
}
if (cruiser.Coating)
{
g.FillEllipse(addBrush, _startPosX + 90, _startPosY + 20, 20, 20);
}
}
}
}

View File

@@ -1,136 +1,169 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.Entities;
using Cruiser.MovementStrategy;
using Cruiser;
using Monorail.Entities;
using Monorail.MovementStrategy;
namespace Cruiser.DrawningObjects
namespace Monorail.DrawningObjects
{
public class DrawningCruiser
public class DrawingPlane
{
public EntityCruiser? EntityCruiser { get; protected set; }
public EntityPlane? EntityPlane { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
private readonly int _cruiserWidth = 110;
private readonly int _cruiserHeight = 60;
protected readonly int _planeWidth = 160;
protected readonly int _planeHeight = 160;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _cruiserWidth;
public int GetHeight => _cruiserHeight;
public IMoveableObject GetMoveableObject => new DrawningObjectCruiser(this);
public DrawningCruiser(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _cruiserWidth || height < _cruiserHeight)
public int GetWidth => _planeWidth;
public int GetHeight => _planeHeight;
public DrawingPlane(int speed, double weight, Color bodyColor, int width, int height)
{
if (_planeWidth > width || _planeHeight > height)
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
protected DrawningCruiser(int speed, double weight, Color bodyColor, int
width, int height, int cruiserWidth, int cruiserHeight)
{
if (width <= _cruiserWidth || height <= _cruiserHeight)
public void ChangeColor(Color col)
{
if (EntityPlane == null)
return;
EntityPlane.BodyColor = col;
}
protected DrawingPlane(int speed, double weight, Color bodyColor, int width, int height, int planeWidth, int planeHeight)
{
if (_planeWidth > width || _planeHeight > height)
return;
_pictureWidth = width;
_pictureHeight = height;
_cruiserWidth = cruiserWidth;
_cruiserHeight = cruiserHeight;
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
_planeWidth = planeWidth;
_planeHeight = planeHeight;
EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
public IMoveableObject GetMoveableObject => new DrawingObjectPlane(this);
public void SetPosition(int x, int y)
{
if (x < 0 || x + _cruiserWidth > _pictureWidth)
{
x = Math.Max(0, _pictureWidth - _cruiserWidth);
}
if (y < 0 || y + _cruiserHeight > _pictureHeight)
{
y = Math.Max(0, _pictureHeight - _cruiserHeight);
}
if (x < 0 || y < 0 || x + _planeWidth >= _pictureWidth || y + _planeHeight >= _pictureHeight)
x = y = 2;
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(Direction direction)
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному направлению</returns>
public bool CanMove(DirectionType direction)
{
if (!CanMove(direction) || EntityCruiser == null)
{
return;
}
switch (direction)
{
case Direction.Left:
_startPosX -= (int)EntityCruiser.Step;
break;
case Direction.Up:
_startPosY -= (int)EntityCruiser.Step;
break;
case Direction.Right:
_startPosX += (int)EntityCruiser.Step;
break;
case Direction.Down:
_startPosY += (int)EntityCruiser.Step;
break;
}
}
public bool CanMove(Direction direction)
{
if (EntityCruiser == null)
if (EntityPlane == null)
{
return false;
}
return direction switch
{
Direction.Left => _startPosX - EntityCruiser.Step > 0,
Direction.Up => _startPosY - EntityCruiser.Step > 0,
Direction.Right => _startPosX + EntityCruiser.Step + _cruiserWidth < _pictureWidth,
Direction.Down => _startPosY + EntityCruiser.Step + _cruiserHeight < _pictureHeight,
//влево
DirectionType.Left => _startPosX - EntityPlane.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityPlane.Step > 0,
// вправо
DirectionType.Right => _startPosX + EntityPlane.Step + _planeWidth < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + EntityPlane.Step + _planeHeight < _pictureHeight,
_ => false,
};
}
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
_pictureWidth = pictureBoxWidth;
_pictureHeight = pictureBoxHeight;
}
public virtual void DrawTransport(Graphics g)
{
if (EntityCruiser == null)
if (!CanMove(direction) || EntityPlane == null)
{
return;
}
Pen pen = new Pen(Color.Black);
Brush brush = new SolidBrush(EntityCruiser.BodyColor);
switch (direction)
{
//влево
case DirectionType.Left:
_startPosX -= (int)EntityPlane.Step;
break;
//вверх
case DirectionType.Up:
_startPosY -= (int)EntityPlane.Step;
break;
// вправо
case DirectionType.Right:
_startPosX += (int)EntityPlane.Step;
break;
//вниз
case DirectionType.Down:
_startPosY += (int)EntityPlane.Step;
break;
}
}
public virtual void DrawTransport(Graphics g)
{
if (EntityPlane == null)
{
return;
}
Pen pen = new Pen(Color.Black, 2);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 5, 20, 20);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 35, 20, 20);
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
30);
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
Brush br = new SolidBrush(EntityCruiser.BodyColor);
Brush br = new SolidBrush(EntityPlane.BodyColor);
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
Point[] points = new Point[3];//
Point[] points = new Point[3];// нос лодки
points[0] = new Point(_startPosX + 100, _startPosY + 5);
points[1] = new Point(_startPosX + 100, _startPosY + 55);
points[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
g.FillPolygon(Brushes.Pink, points);
//границы носа лодки
Point[] points1 = new Point[3];// нос лодки
points1[0] = new Point(_startPosX + 100, _startPosY + 5);
points1[1] = new Point(_startPosX + 100, _startPosY + 55);
points1[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
g.DrawPolygon(pen, points1);
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 15, 10, 10);
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 35, 10, 10);
//если есть ракетные шахты, добавить условие
g.DrawRectangle(Pens.Black, _startPosX + 35,
_startPosY + 23, 15, 15);
g.DrawRectangle(Pens.Black, _startPosX + 50,
_startPosY + 19, 30, 25);
}
}
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser;
using Monorail.DrawningObjects;
namespace Monorail.MovementStrategy
{
public class DrawingObjectPlane : IMoveableObject
{
private readonly DrawingPlane? _drawningPlane = null;
public DrawingObjectPlane(DrawingPlane drawingPlane)
{
_drawningPlane = drawingPlane;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningPlane == null || _drawningPlane.EntityPlane ==
null)
{
return null;
}
return new ObjectParameters(_drawningPlane.GetPosX,
_drawningPlane.GetPosY, _drawningPlane.GetWidth, _drawningPlane.GetHeight);
}
}
public int GetStep => (int)(_drawningPlane?.EntityPlane?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawningPlane?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawningPlane?.MoveTransport(direction);
}
}

View File

@@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.DrawningObjects;
namespace Cruiser.MovementStrategy
{
internal class DrawningObjectCruiser : IMoveableObject
{
private readonly DrawningCruiser? _drawningCruiser = null;
public DrawningObjectCruiser(DrawningCruiser drawningCruiser)
{
_drawningCruiser = drawningCruiser;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningCruiser == null || _drawningCruiser.EntityCruiser ==
null)
{
return null;
}
return new ObjectParameters(_drawningCruiser.GetPosX,
_drawningCruiser.GetPosY, _drawningCruiser.GetWidth, _drawningCruiser.GetHeight);
}
}
public int GetStep => (int)(_drawningCruiser?.EntityCruiser?.Step ?? 0);
public bool CheckCanMove(Direction direction) =>
_drawningCruiser?.CanMove(direction) ?? false;
public void MoveObject(Direction direction) =>
_drawningCruiser?.MoveTransport(direction);
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Monorail.Entities;
namespace Monorail.DrawningObjects
{
public class DrawingAirBomber : DrawingPlane
{
public DrawingAirBomber(int speed, double weight, Color bodyColor, Color
additionalColor, bool bombs, bool wing, int width, int height)
: base(speed, width, bodyColor, width, height, 160, 160)
{
if (EntityPlane != null)
{
EntityPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, wing);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityPlane is not EntityAirBomber airBomber)
{
return;
}
base.DrawTransport(g);
Pen pen = new Pen(Color.Black, 2);
Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor);
if (airBomber.Fuel)
{
Point[] trianglePoints1 =
{
new Point(_startPosX + 20, _startPosY + 5),
new Point(_startPosX + 40, _startPosY + 25),
new Point(_startPosX + 60, _startPosY + 5)
};
Point[] trianglePoints2 =
{
new Point(_startPosX + 20, _startPosY + 55),
new Point(_startPosX + 40, _startPosY + 35),
new Point(_startPosX + 60, _startPosY + 55)
};
g.FillPolygon(additionalBrush, trianglePoints1);
g.FillPolygon(additionalBrush, trianglePoints2);
}
if (airBomber.Bombs)
{
g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 20, 20, 20);
}
}
}
}

View File

@@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Cruiser.Entities
{
public class EntityAdvancedCruiser : EntityCruiser
{
public Color AdditionalColor { get; private set; }
public bool HelicopterPad { get; private set; }
public bool Coating { get; private set; }
public EntityAdvancedCruiser(int speed, double weight, Color bodyColor, Color
additionalColor, bool helicopterPad, bool coating) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
HelicopterPad = helicopterPad;
Coating = coating;
}
public void setAdditionalColor(Color color)
{
AdditionalColor = color;
}
}
}

View File

@@ -1,43 +1,56 @@
using System;
using Monorail.DrawningObjects;
using Monorail.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.Entities;
namespace Cruiser.DrawningObjects
namespace Cruiser
{
public static class ExtentionDrawingCruiser
public static class ExtentionDrawingPlane
{
public static DrawningCruiser? CreateDrawningCruiser(this string info, char separatorForObject, int width, int height)
public static DrawingPlane? CreateDrawingPlane(this string info, char
separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawningCruiser(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
return new DrawingPlane(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
if (strs.Length == 7)
if (strs.Length == 6)
{
return new DrawningAdvancedCruiser(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]), width, height);
return new DrawingAirBomber(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]),
Color.FromName(strs[2]),
Color.FromName(strs[3]),
Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]), width, height);
}
return null;
}
public static string GetDataForSave(this DrawningCruiser drawningcruiser, char separatorForObject)
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawingPlane">Сохраняемый объект</param>
/// <param name="separatorForObject">Разделитель даннных</param>
/// <returns>Строка с данными по объекту</returns>
public static string GetDataForSave(this DrawingPlane drawingPlane,
char separatorForObject)
{
var cruiser = drawningcruiser.EntityCruiser;
if (cruiser == null)
var plane = drawingPlane.EntityPlane;
if (plane == null)
{
return string.Empty;
}
var str = $"{cruiser.Speed}{separatorForObject}{cruiser.Weight}{separatorForObject}{cruiser.BodyColor.Name}";
if (cruiser is not EntityAdvancedCruiser advancedCruiser)
var str = $"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}";
if (plane is not EntityAirBomber airBomber)
{
return str;
}
return
$"{str}{separatorForObject}{advancedCruiser.AdditionalColor.Name}{separatorForObject}" +
$"{separatorForObject}{advancedCruiser.HelicopterPad}{separatorForObject}{advancedCruiser.Coating}";
}
$"{str}{separatorForObject}{airBomber.AdditionalColor.Name}{separatorForObject}{airBomber.Bombs}{separatorForObject}{airBomber.Fuel}";
}
}
}

196
Cruiser/Cruiser/Form1.Designer.cs generated Normal file
View File

@@ -0,0 +1,196 @@
namespace Cruiser
{
partial class CruiserForm
{
/// <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>
#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.button1 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.ButtonStep = new System.Windows.Forms.Button();
this.SelectedCruiser = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(386, 68);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 34);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(667, 358);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.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::Cruiser.Properties.Resources.вниз;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(543, 306);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 1;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.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::Cruiser.Properties.Resources.влево;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(517, 306);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 2;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.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::Cruiser.Properties.Resources.вправо;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(567, 306);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 3;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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::Cruiser.Properties.Resources.вверх;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(543, 284);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 4;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(0, 302);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(218, 34);
this.buttonCreate.TabIndex = 5;
this.buttonCreate.Text = "Создать простую";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button2.Location = new System.Drawing.Point(210, 301);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(251, 37);
this.button2.TabIndex = 6;
this.button2.Text = "Создать про версию";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"Центр",
"Угол"});
this.comboBox1.Location = new System.Drawing.Point(415, 22);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(182, 33);
this.comboBox1.TabIndex = 7;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// ButtonStep
//
this.ButtonStep.Location = new System.Drawing.Point(485, 70);
this.ButtonStep.Name = "ButtonStep";
this.ButtonStep.Size = new System.Drawing.Size(112, 34);
this.ButtonStep.TabIndex = 8;
this.ButtonStep.Text = "Шаг";
this.ButtonStep.UseVisualStyleBackColor = true;
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
//
// SelectedCruiser
//
this.SelectedCruiser.Location = new System.Drawing.Point(210, 261);
this.SelectedCruiser.Name = "SelectedCruiser";
this.SelectedCruiser.Size = new System.Drawing.Size(112, 34);
this.SelectedCruiser.TabIndex = 9;
this.SelectedCruiser.Text = "Выбрать";
this.SelectedCruiser.UseVisualStyleBackColor = true;
this.SelectedCruiser.Click += new System.EventHandler(this.SelectedCruiser_Click);
//
// CruiserForm
//
this.ClientSize = new System.Drawing.Size(667, 358);
this.Controls.Add(this.SelectedCruiser);
this.Controls.Add(this.ButtonStep);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.pictureBox1);
this.Name = "CruiserForm";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
/// <param name="e"></param>
#endregion
private Button button1;
private PictureBox pictureBox1;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
private Button buttonUp;
private Button buttonCreate;
private Button button2;
private ComboBox comboBox1;
private Button ButtonStep;
private Button SelectedCruiser;
}
}

168
Cruiser/Cruiser/Form1.cs Normal file
View File

@@ -0,0 +1,168 @@
using System;
using Cruiser;
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 Monorail.DrawningObjects;
using Monorail.MovementStrategy;
using Monorail;
namespace Cruiser
{
public partial class CruiserForm : Form
{
private DrawingPlane? _drawingPlane;
private AbstractStrategy? _strategy;
public DrawingPlane? SelectedPlane { get; private set; }
public CruiserForm()
{
InitializeComponent();
_strategy = null;
SelectedPlane = null;
}
private void Draw()
{
if (_drawingPlane == null)
{
return;
}
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingPlane.DrawTransport(gr);
pictureBox1.Image = bmp;
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingPlane == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingPlane.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawingPlane.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawingPlane.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawingPlane.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void button2_Click(object sender, EventArgs e)
{
Random random = new();
Color mainColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
Color additColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
mainColor = dialog.Color;
}
if (dialog.ShowDialog() == DialogResult.OK)
{
additColor = dialog.Color;
}
_drawingPlane = new DrawingAirBomber(random.Next(100, 300),
random.Next(1000, 3000), mainColor, additColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBox1.Width, pictureBox1.Height);
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawingPlane == null)
{
return;
}
if (comboBox1.Enabled)
{
_strategy = comboBox1.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToEdge(),
_ => null,
};
if (_strategy == null)
{
return;
}
_strategy.SetData(new
DrawingObjectPlane(_drawingPlane), pictureBox1.Width,
pictureBox1.Height);
comboBox1.Enabled = false;
}
if (_strategy == null)
{
return;
}
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == Status.Finish)
{
comboBox1.Enabled = true;
_strategy = null;
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_drawingPlane = new DrawingPlane(random.Next(100, 300),
random.Next(1000, 3000), color,
pictureBox1.Width, pictureBox1.Height);
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
public void SelectedCruiser_Click(object sender, EventArgs e)
{
SelectedPlane = _drawingPlane;
DialogResult = DialogResult.OK;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}

383
Cruiser/Cruiser/Form2.Designer.cs generated Normal file
View File

@@ -0,0 +1,383 @@
namespace Cruiser
{
partial class Form2
{
/// <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.groupBox1 = new System.Windows.Forms.GroupBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.panel3 = new System.Windows.Forms.Panel();
this.label_addit_color = new System.Windows.Forms.Label();
this.label_color = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.labelAdvanced = new System.Windows.Forms.Label();
this.labelBasic = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.panel9 = new System.Windows.Forms.Panel();
this.panel8 = new System.Windows.Forms.Panel();
this.panel7 = new System.Windows.Forms.Panel();
this.panel6 = new System.Windows.Forms.Panel();
this.panel5 = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.panel1 = new System.Windows.Forms.Panel();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.panel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.checkBox2);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.panel3);
this.groupBox1.Controls.Add(this.labelAdvanced);
this.groupBox1.Controls.Add(this.labelBasic);
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.checkBox1);
this.groupBox1.Controls.Add(this.numericUpDown2);
this.groupBox1.Controls.Add(this.numericUpDown1);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(57, 43);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(1163, 391);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Параметры";
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(33, 277);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(232, 29);
this.checkBox2.TabIndex = 12;
this.checkBox2.Text = "Наличие ракетных шахт";
this.checkBox2.UseVisualStyleBackColor = true;
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
//
// button2
//
this.button2.Location = new System.Drawing.Point(991, 321);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(127, 38);
this.button2.TabIndex = 11;
this.button2.Text = "Отмена";
this.button2.UseVisualStyleBackColor = true;
//
// button1
//
this.button1.Location = new System.Drawing.Point(838, 321);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(136, 38);
this.button1.TabIndex = 10;
this.button1.Text = "Добавить";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// panel3
//
this.panel3.AllowDrop = true;
this.panel3.Controls.Add(this.label_addit_color);
this.panel3.Controls.Add(this.label_color);
this.panel3.Controls.Add(this.pictureBox1);
this.panel3.Location = new System.Drawing.Point(822, 45);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(312, 261);
this.panel3.TabIndex = 9;
this.panel3.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panel3.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// label_addit_color
//
this.label_addit_color.AllowDrop = true;
this.label_addit_color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_addit_color.Location = new System.Drawing.Point(169, 23);
this.label_addit_color.Name = "label_addit_color";
this.label_addit_color.Size = new System.Drawing.Size(117, 38);
this.label_addit_color.TabIndex = 10;
this.label_addit_color.Text = "Доп.цвет";
this.label_addit_color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_addit_color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelAddColor_DragDrop);
this.label_addit_color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelAddColor_DragEnter);
//
// label_color
//
this.label_color.AllowDrop = true;
this.label_color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_color.Location = new System.Drawing.Point(30, 23);
this.label_color.Name = "label_color";
this.label_color.Size = new System.Drawing.Size(110, 38);
this.label_color.TabIndex = 9;
this.label_color.Text = "Цвет";
this.label_color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
this.label_color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(76, 64);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(163, 178);
this.pictureBox1.TabIndex = 8;
this.pictureBox1.TabStop = false;
//
// labelAdvanced
//
this.labelAdvanced.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAdvanced.Location = new System.Drawing.Point(521, 293);
this.labelAdvanced.Name = "labelAdvanced";
this.labelAdvanced.Size = new System.Drawing.Size(141, 47);
this.labelAdvanced.TabIndex = 7;
this.labelAdvanced.Text = "Продвинутый";
this.labelAdvanced.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelAdvanced.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelBasic
//
this.labelBasic.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelBasic.Location = new System.Drawing.Point(369, 293);
this.labelBasic.Name = "labelBasic";
this.labelBasic.Size = new System.Drawing.Size(131, 47);
this.labelBasic.TabIndex = 6;
this.labelBasic.Text = "Простой";
this.labelBasic.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBasic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.panel9);
this.groupBox2.Controls.Add(this.panel8);
this.groupBox2.Controls.Add(this.panel7);
this.groupBox2.Controls.Add(this.panel6);
this.groupBox2.Controls.Add(this.panel5);
this.groupBox2.Controls.Add(this.panel4);
this.groupBox2.Controls.Add(this.panel2);
this.groupBox2.Controls.Add(this.panel1);
this.groupBox2.Location = new System.Drawing.Point(335, 40);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(357, 231);
this.groupBox2.TabIndex = 5;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Цвета";
//
// panel9
//
this.panel9.BackColor = System.Drawing.Color.Fuchsia;
this.panel9.Location = new System.Drawing.Point(264, 153);
this.panel9.Name = "panel9";
this.panel9.Size = new System.Drawing.Size(53, 49);
this.panel9.TabIndex = 7;
//
// panel8
//
this.panel8.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
this.panel8.Location = new System.Drawing.Point(180, 153);
this.panel8.Name = "panel8";
this.panel8.Size = new System.Drawing.Size(53, 49);
this.panel8.TabIndex = 6;
//
// panel7
//
this.panel7.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
this.panel7.Location = new System.Drawing.Point(108, 153);
this.panel7.Name = "panel7";
this.panel7.Size = new System.Drawing.Size(53, 49);
this.panel7.TabIndex = 5;
//
// panel6
//
this.panel6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
this.panel6.Location = new System.Drawing.Point(34, 153);
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(53, 49);
this.panel6.TabIndex = 4;
//
// panel5
//
this.panel5.BackColor = System.Drawing.Color.Purple;
this.panel5.Location = new System.Drawing.Point(264, 44);
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(53, 49);
this.panel5.TabIndex = 3;
//
// panel4
//
this.panel4.BackColor = System.Drawing.Color.DarkOrchid;
this.panel4.Location = new System.Drawing.Point(186, 44);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(53, 49);
this.panel4.TabIndex = 2;
//
// panel2
//
this.panel2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.panel2.Location = new System.Drawing.Point(108, 44);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(53, 49);
this.panel2.TabIndex = 1;
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.ButtonHighlight;
this.panel1.Location = new System.Drawing.Point(32, 44);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(55, 49);
this.panel1.TabIndex = 0;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(33, 213);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(310, 29);
this.checkBox1.TabIndex = 4;
this.checkBox1.Text = "Наличие площадки под вертолет";
this.checkBox1.UseVisualStyleBackColor = true;
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(128, 143);
this.numericUpDown2.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDown2.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(84, 31);
this.numericUpDown2.TabIndex = 3;
this.numericUpDown2.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(128, 75);
this.numericUpDown1.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDown1.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(74, 31);
this.numericUpDown1.TabIndex = 2;
this.numericUpDown1.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(33, 145);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(43, 25);
this.label2.TabIndex = 1;
this.label2.Text = "Вес:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(33, 75);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(93, 25);
this.label1.TabIndex = 0;
this.label1.Text = "Скорость:";
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1279, 552);
this.Controls.Add(this.groupBox1);
this.Name = "Form2";
this.Text = "Создание объекта";
this.Load += new System.EventHandler(this.Form2_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.panel3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private Button button2;
private Button button1;
private Panel panel3;
private Label label_addit_color;
private Label label_color;
private PictureBox pictureBox1;
private Label labelAdvanced;
private Label labelBasic;
private GroupBox groupBox2;
private Panel panel2;
private Panel panel1;
private CheckBox checkBox1;
private NumericUpDown numericUpDown2;
private NumericUpDown numericUpDown1;
private Label label2;
private Label label1;
private CheckBox checkBox2;
private Panel panel9;
private Panel panel8;
private Panel panel7;
private Panel panel6;
private Panel panel5;
private Panel panel4;
}
}

214
Cruiser/Cruiser/Form2.cs Normal file
View File

@@ -0,0 +1,214 @@
using Monorail.DrawningObjects;
using Monorail.Entities;
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 Cruiser
{
public partial class Form2 : Form
{
public int _pictureWidth { get; private set; }
public int _pictureHeight { get; private set; }
/// <summary>
/// Переменная
/// </summary>
DrawingPlane? _plane = null;
/// <summary>
/// Событие
/// </summary>
public event Action<DrawingPlane>? EventAddPlane;
public Form2(int pictureWidth, int pictureHeight)
{
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
InitializeComponent();
panel1.MouseDown += PanelColor_MouseDown;
panel2.MouseDown += PanelColor_MouseDown;
panel3.MouseDown += PanelColor_MouseDown;
panel4.MouseDown += PanelColor_MouseDown;
panel5.MouseDown += PanelColor_MouseDown;
panel6.MouseDown += PanelColor_MouseDown;
panel7.MouseDown += PanelColor_MouseDown;
panel8.MouseDown += PanelColor_MouseDown;
panel9.MouseDown += PanelColor_MouseDown;
button2.Click += (s, e) => Close();
}
private void DrawPlane()
{
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
Graphics gr = Graphics.FromImage(bmp);
_plane?.SetPosition(5, 5);
_plane?.DrawTransport(gr);
pictureBox1.Image = bmp;
}
public void AddEvent(Action<DrawingPlane> ev)
{
if (EventAddPlane == null)
{
EventAddPlane = ev;
}
else
{
EventAddPlane += ev;
}
}
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) ?? false)
{
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 "labelBasic":
_plane = new DrawingPlane((int)numericUpDown1.Value,
(int)numericUpDown2.Value, Color.White, _pictureWidth, _pictureHeight);
break;
case "labelAdvanced":
_plane = new DrawingAirBomber((int)numericUpDown1.Value,
(int)numericUpDown2.Value, Color.White, Color.Black, checkBox1.Checked,
checkBox2.Checked, _pictureWidth, _pictureHeight);
break;
}
DrawPlane();
}
private void PanelColor_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Добавление
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (_plane == null)
return;
EventAddPlane?.Invoke(_plane);
Close();
}
private void labelColor_DragDrop(object sender, DragEventArgs e)
{
if (_plane?.EntityPlane == null)
return;
switch (((Label)sender).Name)
{
case "label_color":
_plane?.EntityPlane?.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "label_addit_color":
if (!(_plane is DrawingAirBomber))
return;
(_plane.EntityPlane as EntityAirBomber)?.setAdditionalColor(color: (Color)e.Data.GetData(typeof(Color)));
break;
}
//на всякий случай
Color bodyColor = (Color)e.Data.GetData(typeof(Color));
if (_plane is DrawingAirBomber)
{
_plane = new DrawingAirBomber((int)numericUpDown1.Value,
(int)numericUpDown2.Value, bodyColor, ((EntityAirBomber)_plane.EntityPlane).AdditionalColor, checkBox1.Checked,
checkBox2.Checked, _pictureWidth, _pictureHeight);
}
else
{
_plane = new DrawingPlane((int)numericUpDown1.Value,
(int)numericUpDown2.Value, bodyColor, _pictureWidth, _pictureHeight);
}
//
DrawPlane();
}
private void labelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void labelAddColor_DragDrop(object sender, DragEventArgs e)
{
if ((_plane?.EntityPlane == null) || (_plane is DrawingAirBomber == false))
return;
Color additionalColor = (Color)e.Data.GetData(typeof(Color));
_plane = new DrawingAirBomber((int)numericUpDown1.Value,
(int)numericUpDown1.Value, _plane.EntityPlane.BodyColor, additionalColor, checkBox1.Checked,
checkBox2.Checked, _pictureWidth, _pictureHeight);
DrawPlane();
}
private void labelAddColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void ButtonAddCruiser()
{
throw new NotImplementedException();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
}
}
}

View File

@@ -1,8 +1,18 @@
namespace Cruiser
using System.Windows.Forms;
namespace Cruiser
{
partial class FormCruiserCollection
{
/// <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))
@@ -13,178 +23,175 @@
}
#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.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.panelCruiser = new System.Windows.Forms.Panel();
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
this.ButtonRemoveCruiser = new System.Windows.Forms.Button();
this.textBoxCruiser = new System.Windows.Forms.TextBox();
this.ButtonAddCruiser = new System.Windows.Forms.Button();
this.panelSet = new System.Windows.Forms.Panel();
this.ButtonDelObject = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel1 = new System.Windows.Forms.Panel();
this.textBox2 = new System.Windows.Forms.TextBox();
this.addStorageButton = new System.Windows.Forms.Button();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.ButtonAddObject = new System.Windows.Forms.Button();
this.textBoxSet = new System.Windows.Forms.TextBox();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.button2 = new System.Windows.Forms.Button();
this.updateCollectionButton = new System.Windows.Forms.Button();
this.ButtonRemoveCar = new System.Windows.Forms.Button();
this.ButtonAddCruiser = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.FileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
this.panelCruiser.SuspendLayout();
this.panelSet.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.panel1.SuspendLayout();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxCruiser
// pictureBox1
//
this.pictureBoxCruiser.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCruiser.Location = new System.Drawing.Point(0, 33);
this.pictureBoxCruiser.Name = "pictureBoxCruiser";
this.pictureBoxCruiser.Size = new System.Drawing.Size(904, 477);
this.pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCruiser.TabIndex = 0;
this.pictureBoxCruiser.TabStop = false;
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 33);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(971, 511);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// panelCruiser
// panel1
//
this.panelCruiser.Controls.Add(this.ButtonRefreshCollection);
this.panelCruiser.Controls.Add(this.ButtonRemoveCruiser);
this.panelCruiser.Controls.Add(this.textBoxCruiser);
this.panelCruiser.Controls.Add(this.ButtonAddCruiser);
this.panelCruiser.Controls.Add(this.panelSet);
this.panelCruiser.Location = new System.Drawing.Point(655, 12);
this.panelCruiser.Name = "panelCruiser";
this.panelCruiser.Size = new System.Drawing.Size(221, 486);
this.panelCruiser.TabIndex = 1;
this.panel1.Controls.Add(this.textBox2);
this.panel1.Controls.Add(this.addStorageButton);
this.panel1.Controls.Add(this.listBoxStorages);
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.updateCollectionButton);
this.panel1.Controls.Add(this.ButtonRemoveCar);
this.panel1.Controls.Add(this.ButtonAddCruiser);
this.panel1.Controls.Add(this.textBox1);
this.panel1.Location = new System.Drawing.Point(692, 12);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(267, 520);
this.panel1.TabIndex = 1;
//
// ButtonRefreshCollection
// textBox2
//
this.ButtonRefreshCollection.Location = new System.Drawing.Point(45, 435);
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
this.ButtonRefreshCollection.Size = new System.Drawing.Size(138, 41);
this.ButtonRefreshCollection.TabIndex = 2;
this.ButtonRefreshCollection.Text = "Обновить";
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
this.textBox2.Location = new System.Drawing.Point(60, 36);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(150, 31);
this.textBox2.TabIndex = 2;
//
// ButtonRemoveCruiser
// addStorageButton
//
this.ButtonRemoveCruiser.Location = new System.Drawing.Point(45, 391);
this.ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
this.ButtonRemoveCruiser.Size = new System.Drawing.Size(138, 38);
this.ButtonRemoveCruiser.TabIndex = 2;
this.ButtonRemoveCruiser.Text = "Удалить";
this.ButtonRemoveCruiser.UseVisualStyleBackColor = true;
this.ButtonRemoveCruiser.Click += new System.EventHandler(this.ButtonRemoveCruiser_Click);
//
// textBoxCruiser
//
this.textBoxCruiser.Location = new System.Drawing.Point(45, 330);
this.textBoxCruiser.Name = "textBoxCruiser";
this.textBoxCruiser.Size = new System.Drawing.Size(133, 31);
this.textBoxCruiser.TabIndex = 3;
//
// ButtonAddCruiser
//
this.ButtonAddCruiser.Location = new System.Drawing.Point(45, 266);
this.ButtonAddCruiser.Name = "ButtonAddCruiser";
this.ButtonAddCruiser.Size = new System.Drawing.Size(133, 38);
this.ButtonAddCruiser.TabIndex = 2;
this.ButtonAddCruiser.Text = "Добавить";
this.ButtonAddCruiser.UseVisualStyleBackColor = true;
this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click);
//
// panelSet
//
this.panelSet.Controls.Add(this.ButtonDelObject);
this.panelSet.Controls.Add(this.listBoxStorages);
this.panelSet.Controls.Add(this.ButtonAddObject);
this.panelSet.Controls.Add(this.textBoxSet);
this.panelSet.Location = new System.Drawing.Point(22, 19);
this.panelSet.Name = "panelSet";
this.panelSet.Size = new System.Drawing.Size(185, 241);
this.panelSet.TabIndex = 0;
//
// ButtonDelObject
//
this.ButtonDelObject.Location = new System.Drawing.Point(18, 175);
this.ButtonDelObject.Name = "ButtonDelObject";
this.ButtonDelObject.Size = new System.Drawing.Size(153, 47);
this.ButtonDelObject.TabIndex = 2;
this.ButtonDelObject.Text = "Удалить набор";
this.ButtonDelObject.UseVisualStyleBackColor = true;
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
this.addStorageButton.Location = new System.Drawing.Point(79, 88);
this.addStorageButton.Name = "addStorageButton";
this.addStorageButton.Size = new System.Drawing.Size(112, 34);
this.addStorageButton.TabIndex = 2;
this.addStorageButton.Text = "Добавить";
this.addStorageButton.UseVisualStyleBackColor = true;
this.addStorageButton.Click += new System.EventHandler(this.addStorageButton_Click);
//
// listBoxStorages
//
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 25;
this.listBoxStorages.Location = new System.Drawing.Point(49, 115);
this.listBoxStorages.Location = new System.Drawing.Point(60, 128);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(97, 54);
this.listBoxStorages.TabIndex = 3;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged);
this.listBoxStorages.Size = new System.Drawing.Size(152, 104);
this.listBoxStorages.TabIndex = 4;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged);
//
// ButtonAddObject
// button2
//
this.ButtonAddObject.Location = new System.Drawing.Point(18, 58);
this.ButtonAddObject.Name = "ButtonAddObject";
this.ButtonAddObject.Size = new System.Drawing.Size(153, 51);
this.ButtonAddObject.TabIndex = 2;
this.ButtonAddObject.Text = "Создать набор";
this.ButtonAddObject.UseVisualStyleBackColor = true;
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
this.button2.Location = new System.Drawing.Point(60, 264);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(159, 36);
this.button2.TabIndex = 2;
this.button2.Text = "Удалить набор";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.delStorageButton_Click);
//
// textBoxSet
// updateCollectionButton
//
this.textBoxSet.Location = new System.Drawing.Point(38, 21);
this.textBoxSet.Name = "textBoxSet";
this.textBoxSet.Size = new System.Drawing.Size(118, 31);
this.textBoxSet.TabIndex = 0;
this.updateCollectionButton.Location = new System.Drawing.Point(79, 469);
this.updateCollectionButton.Name = "updateCollectionButton";
this.updateCollectionButton.Size = new System.Drawing.Size(112, 34);
this.updateCollectionButton.TabIndex = 2;
this.updateCollectionButton.Text = "Обновить";
this.updateCollectionButton.UseVisualStyleBackColor = true;
this.updateCollectionButton.Click += new System.EventHandler(this.button1_Click);
//
// openFileDialog
// ButtonRemoveCar
//
this.openFileDialog.FileName = "openFileDialog";
this.openFileDialog.Filter = "txt file | *.txt";
this.ButtonRemoveCar.Location = new System.Drawing.Point(60, 429);
this.ButtonRemoveCar.Name = "ButtonRemoveCar";
this.ButtonRemoveCar.Size = new System.Drawing.Size(150, 34);
this.ButtonRemoveCar.TabIndex = 2;
this.ButtonRemoveCar.Text = "Удалить";
this.ButtonRemoveCar.UseVisualStyleBackColor = true;
this.ButtonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
//
// ButtonAddCruiser
//
this.ButtonAddCruiser.Location = new System.Drawing.Point(60, 317);
this.ButtonAddCruiser.Name = "ButtonAddCruiser";
this.ButtonAddCruiser.Size = new System.Drawing.Size(150, 34);
this.ButtonAddCruiser.TabIndex = 3;
this.ButtonAddCruiser.Text = "Добавить";
this.ButtonAddCruiser.UseVisualStyleBackColor = true;
this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(60, 381);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(150, 31);
this.textBox1.TabIndex = 2;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// saveFileDialog
//
this.saveFileDialog.FileName = "PlanesStorage";
this.saveFileDialog.Filter = "txt file | *.txt";
//
// openFileDialog
//
this.openFileDialog.FileName = "openFileDialog1";
this.openFileDialog.Filter = "txt file | *.txt";
//
// menuStrip
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.FileToolStripMenuItem});
this.ToolStripMenuItem,
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(904, 33);
this.menuStrip.Size = new System.Drawing.Size(971, 33);
this.menuStrip.TabIndex = 2;
this.menuStrip.Text = "menuStrip";
//
// FileToolStripMenuItem
// ToolStripMenuItem
//
this.FileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem});
this.FileToolStripMenuItem.Name = "FileToolStripMenuItem";
this.FileToolStripMenuItem.Size = new System.Drawing.Size(69, 29);
this.FileToolStripMenuItem.Text = "Файл";
this.ToolStripMenuItem.Name = "ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(69, 29);
this.ToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(114, 29);
this.SaveToolStripMenuItem.Text = "Сохранить";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(108, 29);
this.LoadToolStripMenuItem.Text = "Загрузить";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
@@ -192,41 +199,38 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(904, 510);
this.Controls.Add(this.panelCruiser);
this.Controls.Add(this.pictureBoxCruiser);
this.ClientSize = new System.Drawing.Size(971, 544);
this.Controls.Add(this.panel1);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormCruiserCollection";
this.Text = "FormCruiserCollection";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
this.panelCruiser.ResumeLayout(false);
this.panelCruiser.PerformLayout();
this.panelSet.ResumeLayout(false);
this.panelSet.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxCruiser;
private Panel panelCruiser;
private Panel panelSet;
private TextBox textBoxSet;
private ListBox listBoxStorages;
private Button ButtonAddObject;
private Button ButtonDelObject;
private PictureBox pictureBox1;
private Panel panel1;
private Button ButtonRemoveCar;
private Button ButtonAddCruiser;
private Button ButtonRemoveCruiser;
private TextBox textBoxCruiser;
private Button ButtonRefreshCollection;
private OpenFileDialog openFileDialog;
private TextBox textBox1;
private Button updateCollectionButton;
private TextBox textBox2;
private Button addStorageButton;
private ListBox listBoxStorages;
private Button button2;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
private MenuStrip menuStrip;
private ToolStripMenuItem FileToolStripMenuItem;
private ToolStripMenuItem ToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
}

View File

@@ -1,5 +1,6 @@
using Cruiser.Generics;
using Cruiser.DrawningObjects;
using Monorail.DrawningObjects;
using Monorail.Generics;
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -10,16 +11,92 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Cruiser
{
public partial class FormCruiserCollection : Form
{
private readonly CruiserGenericStorage _storage;
private readonly PlanesGenericStorage _storage;
public FormCruiserCollection()
{
InitializeComponent();
_storage = new CruiserGenericStorage(pictureBoxCruiser.Width, pictureBoxCruiser.Height);
_storage = new PlanesGenericStorage(pictureBox1.Width, pictureBox1.Height);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Обработка нажатия "Загрузка"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
foreach (var collection in _storage.Keys)
{
listBoxStorages.Items.Add(collection);
}
}
else
{
MessageBox.Show("Не удалось загрузить", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
public void ButtonAddCruiser_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
Form2 form = new Form2(pictureBox1.Width, pictureBox1.Height);
form.Show();
Action<DrawingPlane>? planeDelegate = new((m) => {
bool q = (obj + m);
if (q)
{
MessageBox.Show("Объект добавлен");
pictureBox1.Image = obj.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
});
form.AddEvent(planeDelegate);
}
private void ReloadObjects()
{
@@ -30,75 +107,20 @@ namespace Cruiser
{
listBoxStorages.Items.Add(_storage.Keys[i]);
}
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
>= listBoxStorages.Items.Count))
{
listBoxStorages.SelectedIndex = 0;
}
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
index < listBoxStorages.Items.Count)
{
listBoxStorages.SelectedIndex = index;
}
}
private void ButtonAddObject_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxSet.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBoxSet.Text);
ReloadObjects();
}
private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxCruiser.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowCruisers();
}
private void ButtonDelObject_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
private void ButtonAddCruiser_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
FormCruiserConfig form = new();
form.Show();
Action<DrawningCruiser>? cruiserDelegate = new((m) =>
{
bool isAdditionSuccessful = (obj + m);
if (isAdditionSuccessful)
{
MessageBox.Show("Объект добавлен");
m.ChangePictureBoxSize(pictureBoxCruiser.Width, pictureBoxCruiser.Height);
pictureBoxCruiser.Image = obj.ShowCruisers();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
});
form.AddEvent(cruiserDelegate);
}
private void ButtonRemoveCruiser_Click(object sender, EventArgs e)
private void ButtonRemoveCar_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
@@ -115,18 +137,42 @@ namespace Cruiser
{
return;
}
int pos = Convert.ToInt32(textBoxCruiser.Text);
int pos;
if (textBox1.Text == null || !int.TryParse(textBox1.Text, out pos))
{
MessageBox.Show("Введите номер парковочного места");
return;
}
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCruiser.Image = obj.ShowCruisers();
pictureBox1.Image = obj.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
}
private void maskedTextBoxNumber_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
@@ -138,40 +184,46 @@ namespace Cruiser
{
return;
}
pictureBoxCruiser.Image = obj.ShowCruisers();
pictureBox1.Image = obj.ShowPlanes();
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
pictureBox1.Image =
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
}
else
private void delStorageButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
private void addStorageButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBox2.Text);
ReloadObjects();
}
}
}
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
foreach (var collection in _storage.Keys)
{
listBoxStorages.Items.Add(collection);
}
}
else
{
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

View File

@@ -57,13 +57,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>201, 17</value>
<value>28, 24</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>216, 24</value>
</metadata>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>379, 17</value>
<value>400, 24</value>
</metadata>
</root>

View File

@@ -1,381 +0,0 @@
namespace Cruiser
{
partial class FormCruiserConfig
{
/// <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.groupBoxCruiser = new System.Windows.Forms.GroupBox();
this.checkBoxMissileSilos = new System.Windows.Forms.CheckBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.panelOrchid = new System.Windows.Forms.Panel();
this.label_addit_color = new System.Windows.Forms.Label();
this.label_color = new System.Windows.Forms.Label();
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.labelAdvanced = new System.Windows.Forms.Label();
this.labelBasic = new System.Windows.Forms.Label();
this.groupBoxColor = new System.Windows.Forms.GroupBox();
this.panelColor = new System.Windows.Forms.Panel();
this.panelPink = new System.Windows.Forms.Panel();
this.panelViolet = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelLightBlue = new System.Windows.Forms.Panel();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.checkBoxHelicopterPad = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelWeight = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label();
this.groupBoxCruiser.SuspendLayout();
this.panelOrchid.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
this.groupBoxColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.SuspendLayout();
//
// groupBoxCruiser
//
this.groupBoxCruiser.Controls.Add(this.checkBoxMissileSilos);
this.groupBoxCruiser.Controls.Add(this.buttonCancel);
this.groupBoxCruiser.Controls.Add(this.buttonAdd);
this.groupBoxCruiser.Controls.Add(this.panelOrchid);
this.groupBoxCruiser.Controls.Add(this.labelAdvanced);
this.groupBoxCruiser.Controls.Add(this.labelBasic);
this.groupBoxCruiser.Controls.Add(this.groupBoxColor);
this.groupBoxCruiser.Controls.Add(this.checkBoxHelicopterPad);
this.groupBoxCruiser.Controls.Add(this.numericUpDownWeight);
this.groupBoxCruiser.Controls.Add(this.numericUpDownSpeed);
this.groupBoxCruiser.Controls.Add(this.labelWeight);
this.groupBoxCruiser.Controls.Add(this.labelSpeed);
this.groupBoxCruiser.Location = new System.Drawing.Point(57, 43);
this.groupBoxCruiser.Name = "groupBoxCruiser";
this.groupBoxCruiser.Size = new System.Drawing.Size(1163, 391);
this.groupBoxCruiser.TabIndex = 0;
this.groupBoxCruiser.TabStop = false;
this.groupBoxCruiser.Text = "Параметры";
//
// checkBoxMissileSilos
//
this.checkBoxMissileSilos.AutoSize = true;
this.checkBoxMissileSilos.Location = new System.Drawing.Point(33, 277);
this.checkBoxMissileSilos.Name = "checkBoxMissileSilos";
this.checkBoxMissileSilos.Size = new System.Drawing.Size(232, 29);
this.checkBoxMissileSilos.TabIndex = 12;
this.checkBoxMissileSilos.Text = "Наличие ракетных шахт";
this.checkBoxMissileSilos.UseVisualStyleBackColor = true;
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(991, 321);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(127, 38);
this.buttonCancel.TabIndex = 11;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(838, 321);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(136, 38);
this.buttonAdd.TabIndex = 10;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// panelOrchid
//
this.panelOrchid.AllowDrop = true;
this.panelOrchid.Controls.Add(this.label_addit_color);
this.panelOrchid.Controls.Add(this.label_color);
this.panelOrchid.Controls.Add(this.pictureBoxCruiser);
this.panelOrchid.Location = new System.Drawing.Point(822, 45);
this.panelOrchid.Name = "panelOrchid";
this.panelOrchid.Size = new System.Drawing.Size(312, 261);
this.panelOrchid.TabIndex = 9;
this.panelOrchid.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelOrchid.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// label_addit_color
//
this.label_addit_color.AllowDrop = true;
this.label_addit_color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_addit_color.Location = new System.Drawing.Point(169, 23);
this.label_addit_color.Name = "label_addit_color";
this.label_addit_color.Size = new System.Drawing.Size(117, 38);
this.label_addit_color.TabIndex = 10;
this.label_addit_color.Text = "Доп.цвет";
this.label_addit_color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_addit_color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
this.label_addit_color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
//
// label_color
//
this.label_color.AllowDrop = true;
this.label_color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_color.Location = new System.Drawing.Point(30, 23);
this.label_color.Name = "label_color";
this.label_color.Size = new System.Drawing.Size(110, 38);
this.label_color.TabIndex = 9;
this.label_color.Text = "Цвет";
this.label_color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
this.label_color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
//
// pictureBoxCruiser
//
this.pictureBoxCruiser.Location = new System.Drawing.Point(76, 64);
this.pictureBoxCruiser.Name = "pictureBoxCruiser";
this.pictureBoxCruiser.Size = new System.Drawing.Size(163, 178);
this.pictureBoxCruiser.TabIndex = 8;
this.pictureBoxCruiser.TabStop = false;
//
// labelAdvanced
//
this.labelAdvanced.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAdvanced.Location = new System.Drawing.Point(521, 293);
this.labelAdvanced.Name = "labelAdvanced";
this.labelAdvanced.Size = new System.Drawing.Size(141, 47);
this.labelAdvanced.TabIndex = 7;
this.labelAdvanced.Text = "Продвинутый";
this.labelAdvanced.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelAdvanced.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelBasic
//
this.labelBasic.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelBasic.Location = new System.Drawing.Point(369, 293);
this.labelBasic.Name = "labelBasic";
this.labelBasic.Size = new System.Drawing.Size(131, 47);
this.labelBasic.TabIndex = 6;
this.labelBasic.Text = "Простой";
this.labelBasic.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBasic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBoxColor
//
this.groupBoxColor.Controls.Add(this.panelColor);
this.groupBoxColor.Controls.Add(this.panelPink);
this.groupBoxColor.Controls.Add(this.panelViolet);
this.groupBoxColor.Controls.Add(this.panelBlue);
this.groupBoxColor.Controls.Add(this.panelLightBlue);
this.groupBoxColor.Controls.Add(this.panelPurple);
this.groupBoxColor.Controls.Add(this.panelBlack);
this.groupBoxColor.Controls.Add(this.panelWhite);
this.groupBoxColor.Location = new System.Drawing.Point(335, 40);
this.groupBoxColor.Name = "groupBoxColor";
this.groupBoxColor.Size = new System.Drawing.Size(357, 231);
this.groupBoxColor.TabIndex = 5;
this.groupBoxColor.TabStop = false;
this.groupBoxColor.Text = "Цвета";
//
// panelColor
//
this.panelColor.BackColor = System.Drawing.Color.Fuchsia;
this.panelColor.Location = new System.Drawing.Point(264, 153);
this.panelColor.Name = "panelColor";
this.panelColor.Size = new System.Drawing.Size(53, 49);
this.panelColor.TabIndex = 7;
//
// panelPink
//
this.panelPink.BackColor = System.Drawing.Color.Violet;
this.panelPink.Location = new System.Drawing.Point(180, 153);
this.panelPink.Name = "panelPink";
this.panelPink.Size = new System.Drawing.Size(53, 49);
this.panelPink.TabIndex = 6;
//
// panelViolet
//
this.panelViolet.BackColor = System.Drawing.Color.DarkTurquoise;
this.panelViolet.Location = new System.Drawing.Point(108, 153);
this.panelViolet.Name = "panelViolet";
this.panelViolet.Size = new System.Drawing.Size(53, 49);
this.panelViolet.TabIndex = 5;
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.PaleTurquoise;
this.panelBlue.Location = new System.Drawing.Point(34, 153);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(53, 49);
this.panelBlue.TabIndex = 4;
//
// panelLightBlue
//
this.panelLightBlue.BackColor = System.Drawing.Color.Purple;
this.panelLightBlue.Location = new System.Drawing.Point(264, 44);
this.panelLightBlue.Name = "panelLightBlue";
this.panelLightBlue.Size = new System.Drawing.Size(53, 49);
this.panelLightBlue.TabIndex = 3;
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.DarkOrchid;
this.panelPurple.Location = new System.Drawing.Point(186, 44);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(53, 49);
this.panelPurple.TabIndex = 2;
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.panelBlack.Location = new System.Drawing.Point(108, 44);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(53, 49);
this.panelBlack.TabIndex = 1;
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.SystemColors.ButtonHighlight;
this.panelWhite.Location = new System.Drawing.Point(32, 44);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(55, 49);
this.panelWhite.TabIndex = 0;
//
// checkBoxHelicopterPad
//
this.checkBoxHelicopterPad.AutoSize = true;
this.checkBoxHelicopterPad.Location = new System.Drawing.Point(33, 213);
this.checkBoxHelicopterPad.Name = "checkBoxHelicopterPad";
this.checkBoxHelicopterPad.Size = new System.Drawing.Size(310, 29);
this.checkBoxHelicopterPad.TabIndex = 4;
this.checkBoxHelicopterPad.Text = "Наличие площадки под вертолет";
this.checkBoxHelicopterPad.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(128, 143);
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(84, 31);
this.numericUpDownWeight.TabIndex = 3;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(128, 75);
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(74, 31);
this.numericUpDownSpeed.TabIndex = 2;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(33, 145);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(43, 25);
this.labelWeight.TabIndex = 1;
this.labelWeight.Text = "Вес:";
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(33, 75);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(93, 25);
this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = "Скорость:";
//
// FormCruiserConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1279, 552);
this.Controls.Add(this.groupBoxCruiser);
this.Name = "FormCruiserConfig";
this.Text = "Создание объекта";
this.groupBoxCruiser.ResumeLayout(false);
this.groupBoxCruiser.PerformLayout();
this.panelOrchid.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
this.groupBoxColor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxCruiser;
private Button buttonCancel;
private Button buttonAdd;
private Panel panelOrchid;
private Label label_addit_color;
private Label label_color;
private PictureBox pictureBoxCruiser;
private Label labelAdvanced;
private Label labelBasic;
private GroupBox groupBoxColor;
private Panel panelBlack;
private Panel panelWhite;
private CheckBox checkBoxHelicopterPad;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelWeight;
private Label labelSpeed;
private CheckBox checkBoxMissileSilos;
private Panel panelColor;
private Panel panelPink;
private Panel panelViolet;
private Panel panelBlue;
private Panel panelLightBlue;
private Panel panelPurple;
}
}

View File

@@ -1,126 +0,0 @@
using Cruiser.DrawningObjects;
using Cruiser.Entities;
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.VisualStyles.VisualStyleElement.Button;
namespace Cruiser
{
public partial class FormCruiserConfig : Form
{
DrawningCruiser? _cruiser = null;
public event Action<DrawningCruiser>? EventAddCruiser;
public FormCruiserConfig()
{
InitializeComponent();
panelWhite.MouseDown += PanelColor_MouseDown;
panelBlack.MouseDown += PanelColor_MouseDown;
panelLightBlue.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
panelPink.MouseDown += PanelColor_MouseDown;
panelViolet.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelOrchid.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
private void DrawCruiser()
{
Bitmap bmp = new(pictureBoxCruiser.Width, pictureBoxCruiser.Height);
Graphics gr = Graphics.FromImage(bmp);
_cruiser?.SetPosition(5, 5);
_cruiser?.DrawTransport(gr);
pictureBoxCruiser.Image = bmp;
}
public void AddEvent(Action<DrawningCruiser> ev)
{
if (EventAddCruiser == null)
{
EventAddCruiser = ev;
}
else
{
EventAddCruiser += ev;
}
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelBasic":
_cruiser = new DrawningCruiser((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
Color.White, pictureBoxCruiser.Width, pictureBoxCruiser.Height);
break;
case "labelAdvanced":
_cruiser = new DrawningAdvancedCruiser((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
Color.White, Color.Black, checkBoxHelicopterPad.Checked, checkBoxMissileSilos.Checked,
pictureBoxCruiser.Width, pictureBoxCruiser.Height);
break;
}
label_color.BackColor = Color.Empty;
label_addit_color.BackColor = Color.Empty;
DrawCruiser();
}
private void PanelColor_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Control)?.DoDragDrop((sender as Control)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
EventAddCruiser?.Invoke(_cruiser);
Close();
}
private void labelColor_DragDrop(object sender, DragEventArgs e)
{
if (_cruiser?.EntityCruiser == null)
return;
switch (((Label)sender).Name)
{
case "label_color":
_cruiser?.EntityCruiser?.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "label_addit_color":
if (!(_cruiser is DrawningAdvancedCruiser))
return;
(_cruiser.EntityCruiser as EntityAdvancedCruiser)?.setAdditionalColor(color: (Color)e.Data.GetData(typeof(Color)));
break;
}
DrawCruiser();
}
private void labelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
}

View File

@@ -1,17 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.MovementStrategy;
using Cruiser;
using Monorail.DrawningObjects;
namespace Cruiser.MovementStrategy
namespace Monorail.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(Direction direction);
void MoveObject(Direction direction);
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}
}

View File

@@ -1,12 +1,14 @@
using System;

using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.MovementStrategy
namespace Monorail.MovementStrategy
{
internal class MoveToBorder : AbstractStrategy
public class MoveToEdge : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
@@ -15,11 +17,10 @@ namespace Cruiser.MovementStrategy
{
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight;
return objParams.RightBorder < FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder < FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
@@ -30,11 +31,7 @@ namespace Cruiser.MovementStrategy
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
if (diffX < 0)
{
MoveRight();
}
@@ -42,14 +39,9 @@ namespace Cruiser.MovementStrategy
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
if (diffY < 0)
{
MoveDown();
}
}
}

View File

@@ -1,12 +1,13 @@
using System;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.MovementStrategy
namespace Monorail.MovementStrategy
{
internal class MoveToCenter : AbstractStrategy
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
@@ -15,12 +16,12 @@ namespace Cruiser.MovementStrategy
{
return false;
}
return (objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2);
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
@@ -53,5 +54,6 @@ namespace Cruiser.MovementStrategy
}
}
}
}
}

View File

@@ -1,23 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.MovementStrategy
namespace Monorail.MovementStrategy
{
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int TopBorder => _y;
public int RightBorder => _x + _width;
public int DownBorder => _y + _height;
public int ObjectMiddleHorizontal => _x + _width / 2;
public int ObjectMiddleVertical => _y + _height / 2;
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
@@ -25,5 +27,6 @@ namespace Cruiser.MovementStrategy
_width = width;
_height = height;
}
}
}

29
Cruiser/Cruiser/Pro.cs Normal file
View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Monorail.Entities
{
public class EntityAirBomber : EntityPlane
{
public Color AdditionalColor { get; private set; }
public bool Bombs { get; private set; }
public bool Fuel { get; private set; }
public EntityAirBomber(int speed, double weight, Color bodyColor, Color
additionalColor, bool bombs, bool fuel)
: base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Bombs = bombs;
Fuel = fuel;
}
public void setAdditionalColor(Color color)
{
AdditionalColor = color;
}
}
}

View File

@@ -1,5 +1,6 @@
namespace Cruiser
{
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
internal static class Program
{
/// <summary>

View File

@@ -4,78 +4,69 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.Generics
namespace Monorail.Generics
{
internal class SetGeneric<T>
where T : class
{
private readonly List<T?> _places;
public int Count => _places.Count;
private readonly int _maxCount;
public SetGeneric(int count)
{
_maxCount = count;
_places = new List<T?>(count);
}
public bool Insert(T cruiser)
public bool Insert(T plane)
{
if (_places.Count == _maxCount)
{
return false;
}
Insert(cruiser, 0);
Insert(plane, 0);
return true;
}
public bool Insert(T cruiser, int position)
public bool Insert(T plane, int position)
{
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
{
return false;
}
_places.Insert(position, cruiser);
_places.Insert(position, plane);
return true;
}
public bool Remove(int position)
{
if (position < 0 || position >= Count)
{
if (!(position >= 0 && position < Count))
return false;
}
_places.RemoveAt(position);
return true;
}
public T? this[int position]
{
get
{
if (position < 0 || position >= _maxCount)
{
if (!(position >= 0 && position <= Count))
return null;
}
return _places[position];
}
set
{
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
{
if (!(position >= 0 && position <= Count))
return;
}
_places.Insert(position, value);
return;
}
}
public IEnumerable<T?> GetCruiser(int? maxCruisers = null)
public IEnumerable<T?> GetPlanes(int? maxPlanes = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxCruisers.HasValue && i == maxCruisers.Value)
{
if (maxPlanes.HasValue && i == maxPlanes.Value)
yield break;
}
}
}
}
}

View File

@@ -4,12 +4,12 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.MovementStrategy
namespace Monorail
{
public enum Status
{
NotInit,
InProgress,
Finish
NotInit = 1,
InProgress = 2,
Finish = 3
}
}