Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a53b2840c | ||
|
|
ed2a685f66 | ||
|
|
6806a3c9ca | ||
|
|
19b93bd2ee | ||
|
|
f7f15d31fb | ||
|
|
34bacd6d35 |
BIN
WinFormsApp1.rar1
Normal file
BIN
WinFormsApp1.rar1
Normal file
Binary file not shown.
158
WinFormsApp1/AbstractMap.cs
Normal file
158
WinFormsApp1/AbstractMap.cs
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
internal abstract class AbstractMap
|
||||||
|
{
|
||||||
|
private IDrawningObject _drawningObject = null;
|
||||||
|
protected int[,] _map = null;
|
||||||
|
protected int _width;
|
||||||
|
protected int _height;
|
||||||
|
protected float _size_x;
|
||||||
|
protected float _size_y;
|
||||||
|
protected readonly Random _random = new();
|
||||||
|
protected readonly int _freeRoad = 0;
|
||||||
|
protected readonly int _barrier = 1;
|
||||||
|
|
||||||
|
public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawningObject = drawningObject;
|
||||||
|
GenerateMap();
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CheckAround(float Left, float Right, float Top, float Bottom)
|
||||||
|
{
|
||||||
|
int startX = (int)(Left / _size_x);
|
||||||
|
int startY = (int)(Right / _size_y);
|
||||||
|
int endX = (int)(Top / _size_x);
|
||||||
|
if (endX > 100)
|
||||||
|
{
|
||||||
|
endX = 100;
|
||||||
|
}
|
||||||
|
int endY = (int)(Bottom / _size_y);
|
||||||
|
if (endY > 100)
|
||||||
|
{
|
||||||
|
endY = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = startX; i < endX; i++)
|
||||||
|
{
|
||||||
|
for (int j = startY; j < endY; j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_drawningObject.MoveObject(direction);
|
||||||
|
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
|
||||||
|
|
||||||
|
if (CheckAround(Left, Right, Top, Bottom))
|
||||||
|
{
|
||||||
|
_drawningObject.MoveObject(MoveObjectBack(direction));
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Direction MoveObjectBack(Direction direction)
|
||||||
|
{
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Direction.Up:
|
||||||
|
return Direction.Down;
|
||||||
|
case Direction.Down:
|
||||||
|
return Direction.Up;
|
||||||
|
case Direction.Left:
|
||||||
|
return Direction.Right;
|
||||||
|
case Direction.Right:
|
||||||
|
return Direction.Left;
|
||||||
|
}
|
||||||
|
return Direction.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool SetObjectOnMap()
|
||||||
|
{
|
||||||
|
if (_drawningObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int x = _random.Next(0, 10);
|
||||||
|
int y = _random.Next(0, 10);
|
||||||
|
_drawningObject.SetObject(x, y, _width, _height);
|
||||||
|
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
|
||||||
|
if (!CheckAround(Left, Right, Top, Bottom)) return true;
|
||||||
|
float startX = Left;
|
||||||
|
float startY = Right;
|
||||||
|
float lengthX = Top - Left;
|
||||||
|
float lengthY = Bottom - Right;
|
||||||
|
while (CheckAround(startX, startY, startX + lengthX, startY + lengthY))
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
result = CheckAround(startX, startY, startX + lengthX, startY + lengthY);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
_drawningObject.SetObject((int)startX, (int)startY, _width, _height);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startX += _size_x;
|
||||||
|
}
|
||||||
|
} while (result);
|
||||||
|
startX = x;
|
||||||
|
startY += _size_y;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Bitmap DrawMapWithObject()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_width, _height);
|
||||||
|
if (_drawningObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _freeRoad)
|
||||||
|
{
|
||||||
|
DrawRoadPart(gr, i, j);
|
||||||
|
}
|
||||||
|
else if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
DrawBarrierPart(gr, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_drawningObject.DrawningObject(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void GenerateMap();
|
||||||
|
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||||
|
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,9 @@ using System.Text;
|
|||||||
|
|
||||||
namespace WinFormsApp1
|
namespace WinFormsApp1
|
||||||
{
|
{
|
||||||
internal enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
|
None = 0,
|
||||||
Up = 1,
|
Up = 1,
|
||||||
Down = 2,
|
Down = 2,
|
||||||
Left = 3,
|
Left = 3,
|
||||||
|
|||||||
41
WinFormsApp1/DrawningObjectTraktor.cs
Normal file
41
WinFormsApp1/DrawningObjectTraktor.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
class DrawningObjectTractor : IDrawningObject
|
||||||
|
{
|
||||||
|
private TractorDraw _tractor = null;
|
||||||
|
|
||||||
|
public DrawningObjectTractor(TractorDraw tractor)
|
||||||
|
{
|
||||||
|
_tractor = tractor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Step => _tractor?.Tractor?.Step ?? 0;
|
||||||
|
|
||||||
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return _tractor?.GetCurrentPosition() ?? default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_tractor?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetObject(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_tractor.SetPosition(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDrawningObject.DrawningObject(Graphics g)
|
||||||
|
{
|
||||||
|
_tractor.DrawEntity(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ using System.Drawing;
|
|||||||
|
|
||||||
namespace WinFormsApp1
|
namespace WinFormsApp1
|
||||||
{
|
{
|
||||||
class EntityTractor
|
public class EntityTractor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Скорость
|
/// Скорость
|
||||||
@@ -26,13 +26,8 @@ namespace WinFormsApp1
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public float Step => Speed * 100 / Weight;
|
public float Step => Speed * 100 / Weight;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация полей объекта-класса автомобиля
|
|
||||||
/// </summary>
|
public EntityTractor(int speed, float weight, Color bodyColor)
|
||||||
/// <param name="speed"></param>
|
|
||||||
/// <param name="weight"></param>
|
|
||||||
/// <param name="bodyColor"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||||
|
|||||||
52
WinFormsApp1/FieldMap.cs
Normal file
52
WinFormsApp1/FieldMap.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
class FieldMap : AbstractMap
|
||||||
|
{
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Yellow);
|
||||||
|
/// Цвет участка открытого
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Green);
|
||||||
|
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 25)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 97);
|
||||||
|
int y = _random.Next(0, 97);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
_map[x + 2, y] = _barrier;
|
||||||
|
_map[x, y + 2] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
294
WinFormsApp1/FormMapWithSetTraktor.Designer.cs
generated
Normal file
294
WinFormsApp1/FormMapWithSetTraktor.Designer.cs
generated
Normal file
@@ -0,0 +1,294 @@
|
|||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
partial class FormMapWithSetTraktor
|
||||||
|
{
|
||||||
|
/// <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.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
||||||
|
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||||
|
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
|
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||||
|
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||||
|
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.buttonRemoveTraktor = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAddTraktor = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
|
this.groupBoxMaps.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.groupBoxMaps);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonRight);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonDown);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonLeft);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonUp);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonShowOnMap);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonShowStorage);
|
||||||
|
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonRemoveTraktor);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonAddTraktor);
|
||||||
|
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
|
this.groupBox1.Location = new System.Drawing.Point(596, 0);
|
||||||
|
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.groupBox1.Name = "groupBox1";
|
||||||
|
this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.groupBox1.Size = new System.Drawing.Size(219, 476);
|
||||||
|
this.groupBox1.TabIndex = 0;
|
||||||
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// groupBoxMaps
|
||||||
|
//
|
||||||
|
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
|
||||||
|
this.groupBoxMaps.Location = new System.Drawing.Point(7, 20);
|
||||||
|
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||||
|
this.groupBoxMaps.Size = new System.Drawing.Size(200, 244);
|
||||||
|
this.groupBoxMaps.TabIndex = 2;
|
||||||
|
this.groupBoxMaps.TabStop = false;
|
||||||
|
this.groupBoxMaps.Text = "Карты";
|
||||||
|
//
|
||||||
|
// listBoxMaps
|
||||||
|
//
|
||||||
|
this.listBoxMaps.FormattingEnabled = true;
|
||||||
|
this.listBoxMaps.ItemHeight = 15;
|
||||||
|
this.listBoxMaps.Location = new System.Drawing.Point(6, 109);
|
||||||
|
this.listBoxMaps.Name = "listBoxMaps";
|
||||||
|
this.listBoxMaps.Size = new System.Drawing.Size(188, 94);
|
||||||
|
this.listBoxMaps.TabIndex = 4;
|
||||||
|
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// buttonDeleteMap
|
||||||
|
//
|
||||||
|
this.buttonDeleteMap.Location = new System.Drawing.Point(6, 215);
|
||||||
|
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||||
|
this.buttonDeleteMap.Size = new System.Drawing.Size(188, 23);
|
||||||
|
this.buttonDeleteMap.TabIndex = 3;
|
||||||
|
this.buttonDeleteMap.Text = "Удалить карту";
|
||||||
|
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
|
||||||
|
//
|
||||||
|
// buttonAddMap
|
||||||
|
//
|
||||||
|
this.buttonAddMap.Location = new System.Drawing.Point(6, 80);
|
||||||
|
this.buttonAddMap.Name = "buttonAddMap";
|
||||||
|
this.buttonAddMap.Size = new System.Drawing.Size(188, 23);
|
||||||
|
this.buttonAddMap.TabIndex = 2;
|
||||||
|
this.buttonAddMap.Text = " Добавить карту";
|
||||||
|
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
|
||||||
|
//
|
||||||
|
// textBoxNewMapName
|
||||||
|
//
|
||||||
|
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 22);
|
||||||
|
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||||
|
this.textBoxNewMapName.Size = new System.Drawing.Size(188, 23);
|
||||||
|
this.textBoxNewMapName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// comboBoxSelectorMap
|
||||||
|
//
|
||||||
|
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
|
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||||
|
"Простая карта",
|
||||||
|
"Поле"});
|
||||||
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 52);
|
||||||
|
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23);
|
||||||
|
this.comboBoxSelectorMap.TabIndex = 0;
|
||||||
|
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonRight.BackgroundImage = global::Tractors.Properties.Resources.RkYIe2_6DuQ;
|
||||||
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonRight.Location = new System.Drawing.Point(126, 435);
|
||||||
|
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonRight.Name = "buttonRight";
|
||||||
|
this.buttonRight.Size = new System.Drawing.Size(35, 30);
|
||||||
|
this.buttonRight.TabIndex = 10;
|
||||||
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonDown.BackgroundImage = global::Tractors.Properties.Resources.MbV2DYU_nPM;
|
||||||
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonDown.Location = new System.Drawing.Point(91, 435);
|
||||||
|
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonDown.Name = "buttonDown";
|
||||||
|
this.buttonDown.Size = new System.Drawing.Size(35, 30);
|
||||||
|
this.buttonDown.TabIndex = 9;
|
||||||
|
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::Tractors.Properties.Resources.Hhxt4dLqV5g;
|
||||||
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonLeft.Location = new System.Drawing.Point(56, 435);
|
||||||
|
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
|
this.buttonLeft.Size = new System.Drawing.Size(35, 30);
|
||||||
|
this.buttonLeft.TabIndex = 8;
|
||||||
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonUp.BackgroundImage = global::Tractors.Properties.Resources._2EdzyM4iEKw;
|
||||||
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonUp.Location = new System.Drawing.Point(91, 405);
|
||||||
|
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonUp.Name = "buttonUp";
|
||||||
|
this.buttonUp.Size = new System.Drawing.Size(35, 30);
|
||||||
|
this.buttonUp.TabIndex = 7;
|
||||||
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonShowOnMap
|
||||||
|
//
|
||||||
|
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 380);
|
||||||
|
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
|
this.buttonShowOnMap.Size = new System.Drawing.Size(207, 22);
|
||||||
|
this.buttonShowOnMap.TabIndex = 5;
|
||||||
|
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||||
|
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||||
|
//
|
||||||
|
// buttonShowStorage
|
||||||
|
//
|
||||||
|
this.buttonShowStorage.Location = new System.Drawing.Point(7, 353);
|
||||||
|
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
|
this.buttonShowStorage.Size = new System.Drawing.Size(207, 22);
|
||||||
|
this.buttonShowStorage.TabIndex = 4;
|
||||||
|
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||||
|
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 298);
|
||||||
|
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
this.maskedTextBoxPosition.Size = new System.Drawing.Size(207, 23);
|
||||||
|
this.maskedTextBoxPosition.TabIndex = 11;
|
||||||
|
//
|
||||||
|
// buttonRemoveTraktor
|
||||||
|
//
|
||||||
|
this.buttonRemoveTraktor.Location = new System.Drawing.Point(7, 325);
|
||||||
|
this.buttonRemoveTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonRemoveTraktor.Name = "buttonRemoveTraktor";
|
||||||
|
this.buttonRemoveTraktor.Size = new System.Drawing.Size(207, 24);
|
||||||
|
this.buttonRemoveTraktor.TabIndex = 2;
|
||||||
|
this.buttonRemoveTraktor.Text = "Удалить трактор";
|
||||||
|
this.buttonRemoveTraktor.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRemoveTraktor.Click += new System.EventHandler(this.ButtonRemoveTraktor_Click);
|
||||||
|
//
|
||||||
|
// buttonAddTraktor
|
||||||
|
//
|
||||||
|
this.buttonAddTraktor.Location = new System.Drawing.Point(7, 269);
|
||||||
|
this.buttonAddTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonAddTraktor.Name = "buttonAddTraktor";
|
||||||
|
this.buttonAddTraktor.Size = new System.Drawing.Size(207, 25);
|
||||||
|
this.buttonAddTraktor.TabIndex = 1;
|
||||||
|
this.buttonAddTraktor.Text = "Добавить трактор";
|
||||||
|
this.buttonAddTraktor.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddTraktor.Click += new System.EventHandler(this.ButtonAddTraktor_Click);
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.pictureBox.Name = "pictureBox";
|
||||||
|
this.pictureBox.Size = new System.Drawing.Size(596, 476);
|
||||||
|
this.pictureBox.TabIndex = 1;
|
||||||
|
this.pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormMapWithSetTraktor
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(815, 476);
|
||||||
|
this.Controls.Add(this.pictureBox);
|
||||||
|
this.Controls.Add(this.groupBox1);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.Name = "FormMapWithSetTraktor";
|
||||||
|
this.Text = "Автобус";
|
||||||
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
this.groupBox1.PerformLayout();
|
||||||
|
this.groupBoxMaps.ResumeLayout(false);
|
||||||
|
this.groupBoxMaps.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button buttonShowOnMap;
|
||||||
|
private Button buttonShowStorage;
|
||||||
|
private MaskedTextBox maskedTextBoxPosition;
|
||||||
|
private Button buttonRemoveTraktor;
|
||||||
|
private Button buttonAddTraktor;
|
||||||
|
private ComboBox comboBoxSelectorMap;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonUp;
|
||||||
|
private GroupBox groupBoxMaps;
|
||||||
|
private Button buttonDeleteMap;
|
||||||
|
private Button buttonAddMap;
|
||||||
|
private TextBox textBoxNewMapName;
|
||||||
|
private ListBox listBoxMaps;
|
||||||
|
}
|
||||||
|
}
|
||||||
222
WinFormsApp1/FormMapWithSetTraktor.cs
Normal file
222
WinFormsApp1/FormMapWithSetTraktor.cs
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
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 WinFormsApp1;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
public partial class FormMapWithSetTraktor : Form
|
||||||
|
{
|
||||||
|
private MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> _mapTraktorCollectionGeneric;
|
||||||
|
|
||||||
|
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||||
|
{
|
||||||
|
{"Простая карта", new SimpleMap() },
|
||||||
|
{"Поле", new FieldMap() }
|
||||||
|
};
|
||||||
|
|
||||||
|
private readonly MapsCollection _mapsCollection;
|
||||||
|
|
||||||
|
public FormMapWithSetTraktor()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||||
|
comboBoxSelectorMap.Items.Clear();
|
||||||
|
foreach (var item in _mapsDict)
|
||||||
|
{
|
||||||
|
comboBoxSelectorMap.Items.Add(item.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReloadMaps()
|
||||||
|
{
|
||||||
|
int index = listBoxMaps.SelectedIndex;
|
||||||
|
|
||||||
|
listBoxMaps.Items.Clear();
|
||||||
|
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
AbstractMap map = null;
|
||||||
|
switch (comboBoxSelectorMap.Text)
|
||||||
|
{
|
||||||
|
case "Простая карта":
|
||||||
|
map = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "Поле":
|
||||||
|
map = new FieldMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map != null)
|
||||||
|
{
|
||||||
|
_mapTraktorCollectionGeneric = new MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_mapTraktorCollectionGeneric = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAddTraktor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormTractor form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (form.SelectedTractor == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Сначала создайте объект");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawningObjectTractor bus = new(form.SelectedTractor);
|
||||||
|
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + bus != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRemoveTraktor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapTraktorCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapTraktorCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapTraktorCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
Direction dir = Direction.None;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
dir = Direction.Up;
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
dir = Direction.Down;
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
dir = Direction.Left;
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
dir = Direction.Right;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapTraktorCollectionGeneric.MoveObject(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonAddMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonDeleteMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
120
WinFormsApp1/FormMapWithSetTraktor.resx
Normal file
120
WinFormsApp1/FormMapWithSetTraktor.resx
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
||||||
26
WinFormsApp1/FormTractor.Designer.cs
generated
26
WinFormsApp1/FormTractor.Designer.cs
generated
@@ -39,6 +39,8 @@ namespace WinFormsApp1
|
|||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSelectedTractor = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@@ -145,11 +147,33 @@ namespace WinFormsApp1
|
|||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
|
// buttonCreateModif
|
||||||
|
//
|
||||||
|
this.buttonCreateModif.Location = new System.Drawing.Point(111, 378);
|
||||||
|
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||||
|
this.buttonCreateModif.Size = new System.Drawing.Size(129, 27);
|
||||||
|
this.buttonCreateModif.TabIndex = 7;
|
||||||
|
this.buttonCreateModif.Text = "Модификация";
|
||||||
|
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||||
|
//
|
||||||
|
// buttonSelectedTractor
|
||||||
|
//
|
||||||
|
this.buttonSelectedTractor.Location = new System.Drawing.Point(262, 372);
|
||||||
|
this.buttonSelectedTractor.Name = "buttonSelectedTractor";
|
||||||
|
this.buttonSelectedTractor.Size = new System.Drawing.Size(89, 35);
|
||||||
|
this.buttonSelectedTractor.TabIndex = 8;
|
||||||
|
this.buttonSelectedTractor.Text = "Выбрать";
|
||||||
|
this.buttonSelectedTractor.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSelectedTractor.Click += new System.EventHandler(this.buttonSelectedTractor_Click);
|
||||||
|
//
|
||||||
// FormTractor
|
// FormTractor
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonSelectedTractor);
|
||||||
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
@@ -179,6 +203,8 @@ namespace WinFormsApp1
|
|||||||
private System.Windows.Forms.Button buttonLeft;
|
private System.Windows.Forms.Button buttonLeft;
|
||||||
private System.Windows.Forms.Button buttonDown;
|
private System.Windows.Forms.Button buttonDown;
|
||||||
private System.Windows.Forms.Button buttonRight;
|
private System.Windows.Forms.Button buttonRight;
|
||||||
|
private System.Windows.Forms.Button buttonCreateModif;
|
||||||
|
private System.Windows.Forms.Button buttonSelectedTractor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace WinFormsApp1
|
|||||||
{
|
{
|
||||||
private TractorDraw _Tractor;
|
private TractorDraw _Tractor;
|
||||||
|
|
||||||
|
public TractorDraw SelectedTractor { get; private set; }
|
||||||
public FormTractor()
|
public FormTractor()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -27,16 +28,25 @@ namespace WinFormsApp1
|
|||||||
pictureBoxTractor.Image = bmp;
|
pictureBoxTractor.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetData()
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
_Tractor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTractor.Width, pictureBoxTractor.Height);
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Скорость: {_Tractor.Tractor.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Вес: {_Tractor.Tractor.Weight}";
|
||||||
|
toolStripStatusLabelBodyColor.Text = $"Цвет кузова: {_Tractor.Tractor.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
_Tractor = new TractorDraw();
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
_Tractor.Init(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
ColorDialog dialog = new();
|
||||||
_Tractor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTractor.Width, pictureBoxTractor.Height);
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_Tractor.Tractor.Speed}";
|
{
|
||||||
toolStripStatusLabelWeight.Text = $"Вес: {_Tractor.Tractor.Weight}";
|
color = dialog.Color;
|
||||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_Tractor.Tractor.BodyColor.Name}";
|
}
|
||||||
|
_Tractor = new TractorDraw(random.Next(100, 300), random.Next(1000, 2000), color); SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,5 +81,38 @@ namespace WinFormsApp1
|
|||||||
_Tractor?.ChangeBorders(pictureBoxTractor.Width, pictureBoxTractor.Height);
|
_Tractor?.ChangeBorders(pictureBoxTractor.Width, pictureBoxTractor.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialogDop = new();
|
||||||
|
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogDop.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
_Tractor = new MultiTraktorDraw(random.Next(100, 300), random.Next(1000, 2000), color, dopColor);
|
||||||
|
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSelectedTractor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedTractor = _Tractor;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
WinFormsApp1/IDrawningObject.cs
Normal file
29
WinFormsApp1/IDrawningObject.cs
Normal 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 WinFormsApp1
|
||||||
|
{
|
||||||
|
interface IDrawningObject
|
||||||
|
{
|
||||||
|
/// Шаг перемещения объекта
|
||||||
|
public float Step { get; }
|
||||||
|
/// Установка позиции объекта
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
/// <param name="width">Ширина полотна</param>
|
||||||
|
/// <param name="height">Высота полотна</param>
|
||||||
|
void SetObject(int x, int y, int width, int height);
|
||||||
|
/// Изменение направления пермещения объекта
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
/// Отрисовка объекта
|
||||||
|
/// <param name="g"></param>
|
||||||
|
void DrawningObject(Graphics g);
|
||||||
|
/// Получение текущей позиции объекта
|
||||||
|
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
140
WinFormsApp1/MapWithSetTraktorGeneric.cs
Normal file
140
WinFormsApp1/MapWithSetTraktorGeneric.cs
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
internal class MapWithSetTraktorGeneric<T, U>
|
||||||
|
where T : class, IDrawningObject
|
||||||
|
where U : AbstractMap
|
||||||
|
{
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
private readonly int _placeSizeWidth = 250;
|
||||||
|
private readonly int _placeSizeHeight = 250;
|
||||||
|
private readonly SetTraktorGeneric<T> _setTraktors;
|
||||||
|
private readonly U _map;
|
||||||
|
|
||||||
|
public MapWithSetTraktorGeneric(int picWidth, int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setTraktors = new SetTraktorGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int operator +(MapWithSetTraktorGeneric<T, U> map, T bus)
|
||||||
|
{
|
||||||
|
return map._setTraktors.Insert(bus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T operator -(MapWithSetTraktorGeneric<T, U> map, int position)
|
||||||
|
{
|
||||||
|
return map._setTraktors.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap ShowSet()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawTraktors(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
foreach (var traktor in _setTraktors.GetTraktor())
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, traktor);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
return _map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setTraktors.Count - 1;
|
||||||
|
for (int i = 0; i < _setTraktors.Count; i++)
|
||||||
|
{
|
||||||
|
if (_setTraktors[i] == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var bus = _setTraktors[j];
|
||||||
|
if (bus != null)
|
||||||
|
{
|
||||||
|
_setTraktors.Insert(bus, i);
|
||||||
|
_setTraktors.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
Brush brush = new SolidBrush(Color.LightSlateGray);
|
||||||
|
g.FillRectangle(brush, 0, 0, _pictureWidth, _pictureHeight);
|
||||||
|
for (int i = 0; i <= _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j <= _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight);
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight + 10, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + 10);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawTraktors(Graphics g)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int currentWidth = _pictureWidth / _placeSizeWidth - 1;
|
||||||
|
int currentHeight = _pictureHeight / _placeSizeHeight - 1;
|
||||||
|
|
||||||
|
foreach (var traktor in _setTraktors.GetTraktor())
|
||||||
|
{
|
||||||
|
traktor?.SetObject(
|
||||||
|
currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||||
|
traktor?.DrawningObject(g);
|
||||||
|
|
||||||
|
if (currentWidth > 0)
|
||||||
|
{
|
||||||
|
currentWidth -= 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (currentHeight > 0)
|
||||||
|
{
|
||||||
|
currentHeight -= 1;
|
||||||
|
currentWidth = _pictureWidth / _placeSizeWidth - 1;
|
||||||
|
}
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
53
WinFormsApp1/MapsCollection.cs
Normal file
53
WinFormsApp1/MapsCollection.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
internal class MapsCollection
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>> _mapStorages;
|
||||||
|
|
||||||
|
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||||
|
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_mapStorages = new Dictionary<string, MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddMap(string name, AbstractMap map)
|
||||||
|
{
|
||||||
|
if (_mapStorages.ContainsKey(name)) return; //уникальное имя
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_mapStorages.Add(name, new MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelMap(string name)
|
||||||
|
{
|
||||||
|
if (_mapStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_mapStorages.Remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
_mapStorages.TryGetValue(ind, out var MapWithSetDoubleDeckerBusGeneric);
|
||||||
|
return MapWithSetDoubleDeckerBusGeneric;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
WinFormsApp1/MultiTraktor.cs
Normal file
21
WinFormsApp1/MultiTraktor.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
internal class MultiTraktor : EntityTractor
|
||||||
|
{
|
||||||
|
public Color DopColor { get; private set; }
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес трактора</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
public MultiTraktor(int speed, float weight, Color bodyColor, Color dopColor) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
DopColor = dopColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
85
WinFormsApp1/MultiTraktorDraw.cs
Normal file
85
WinFormsApp1/MultiTraktorDraw.cs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
class MultiTraktorDraw : TractorDraw
|
||||||
|
{
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес трактора</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="trktrWidth">Ширина отрисовки автомобиля</param>
|
||||||
|
/// <param name="trktrHeight">Высота отрисовки автомобиля</param>
|
||||||
|
public MultiTraktorDraw(int speed, float weight, Color bodyColor, Color dopColor) : base(speed, weight, bodyColor, 188, 100)
|
||||||
|
{
|
||||||
|
Tractor = new MultiTraktor(speed, weight, bodyColor, dopColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawEntity(Graphics g)
|
||||||
|
{
|
||||||
|
if (Tractor is not MultiTraktor multiTraktor)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen_Black_1pxl = new Pen(Color.Black, 1);
|
||||||
|
Pen pen_Black_2pxl = new Pen(Color.Black, 2);
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
Brush dopBrush = new SolidBrush(multiTraktor.DopColor);
|
||||||
|
|
||||||
|
PointF point1;
|
||||||
|
PointF point2;
|
||||||
|
PointF point3;
|
||||||
|
PointF point4;
|
||||||
|
|
||||||
|
g.DrawRectangle(pen_Black_1pxl, startPosX, startPosY + 8, 4, 35);
|
||||||
|
g.DrawRectangle(pen_Black_1pxl, startPosX + 33, startPosY + 34, 10, 15);
|
||||||
|
|
||||||
|
point1 = new PointF(startPosX, startPosY + 8);
|
||||||
|
point2 = new PointF(startPosX + 33, startPosY + 41);
|
||||||
|
point3 = new PointF(startPosX + 33, startPosY + 34);
|
||||||
|
point4 = new PointF(startPosX + 7, startPosY + 8);
|
||||||
|
PointF[] curvePoints =
|
||||||
|
{
|
||||||
|
point1,
|
||||||
|
point2,
|
||||||
|
point3,
|
||||||
|
point4
|
||||||
|
};
|
||||||
|
g.FillPolygon(dopBrush, curvePoints);
|
||||||
|
g.DrawPolygon(pen_Black_1pxl, curvePoints);
|
||||||
|
|
||||||
|
point1 = new PointF(startPosX + 6, startPosY + 8 + 15);
|
||||||
|
point2 = new PointF(startPosX + 6, startPosY + 8 + 35);
|
||||||
|
point3 = new PointF(startPosX + 26, startPosY + 8 + 35);
|
||||||
|
PointF[] curvePoints2 =
|
||||||
|
{
|
||||||
|
point1,
|
||||||
|
point2,
|
||||||
|
point3
|
||||||
|
};
|
||||||
|
g.FillPolygon(dopBrush, curvePoints2);
|
||||||
|
g.DrawPolygon(pen_Black_1pxl, curvePoints2);
|
||||||
|
|
||||||
|
startPosX += 43;
|
||||||
|
base.DrawEntity(g);
|
||||||
|
startPosX -= 43;
|
||||||
|
|
||||||
|
point1 = new PointF(startPosX + 43 + 102, startPosY + 30);
|
||||||
|
point2 = new PointF(startPosX + 43 + 102, startPosY + 65);
|
||||||
|
point3 = new PointF(startPosX + 43 + 137, startPosY + 65);
|
||||||
|
|
||||||
|
PointF[] curvePoints3 =
|
||||||
|
{
|
||||||
|
point1,
|
||||||
|
point2,
|
||||||
|
point3
|
||||||
|
};
|
||||||
|
g.FillPolygon(dopBrush, curvePoints3);
|
||||||
|
g.DrawPolygon(pen_Black_1pxl, curvePoints3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@ namespace WinFormsApp1
|
|||||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new FormTractor());
|
Application.Run(new FormMapWithSetTraktor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
87
WinFormsApp1/SetTraktorGeneric.cs
Normal file
87
WinFormsApp1/SetTraktorGeneric.cs
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
internal class SetTraktorGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
private readonly List<T> _places;
|
||||||
|
public int Count => _places.Count;
|
||||||
|
private readonly int _maxCount;
|
||||||
|
private int TractorPlaces = 0;
|
||||||
|
|
||||||
|
public SetTraktorGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new List<T>(); ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T tractor)
|
||||||
|
{
|
||||||
|
return Insert(tractor, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T tractor, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 && position > _maxCount)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_places.Insert(position, tractor);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _maxCount)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var result = _places[position];
|
||||||
|
_places.RemoveAt(position);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public T this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position >= 0 && position < _maxCount && position < Count)
|
||||||
|
{
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Insert(value, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T> GetTraktor()
|
||||||
|
{
|
||||||
|
foreach (var traktor in _places)
|
||||||
|
{
|
||||||
|
if (traktor != null)
|
||||||
|
{
|
||||||
|
yield return traktor;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
50
WinFormsApp1/SimpleMap.cs
Normal file
50
WinFormsApp1/SimpleMap.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
class SimpleMap : AbstractMap
|
||||||
|
{
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
/// Цвет участка открытого
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||||
|
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 33)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 100);
|
||||||
|
int y = _random.Next(0, 100);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,30 +7,41 @@ using System.Drawing;
|
|||||||
|
|
||||||
namespace WinFormsApp1
|
namespace WinFormsApp1
|
||||||
{
|
{
|
||||||
class TractorDraw
|
public class TractorDraw
|
||||||
|
|
||||||
{
|
{
|
||||||
//Сущность
|
//Сущность
|
||||||
public EntityTractor Tractor { get; private set; }
|
public EntityTractor Tractor { get; protected set; }
|
||||||
/// Левая координата отрисовки сущности
|
/// Левая координата отрисовки сущности
|
||||||
private float startPosX;
|
protected float startPosX;
|
||||||
/// Верхняя кооридната отрисовки сущности
|
/// Верхняя кооридната отрисовки сущности
|
||||||
private float startPosY;
|
protected float startPosY;
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
private int? pictureWidth = null;
|
private int? pictureWidth = null;
|
||||||
/// Высота окна отрисовки
|
/// Высота окна отрисовки
|
||||||
private int? pictureHeight = null;
|
private int? pictureHeight = null;
|
||||||
/// Ширина отрисовки сущности
|
/// Ширина отрисовки сущности
|
||||||
private readonly int entWidth = 130;
|
private readonly int entWidth = 115;
|
||||||
/// Высота отрисовки сущности
|
/// Высота отрисовки сущности
|
||||||
private readonly int entHeight = 100;
|
private readonly int entHeight = 100;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodycolor)
|
public TractorDraw(int speed, float weight, Color bodycolor)
|
||||||
{
|
{
|
||||||
Tractor = new EntityTractor();
|
Tractor = new EntityTractor(speed, weight, bodycolor);
|
||||||
Tractor.Init(speed, weight, bodycolor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="trktrWidth">Ширина отрисовки автомобиля</param>
|
||||||
|
/// <param name="trktrHeight">Высота отрисовки автомобиля</param>
|
||||||
|
///
|
||||||
|
protected TractorDraw(int speed, float weight, Color bodyColor, int trktrWidth, int trktrHeight) : this(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
entWidth = trktrWidth;
|
||||||
|
entHeight = trktrHeight;
|
||||||
|
}
|
||||||
//Установка позиции сущности
|
//Установка позиции сущности
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
@@ -112,7 +123,7 @@ namespace WinFormsApp1
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Отрисовка сущности
|
//Отрисовка сущности
|
||||||
public void DrawEntity(Graphics g)
|
public virtual void DrawEntity(Graphics g)
|
||||||
{
|
{
|
||||||
if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue)
|
if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue)
|
||||||
{
|
{
|
||||||
@@ -171,5 +182,9 @@ namespace WinFormsApp1
|
|||||||
startPosY = pictureHeight.Value - entHeight;
|
startPosY = pictureHeight.Value - entHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return (startPosX, startPosY, startPosX + entWidth, startPosY + entHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user