Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
4b7e4d1faa | |||
086fa9134b | |||
c9099a2a41 | |||
d81ae716ab | |||
c17430f76d | |||
4c85daa81d | |||
5bb1d850e7 | |||
bec2383a81 | |||
9ab0f8fa63 | |||
203249781c | |||
437d7894e2 | |||
319fa1298d | |||
974fa03ade | |||
811e02b7bd | |||
146d39f5f0 | |||
72b2d823c7 | |||
92cdbb3813 | |||
b576a536db | |||
6fd602ceb6 | |||
ec4543b521 | |||
2b2a373f1a | |||
64b5568fe3 | |||
138eb45634 | |||
1641fc1883 | |||
4b6aa63101 | |||
7846b78a34 | |||
8857f7ed10 |
25
Lab1ContainersShip/Lab1ContainersShip.sln
Normal file
25
Lab1ContainersShip/Lab1ContainersShip.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.4.33122.133
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab1ContainersShip", "Lab1ContainersShip\Lab1ContainersShip.csproj", "{AFA56719-1551-4DFA-9EC2-1FD7AB801A5E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AFA56719-1551-4DFA-9EC2-1FD7AB801A5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AFA56719-1551-4DFA-9EC2-1FD7AB801A5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AFA56719-1551-4DFA-9EC2-1FD7AB801A5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AFA56719-1551-4DFA-9EC2-1FD7AB801A5E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F02369FD-F9A6-45C3-A628-4869EA7856C1}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
139
Lab1ContainersShip/Lab1ContainersShip/AbstractStrategy.cs
Normal file
139
Lab1ContainersShip/Lab1ContainersShip/AbstractStrategy.cs
Normal file
@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Lab1ContainersShip.DrawingObjects;
|
||||
|
||||
|
||||
namespace Lab1ContainersShip.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private Status _state = Status.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public Status GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int
|
||||
height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false -
|
||||
//неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(Direction.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,
|
||||
//false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(Direction.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,
|
||||
//false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(Direction.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,
|
||||
//false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(Direction.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="directionType">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false -
|
||||
//неудача)</returns>
|
||||
private bool MoveTo(Direction direction)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(direction) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(direction);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
6
Lab1ContainersShip/Lab1ContainersShip/App.config
Normal file
6
Lab1ContainersShip/Lab1ContainersShip/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
</configuration>
|
29
Lab1ContainersShip/Lab1ContainersShip/Direction.cs
Normal file
29
Lab1ContainersShip/Lab1ContainersShip/Direction.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lab1ContainersShip
|
||||
{
|
||||
public enum Direction
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Lab1ContainersShip.Entities;
|
||||
|
||||
namespace Lab1ContainersShip.DrawingObjects
|
||||
{
|
||||
internal class DrawingContainerShip : DrawingShip
|
||||
{
|
||||
public DrawingContainerShip(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool crane, bool containers, int width, int height) :
|
||||
base(speed, weight, bodyColor,width, height, 110, 65) {
|
||||
if (EntityShip != null)
|
||||
{
|
||||
EntityShip = new EntityContainerShip(speed, weight, bodyColor,
|
||||
additionalColor, crane, containers);
|
||||
}
|
||||
}
|
||||
public override void DrawShip(Graphics g)
|
||||
{
|
||||
|
||||
if(EntityShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!(EntityShip is EntityContainerShip)) {
|
||||
return;
|
||||
}
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush adbrush = new SolidBrush((EntityShip as EntityContainerShip).AdditionalColor);
|
||||
base.DrawShip(g);
|
||||
if ((EntityShip as EntityContainerShip).Conteiners)
|
||||
{
|
||||
g.FillRectangle(adbrush, _startPosX + 30, _startPosY + 35, 35, 10);
|
||||
g.FillRectangle(adbrush, _startPosX + 65, _startPosY + 35, 20, 10);
|
||||
g.FillRectangle(adbrush, _startPosX + 85, _startPosY + 30, 15, 15);
|
||||
g.FillRectangle(adbrush, _startPosX + 30, _startPosY + 25, 15, 10);
|
||||
g.FillRectangle(adbrush, _startPosX + 45, _startPosY + 25, 55, 5);
|
||||
g.FillRectangle(adbrush, _startPosX + 45, _startPosY + 30, 40, 5);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 35, 35, 10);
|
||||
g.DrawRectangle(pen, _startPosX + 65, _startPosY + 35, 20, 10);
|
||||
g.DrawRectangle(pen, _startPosX + 85, _startPosY + 30, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 25, 15, 10);
|
||||
g.DrawRectangle(pen, _startPosX + 45, _startPosY + 25, 55, 5);
|
||||
g.DrawRectangle(pen, _startPosX + 45, _startPosY + 30, 40, 5);
|
||||
}
|
||||
//кран
|
||||
if ((EntityShip as EntityContainerShip).Crane)
|
||||
{
|
||||
g.FillRectangle(adbrush, _startPosX + 23, _startPosY, 5, 45);
|
||||
g.FillRectangle(adbrush, _startPosX + 27, _startPosY + 10, 20, 3);
|
||||
g.DrawRectangle(pen, _startPosX + 23, _startPosY, 5, 45);
|
||||
g.DrawRectangle(pen, _startPosX + 27, _startPosY + 10, 20, 3);
|
||||
g.DrawLine(pen, _startPosX + 27, _startPosY, _startPosX + 47, _startPosY + 10);
|
||||
g.DrawLine(pen, _startPosX + 47, _startPosY + 13, _startPosX + 47, _startPosY + 25);
|
||||
}
|
||||
}
|
||||
public void setAddColor(Color color)
|
||||
{
|
||||
if (EntityShip is EntityContainerShip )
|
||||
{
|
||||
(EntityShip as EntityContainerShip).setAddColor(color);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
190
Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs
Normal file
190
Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs
Normal file
@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Lab1ContainersShip.Entities;
|
||||
using Lab1ContainersShip.MovementStrategy;
|
||||
|
||||
namespace Lab1ContainersShip.DrawingObjects
|
||||
{
|
||||
public class DrawingShip
|
||||
{
|
||||
|
||||
public EntityShip EntityShip { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
public int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
public int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _shipWidth = 110;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _shipHeight = 65;
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _shipWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _shipHeight;
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new
|
||||
DrawningObjectShip(this);
|
||||
public bool CanMove(Direction direction)
|
||||
{
|
||||
if(EntityShip == null) return false;
|
||||
switch(direction)
|
||||
{
|
||||
case Direction.Left:
|
||||
return _startPosX - EntityShip.Step > 0;
|
||||
case Direction.Right:
|
||||
return _startPosX + _shipWidth + EntityShip.Step < _pictureWidth;
|
||||
case Direction.Up:
|
||||
return _startPosY - EntityShip.Step > 0;
|
||||
case Direction.Down:
|
||||
return _startPosY + _shipHeight+ EntityShip.Step < _pictureHeight;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DrawingShip(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
if(width < _shipWidth || height < _shipHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityShip = new EntityShip(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawingShip(int speed, double weight, Color bodyColor, int width, int height, int shipWidth, int shipHeight)
|
||||
{
|
||||
if (width < _shipWidth || height < _shipHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_shipHeight = shipHeight;
|
||||
_shipWidth = shipWidth;
|
||||
EntityShip = new EntityShip(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
// TODO: Изменение x, y
|
||||
_startPosX = Math.Min(x, _pictureWidth - _shipWidth);
|
||||
_startPosY = Math.Min(y, _pictureHeight - _shipHeight);
|
||||
}
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case Direction.Left:
|
||||
if (_startPosX - EntityShip.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityShip.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case Direction.Up:
|
||||
if (_startPosY - EntityShip.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityShip.Step;
|
||||
}
|
||||
break;
|
||||
// вправо
|
||||
case Direction.Right:
|
||||
// TODO: Продумать логику
|
||||
if (_startPosX + EntityShip.Step + _shipWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityShip.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case Direction.Down:
|
||||
// TODO: Продумать логику
|
||||
if (_startPosY + EntityShip.Step + _shipHeight< _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityShip.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public virtual void DrawShip(Graphics g)
|
||||
{
|
||||
if (EntityShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new Pen(Color.Black);
|
||||
|
||||
Brush brBody = new SolidBrush(EntityShip.BodyColor);
|
||||
// заполнение борта
|
||||
g.FillPolygon(brBody, new PointF[]
|
||||
{
|
||||
new PointF(_startPosX, _startPosY+45),
|
||||
new PointF(_startPosX+20, _startPosY+65),
|
||||
new PointF(_startPosX+90, _startPosY+65),
|
||||
new PointF(_startPosX+110, _startPosY+45),
|
||||
new PointF(_startPosX, _startPosY+45)
|
||||
});
|
||||
//борт корабля контур
|
||||
g.DrawLines(pen, new Point[] {
|
||||
new Point(_startPosX, _startPosY+45),
|
||||
new Point(_startPosX+20, _startPosY+65),
|
||||
new Point(_startPosX+90, _startPosY+65),
|
||||
new Point(_startPosX+110, _startPosY+45),
|
||||
new Point(_startPosX, _startPosY+45)});
|
||||
|
||||
//рисунок на борту
|
||||
g.DrawLine(pen, _startPosX + 23, _startPosY + 60, _startPosX + 27, _startPosY + 60);
|
||||
g.DrawLine(pen, _startPosX + 25, _startPosY + 50, _startPosX + 25, _startPosY + 60);
|
||||
g.DrawLine(pen, _startPosX + 20, _startPosY + 55, _startPosX + 30, _startPosY + 55);
|
||||
|
||||
//контейнеры
|
||||
|
||||
}
|
||||
public void setColor(Color color)
|
||||
{
|
||||
EntityShip.setColor(color);
|
||||
}
|
||||
}
|
||||
}
|
37
Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs
Normal file
37
Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Lab1ContainersShip.DrawingObjects;
|
||||
|
||||
namespace Lab1ContainersShip.MovementStrategy
|
||||
{
|
||||
public class DrawningObjectShip : IMoveableObject
|
||||
{
|
||||
private readonly DrawingShip _drawingShip = null;
|
||||
public DrawningObjectShip(DrawingShip drawingShip)
|
||||
{
|
||||
_drawingShip = drawingShip;
|
||||
}
|
||||
public ObjectParameters GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawingShip == null || _drawingShip.EntityShip ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawingShip.GetPosX,
|
||||
_drawingShip.GetPosY, _drawingShip.GetWidth, _drawingShip.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawingShip?.EntityShip.Step ?? 0);
|
||||
public bool CheckCanMove(Direction direction) =>
|
||||
_drawingShip?.CanMove(direction) ?? false;
|
||||
public void MoveObject(Direction direction) =>
|
||||
_drawingShip?.MoveTransport(direction);
|
||||
|
||||
}
|
||||
}
|
33
Lab1ContainersShip/Lab1ContainersShip/EntityContainerShip.cs
Normal file
33
Lab1ContainersShip/Lab1ContainersShip/EntityContainerShip.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lab1ContainersShip.Entities
|
||||
{
|
||||
internal class EntityContainerShip : EntityShip
|
||||
{
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия крана
|
||||
/// </summary>
|
||||
public bool Crane { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия контейнеров
|
||||
/// </summary>
|
||||
public bool Conteiners { get; private set; }
|
||||
public EntityContainerShip(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
bool crane, bool containers ) : base (speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Crane = crane;
|
||||
Conteiners = containers;
|
||||
}
|
||||
public void setAddColor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
38
Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs
Normal file
38
Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lab1ContainersShip.Entities
|
||||
{
|
||||
public class EntityShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
public EntityShip(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
|
||||
}
|
||||
public void setColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
}
|
||||
}
|
191
Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs
generated
Normal file
191
Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs
generated
Normal file
@ -0,0 +1,191 @@
|
||||
namespace Lab1ContainersShip
|
||||
{
|
||||
partial class FormContainerShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором форм Windows
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
this.buttonCreateContainerShip = new System.Windows.Forms.Button();
|
||||
this.buttonCreateShip = new System.Windows.Forms.Button();
|
||||
this.ButtonSelectCar = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Lab1ContainersShip.Properties.Resources.photo;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(696, 339);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 2;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// 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(884, 461);
|
||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBox1.TabIndex = 0;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::Lab1ContainersShip.Properties.Resources.photo1;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(730, 375);
|
||||
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);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::Lab1ContainersShip.Properties.Resources.photo3;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(660, 375);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 4;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.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::Lab1ContainersShip.Properties.Resources.photo2;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(696, 411);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 5;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxStrategy.FormattingEnabled = true;
|
||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||
"MoveToCenter",
|
||||
"MoveToRight-Down"});
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(751, 12);
|
||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 21);
|
||||
this.comboBoxStrategy.TabIndex = 6;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
this.buttonStep.Location = new System.Drawing.Point(797, 39);
|
||||
this.buttonStep.Name = "buttonStep";
|
||||
this.buttonStep.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonStep.TabIndex = 7;
|
||||
this.buttonStep.Text = "шаг";
|
||||
this.buttonStep.UseVisualStyleBackColor = true;
|
||||
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||
//
|
||||
// buttonCreateContainerShip
|
||||
//
|
||||
this.buttonCreateContainerShip.Location = new System.Drawing.Point(12, 411);
|
||||
this.buttonCreateContainerShip.Name = "buttonCreateContainerShip";
|
||||
this.buttonCreateContainerShip.Size = new System.Drawing.Size(97, 38);
|
||||
this.buttonCreateContainerShip.TabIndex = 8;
|
||||
this.buttonCreateContainerShip.Text = "создать контейнеровоз";
|
||||
this.buttonCreateContainerShip.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateContainerShip.Click += new System.EventHandler(this.buttonCreateContainerShip_Click);
|
||||
//
|
||||
// buttonCreateShip
|
||||
//
|
||||
this.buttonCreateShip.Location = new System.Drawing.Point(115, 411);
|
||||
this.buttonCreateShip.Name = "buttonCreateShip";
|
||||
this.buttonCreateShip.Size = new System.Drawing.Size(94, 38);
|
||||
this.buttonCreateShip.TabIndex = 9;
|
||||
this.buttonCreateShip.Text = "создать кораблик";
|
||||
this.buttonCreateShip.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateShip.Click += new System.EventHandler(this.buttonCreateShip_Click);
|
||||
//
|
||||
// ButtonSelectCar
|
||||
//
|
||||
this.ButtonSelectCar.Location = new System.Drawing.Point(335, 418);
|
||||
this.ButtonSelectCar.Name = "ButtonSelectCar";
|
||||
this.ButtonSelectCar.Size = new System.Drawing.Size(75, 23);
|
||||
this.ButtonSelectCar.TabIndex = 10;
|
||||
this.ButtonSelectCar.Text = "выбрать";
|
||||
this.ButtonSelectCar.UseVisualStyleBackColor = true;
|
||||
this.ButtonSelectCar.Click += new System.EventHandler(this.ButtonSelectCar_Click);
|
||||
//
|
||||
// FormContainerShip
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||
this.Controls.Add(this.ButtonSelectCar);
|
||||
this.Controls.Add(this.buttonCreateShip);
|
||||
this.Controls.Add(this.buttonCreateContainerShip);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Name = "FormContainerShip";
|
||||
this.Text = "контейнеровоз";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.PictureBox pictureBox1;
|
||||
private System.Windows.Forms.Button buttonUp;
|
||||
private System.Windows.Forms.Button buttonRight;
|
||||
private System.Windows.Forms.Button buttonLeft;
|
||||
private System.Windows.Forms.Button buttonDown;
|
||||
private System.Windows.Forms.ComboBox comboBoxStrategy;
|
||||
private System.Windows.Forms.Button buttonStep;
|
||||
private System.Windows.Forms.Button buttonCreateContainerShip;
|
||||
private System.Windows.Forms.Button buttonCreateShip;
|
||||
private System.Windows.Forms.Button ButtonSelectCar;
|
||||
}
|
||||
}
|
||||
|
175
Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs
Normal file
175
Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs
Normal file
@ -0,0 +1,175 @@
|
||||
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 Lab1ContainersShip.DrawingObjects;
|
||||
using Lab1ContainersShip.MovementStrategy;
|
||||
|
||||
namespace Lab1ContainersShip
|
||||
{
|
||||
public partial class FormContainerShip : Form
|
||||
{
|
||||
private DrawingShip _drawingShip;
|
||||
|
||||
|
||||
private AbstractStrategy _abstractStrategy;
|
||||
public DrawingShip SelectedShip { get; private set; }
|
||||
|
||||
public FormContainerShip()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedShip = null;
|
||||
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
|
||||
if (_drawingShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new Bitmap (pictureBox1.Width,
|
||||
pictureBox1.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
if(_drawingShip is DrawingShip)
|
||||
{
|
||||
(_drawingShip as DrawingShip).DrawShip(gr);
|
||||
}
|
||||
else
|
||||
{
|
||||
_drawingShip.DrawShip(gr);
|
||||
}
|
||||
pictureBox1.Image = bmp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingShip.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingShip.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingShip.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingShip.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
|
||||
switch (comboBoxStrategy.SelectedIndex)
|
||||
{
|
||||
case 0:
|
||||
_abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_abstractStrategy = new MoveToBorder();
|
||||
break;
|
||||
default:
|
||||
_abstractStrategy = null;
|
||||
break;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawningObjectShip(_drawingShip), pictureBox1.Width,
|
||||
pictureBox1.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonCreateContainerShip_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 ColorDialog();
|
||||
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 dopdialog = new ColorDialog();
|
||||
if (dopdialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dopdialog.Color;
|
||||
}
|
||||
_drawingShip = new DrawingContainerShip(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
color, dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBox1.Width, pictureBox1.Height);
|
||||
_drawingShip.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonCreateShip_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 ColorDialog();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
_drawingShip = new DrawingShip(random.Next(100, 300), random.Next(1000, 3000),color,
|
||||
pictureBox1.Width, pictureBox1.Height);
|
||||
_drawingShip.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
|
||||
}
|
||||
private void ButtonSelectCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedShip = _drawingShip;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
120
Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.resx
Normal file
120
Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.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>
|
171
Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.Designer.cs
generated
Normal file
171
Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
||||
namespace Lab1ContainersShip
|
||||
{
|
||||
partial class FormShipCollection
|
||||
{
|
||||
/// <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.panel1 = new System.Windows.Forms.Panel();
|
||||
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||
this.ButtonAddObject = new System.Windows.Forms.Button();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
this.ButtonDelObject = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveCar = new System.Windows.Forms.Button();
|
||||
this.ButtonAddCar = new System.Windows.Forms.Button();
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.textBoxStorageName);
|
||||
this.panel1.Controls.Add(this.ButtonAddObject);
|
||||
this.panel1.Controls.Add(this.listBoxStorages);
|
||||
this.panel1.Controls.Add(this.ButtonDelObject);
|
||||
this.panel1.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.panel1.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.panel1.Controls.Add(this.ButtonRemoveCar);
|
||||
this.panel1.Controls.Add(this.ButtonAddCar);
|
||||
this.panel1.Location = new System.Drawing.Point(646, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(157, 449);
|
||||
this.panel1.TabIndex = 1;
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
this.textBoxStorageName.Location = new System.Drawing.Point(18, 25);
|
||||
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||
this.textBoxStorageName.Size = new System.Drawing.Size(118, 20);
|
||||
this.textBoxStorageName.TabIndex = 5;
|
||||
//
|
||||
// ButtonAddObject
|
||||
//
|
||||
this.ButtonAddObject.Location = new System.Drawing.Point(18, 51);
|
||||
this.ButtonAddObject.Name = "ButtonAddObject";
|
||||
this.ButtonAddObject.Size = new System.Drawing.Size(118, 29);
|
||||
this.ButtonAddObject.TabIndex = 2;
|
||||
this.ButtonAddObject.Text = "добавить набор";
|
||||
this.ButtonAddObject.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(18, 86);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(120, 95);
|
||||
this.listBoxStorages.TabIndex = 4;
|
||||
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
|
||||
//
|
||||
// ButtonDelObject
|
||||
//
|
||||
this.ButtonDelObject.Location = new System.Drawing.Point(18, 187);
|
||||
this.ButtonDelObject.Name = "ButtonDelObject";
|
||||
this.ButtonDelObject.Size = new System.Drawing.Size(118, 30);
|
||||
this.ButtonDelObject.TabIndex = 2;
|
||||
this.ButtonDelObject.Text = "удалить набор";
|
||||
this.ButtonDelObject.UseVisualStyleBackColor = true;
|
||||
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(16, 330);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 20);
|
||||
this.maskedTextBoxNumber.TabIndex = 3;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(16, 401);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(118, 37);
|
||||
this.ButtonRefreshCollection.TabIndex = 2;
|
||||
this.ButtonRefreshCollection.Text = "обновить коллекцию";
|
||||
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||
//
|
||||
// ButtonRemoveCar
|
||||
//
|
||||
this.ButtonRemoveCar.Location = new System.Drawing.Point(16, 356);
|
||||
this.ButtonRemoveCar.Name = "ButtonRemoveCar";
|
||||
this.ButtonRemoveCar.Size = new System.Drawing.Size(118, 39);
|
||||
this.ButtonRemoveCar.TabIndex = 1;
|
||||
this.ButtonRemoveCar.Text = "удалить контейнеровоз";
|
||||
this.ButtonRemoveCar.UseVisualStyleBackColor = true;
|
||||
this.ButtonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
|
||||
//
|
||||
// ButtonAddCar
|
||||
//
|
||||
this.ButtonAddCar.Location = new System.Drawing.Point(16, 286);
|
||||
this.ButtonAddCar.Name = "ButtonAddCar";
|
||||
this.ButtonAddCar.Size = new System.Drawing.Size(118, 38);
|
||||
this.ButtonAddCar.TabIndex = 0;
|
||||
this.ButtonAddCar.Text = "добавить контейнеровоз";
|
||||
this.ButtonAddCar.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddCar.Click += new System.EventHandler(this.ButtonAddCar_Click);
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(640, 449);
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// FormShipCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Name = "FormShipCollection";
|
||||
this.Text = "FormShipCollection";
|
||||
this.Load += new System.EventHandler(this.FormShipCollection_Load);
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.PictureBox pictureBoxCollection;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.TextBox maskedTextBoxNumber;
|
||||
private System.Windows.Forms.Button ButtonRefreshCollection;
|
||||
private System.Windows.Forms.Button ButtonRemoveCar;
|
||||
private System.Windows.Forms.Button ButtonAddCar;
|
||||
private System.Windows.Forms.TextBox textBoxStorageName;
|
||||
private System.Windows.Forms.Button ButtonAddObject;
|
||||
private System.Windows.Forms.ListBox listBoxStorages;
|
||||
private System.Windows.Forms.Button ButtonDelObject;
|
||||
}
|
||||
}
|
166
Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs
Normal file
166
Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs
Normal file
@ -0,0 +1,166 @@
|
||||
using Lab1ContainersShip.DrawingObjects;
|
||||
using Lab1ContainersShip.MovementStrategy;
|
||||
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 Lab1ContainersShip
|
||||
{
|
||||
public partial class FormShipCollection : Form
|
||||
{
|
||||
private readonly ShipGenericStorage _storage;
|
||||
public FormShipCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new ShipGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
|
||||
private void FormShipCollection_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
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)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
private void ListBoxObjects_SelectedIndexChanged(object sender,EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowShips();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void ButtonAddCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormShipConfig formShipConfig = new FormShipConfig();
|
||||
formShipConfig.AddEvent(addShip);
|
||||
formShipConfig.Show();
|
||||
|
||||
|
||||
}
|
||||
private void addShip(DrawingShip drawningShip)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((obj + drawningShip) != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowShips();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowShips();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowShips();
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.resx
Normal file
120
Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.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>
|
426
Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.Designer.cs
generated
Normal file
426
Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.Designer.cs
generated
Normal file
@ -0,0 +1,426 @@
|
||||
namespace Lab1ContainersShip
|
||||
{
|
||||
partial class FormShipConfig
|
||||
{
|
||||
/// <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.labelModifiedObject = new System.Windows.Forms.Label();
|
||||
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.panelPink = new System.Windows.Forms.Panel();
|
||||
this.panelPurple = new System.Windows.Forms.Panel();
|
||||
this.panelBlue = new System.Windows.Forms.Panel();
|
||||
this.panelLightBlue = new System.Windows.Forms.Panel();
|
||||
this.panelGreen = new System.Windows.Forms.Panel();
|
||||
this.panelYellow = new System.Windows.Forms.Panel();
|
||||
this.panel6 = new System.Windows.Forms.Panel();
|
||||
this.panelOrange = new System.Windows.Forms.Panel();
|
||||
this.panel4 = new System.Windows.Forms.Panel();
|
||||
this.panelRed = new System.Windows.Forms.Panel();
|
||||
this.panel2 = new System.Windows.Forms.Panel();
|
||||
this.checkBoxContainers = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxCrane = new System.Windows.Forms.CheckBox();
|
||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.panel12 = new System.Windows.Forms.Panel();
|
||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.buttonOk = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.labelColor = new System.Windows.Forms.Label();
|
||||
this.labelAddColor = new System.Windows.Forms.Label();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.panelYellow.SuspendLayout();
|
||||
this.panelOrange.SuspendLayout();
|
||||
this.panelRed.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||
this.panel12.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.labelModifiedObject);
|
||||
this.groupBox1.Controls.Add(this.labelSimpleObject);
|
||||
this.groupBox1.Controls.Add(this.groupBox2);
|
||||
this.groupBox1.Controls.Add(this.checkBoxContainers);
|
||||
this.groupBox1.Controls.Add(this.checkBoxCrane);
|
||||
this.groupBox1.Controls.Add(this.numericUpDownWeight);
|
||||
this.groupBox1.Controls.Add(this.numericUpDownSpeed);
|
||||
this.groupBox1.Controls.Add(this.label3);
|
||||
this.groupBox1.Controls.Add(this.label2);
|
||||
this.groupBox1.Controls.Add(this.label1);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(466, 323);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Параметры";
|
||||
//
|
||||
// labelModifiedObject
|
||||
//
|
||||
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelModifiedObject.Location = new System.Drawing.Point(331, 229);
|
||||
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||
this.labelModifiedObject.Size = new System.Drawing.Size(100, 32);
|
||||
this.labelModifiedObject.TabIndex = 10;
|
||||
this.labelModifiedObject.Text = "Продвинутый";
|
||||
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelSimpleObject.Location = new System.Drawing.Point(206, 229);
|
||||
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||
this.labelSimpleObject.Size = new System.Drawing.Size(100, 32);
|
||||
this.labelSimpleObject.TabIndex = 9;
|
||||
this.labelSimpleObject.Text = "Простой";
|
||||
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.panelPink);
|
||||
this.groupBox2.Controls.Add(this.panelPurple);
|
||||
this.groupBox2.Controls.Add(this.panelBlue);
|
||||
this.groupBox2.Controls.Add(this.panelLightBlue);
|
||||
this.groupBox2.Controls.Add(this.panelGreen);
|
||||
this.groupBox2.Controls.Add(this.panelYellow);
|
||||
this.groupBox2.Controls.Add(this.panelOrange);
|
||||
this.groupBox2.Controls.Add(this.panelRed);
|
||||
this.groupBox2.Location = new System.Drawing.Point(196, 31);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(246, 158);
|
||||
this.groupBox2.TabIndex = 8;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Цвета";
|
||||
//
|
||||
// panelPink
|
||||
//
|
||||
this.panelPink.BackColor = System.Drawing.Color.Fuchsia;
|
||||
this.panelPink.Location = new System.Drawing.Point(187, 75);
|
||||
this.panelPink.Name = "panelPink";
|
||||
this.panelPink.Size = new System.Drawing.Size(43, 41);
|
||||
this.panelPink.TabIndex = 0;
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
this.panelPurple.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(64)))));
|
||||
this.panelPurple.Location = new System.Drawing.Point(125, 75);
|
||||
this.panelPurple.Name = "panelPurple";
|
||||
this.panelPurple.Size = new System.Drawing.Size(43, 40);
|
||||
this.panelPurple.TabIndex = 0;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||
this.panelBlue.Location = new System.Drawing.Point(64, 75);
|
||||
this.panelBlue.Name = "panelBlue";
|
||||
this.panelBlue.Size = new System.Drawing.Size(43, 40);
|
||||
this.panelBlue.TabIndex = 0;
|
||||
//
|
||||
// panelLightBlue
|
||||
//
|
||||
this.panelLightBlue.BackColor = System.Drawing.Color.Cyan;
|
||||
this.panelLightBlue.Location = new System.Drawing.Point(6, 75);
|
||||
this.panelLightBlue.Name = "panelLightBlue";
|
||||
this.panelLightBlue.Size = new System.Drawing.Size(40, 40);
|
||||
this.panelLightBlue.TabIndex = 13;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.Lime;
|
||||
this.panelGreen.Location = new System.Drawing.Point(187, 19);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(43, 41);
|
||||
this.panelGreen.TabIndex = 12;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||
this.panelYellow.Controls.Add(this.panel6);
|
||||
this.panelYellow.Location = new System.Drawing.Point(125, 19);
|
||||
this.panelYellow.Name = "panelYellow";
|
||||
this.panelYellow.Size = new System.Drawing.Size(43, 38);
|
||||
this.panelYellow.TabIndex = 11;
|
||||
//
|
||||
// panel6
|
||||
//
|
||||
this.panel6.Location = new System.Drawing.Point(0, 44);
|
||||
this.panel6.Name = "panel6";
|
||||
this.panel6.Size = new System.Drawing.Size(43, 56);
|
||||
this.panel6.TabIndex = 0;
|
||||
//
|
||||
// panelOrange
|
||||
//
|
||||
this.panelOrange.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
|
||||
this.panelOrange.Controls.Add(this.panel4);
|
||||
this.panelOrange.Location = new System.Drawing.Point(64, 19);
|
||||
this.panelOrange.Name = "panelOrange";
|
||||
this.panelOrange.Size = new System.Drawing.Size(43, 38);
|
||||
this.panelOrange.TabIndex = 10;
|
||||
//
|
||||
// panel4
|
||||
//
|
||||
this.panel4.Location = new System.Drawing.Point(0, 44);
|
||||
this.panel4.Name = "panel4";
|
||||
this.panel4.Size = new System.Drawing.Size(43, 56);
|
||||
this.panel4.TabIndex = 0;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||
this.panelRed.Controls.Add(this.panel2);
|
||||
this.panelRed.Location = new System.Drawing.Point(6, 19);
|
||||
this.panelRed.Name = "panelRed";
|
||||
this.panelRed.Size = new System.Drawing.Size(40, 38);
|
||||
this.panelRed.TabIndex = 9;
|
||||
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
this.panel2.Location = new System.Drawing.Point(157, 72);
|
||||
this.panel2.Name = "panel2";
|
||||
this.panel2.Size = new System.Drawing.Size(43, 28);
|
||||
this.panel2.TabIndex = 0;
|
||||
//
|
||||
// checkBoxContainers
|
||||
//
|
||||
this.checkBoxContainers.AutoSize = true;
|
||||
this.checkBoxContainers.Location = new System.Drawing.Point(9, 129);
|
||||
this.checkBoxContainers.Name = "checkBoxContainers";
|
||||
this.checkBoxContainers.Size = new System.Drawing.Size(88, 17);
|
||||
this.checkBoxContainers.TabIndex = 7;
|
||||
this.checkBoxContainers.Text = "Контейнеры";
|
||||
this.checkBoxContainers.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxCrane
|
||||
//
|
||||
this.checkBoxCrane.AutoSize = true;
|
||||
this.checkBoxCrane.Location = new System.Drawing.Point(9, 106);
|
||||
this.checkBoxCrane.Name = "checkBoxCrane";
|
||||
this.checkBoxCrane.Size = new System.Drawing.Size(51, 17);
|
||||
this.checkBoxCrane.TabIndex = 6;
|
||||
this.checkBoxCrane.Text = "Кран";
|
||||
this.checkBoxCrane.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
this.numericUpDownWeight.Location = new System.Drawing.Point(41, 65);
|
||||
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(120, 20);
|
||||
this.numericUpDownWeight.TabIndex = 5;
|
||||
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(70, 29);
|
||||
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(120, 20);
|
||||
this.numericUpDownSpeed.TabIndex = 4;
|
||||
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(17, 47);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(0, 13);
|
||||
this.label3.TabIndex = 3;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(6, 67);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(29, 13);
|
||||
this.label2.TabIndex = 2;
|
||||
this.label2.Text = "Вес:";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(6, 31);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(58, 13);
|
||||
this.label1.TabIndex = 1;
|
||||
this.label1.Text = "Скорость:";
|
||||
//
|
||||
// panel12
|
||||
//
|
||||
this.panel12.AllowDrop = true;
|
||||
this.panel12.Controls.Add(this.pictureBoxObject);
|
||||
this.panel12.Location = new System.Drawing.Point(484, 43);
|
||||
this.panel12.Name = "panel12";
|
||||
this.panel12.Size = new System.Drawing.Size(316, 235);
|
||||
this.panel12.TabIndex = 1;
|
||||
this.panel12.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||
this.panel12.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
this.pictureBoxObject.Location = new System.Drawing.Point(3, 3);
|
||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||
this.pictureBoxObject.Size = new System.Drawing.Size(310, 204);
|
||||
this.pictureBoxObject.TabIndex = 0;
|
||||
this.pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// buttonOk
|
||||
//
|
||||
this.buttonOk.Location = new System.Drawing.Point(526, 284);
|
||||
this.buttonOk.Name = "buttonOk";
|
||||
this.buttonOk.Size = new System.Drawing.Size(89, 39);
|
||||
this.buttonOk.TabIndex = 2;
|
||||
this.buttonOk.Text = "Добавить";
|
||||
this.buttonOk.UseVisualStyleBackColor = true;
|
||||
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(702, 284);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(95, 39);
|
||||
this.buttonCancel.TabIndex = 3;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// labelColor
|
||||
//
|
||||
this.labelColor.AllowDrop = true;
|
||||
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelColor.Location = new System.Drawing.Point(494, 12);
|
||||
this.labelColor.Name = "labelColor";
|
||||
this.labelColor.Size = new System.Drawing.Size(100, 23);
|
||||
this.labelColor.TabIndex = 4;
|
||||
this.labelColor.Text = "Цвет";
|
||||
this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
|
||||
this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
//
|
||||
// labelAddColor
|
||||
//
|
||||
this.labelAddColor.AllowDrop = true;
|
||||
this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelAddColor.Location = new System.Drawing.Point(632, 13);
|
||||
this.labelAddColor.Name = "labelAddColor";
|
||||
this.labelAddColor.Size = new System.Drawing.Size(100, 23);
|
||||
this.labelAddColor.TabIndex = 5;
|
||||
this.labelAddColor.Text = "Доп. цвет";
|
||||
this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop);
|
||||
this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
//
|
||||
// FormShipConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 347);
|
||||
this.Controls.Add(this.labelAddColor);
|
||||
this.Controls.Add(this.labelColor);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonOk);
|
||||
this.Controls.Add(this.panel12);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Name = "FormShipConfig";
|
||||
this.Text = "FormShipConfig";
|
||||
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop);
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.panelYellow.ResumeLayout(false);
|
||||
this.panelOrange.ResumeLayout(false);
|
||||
this.panelRed.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||
this.panel12.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.CheckBox checkBoxContainers;
|
||||
private System.Windows.Forms.CheckBox checkBoxCrane;
|
||||
private System.Windows.Forms.NumericUpDown numericUpDownWeight;
|
||||
private System.Windows.Forms.NumericUpDown numericUpDownSpeed;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label labelSimpleObject;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.Panel panelPink;
|
||||
private System.Windows.Forms.Panel panelPurple;
|
||||
private System.Windows.Forms.Panel panelBlue;
|
||||
private System.Windows.Forms.Panel panelLightBlue;
|
||||
private System.Windows.Forms.Panel panelGreen;
|
||||
private System.Windows.Forms.Panel panelYellow;
|
||||
private System.Windows.Forms.Panel panel6;
|
||||
private System.Windows.Forms.Panel panelOrange;
|
||||
private System.Windows.Forms.Panel panel4;
|
||||
private System.Windows.Forms.Panel panelRed;
|
||||
private System.Windows.Forms.Panel panel2;
|
||||
private System.Windows.Forms.Label labelModifiedObject;
|
||||
private System.Windows.Forms.Panel panel12;
|
||||
private System.Windows.Forms.PictureBox pictureBoxObject;
|
||||
private System.Windows.Forms.Button buttonOk;
|
||||
private System.Windows.Forms.Button buttonCancel;
|
||||
private System.Windows.Forms.Label labelColor;
|
||||
private System.Windows.Forms.Label labelAddColor;
|
||||
}
|
||||
}
|
138
Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.cs
Normal file
138
Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.cs
Normal file
@ -0,0 +1,138 @@
|
||||
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 Lab1ContainersShip.DrawingObjects;
|
||||
using Lab1ContainersShip.Entities;
|
||||
|
||||
|
||||
namespace Lab1ContainersShip
|
||||
{
|
||||
public partial class FormShipConfig : Form
|
||||
{
|
||||
DrawingShip _ship = null;
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
|
||||
|
||||
private event Action<DrawingShip> EventAddShip;
|
||||
public void AddEvent(Action<DrawingShip> ev)
|
||||
{
|
||||
if (EventAddShip == null)
|
||||
{
|
||||
EventAddShip = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddShip += ev;
|
||||
}
|
||||
}
|
||||
private void ButtonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddShip?.Invoke(_ship);
|
||||
Close();
|
||||
}
|
||||
|
||||
public FormShipConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelRed.MouseDown += PanelColor_MouseDown;
|
||||
panelOrange.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||
panelLightBlue.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||
panelPink.MouseDown += PanelColor_MouseDown;
|
||||
buttonCancel.Click += (s, e) => Close();
|
||||
}
|
||||
private void DrawShip()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_ship?.SetPosition(5, 5);
|
||||
_ship?.DrawShip(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
|
||||
|
||||
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 "labelSimpleObject":
|
||||
_ship = new DrawingShip((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
||||
pictureBoxObject.Height);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_ship = new DrawingContainerShip((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxCrane.Checked,
|
||||
checkBoxContainers.Checked, pictureBoxObject.Width,pictureBoxObject.Height);
|
||||
break;
|
||||
}
|
||||
DrawShip();
|
||||
}
|
||||
|
||||
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
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 LabelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
|
||||
if (_ship is DrawingShip)
|
||||
{
|
||||
labelColor.BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||
_ship.setColor((Color)e.Data.GetData(typeof(Color)));
|
||||
}
|
||||
DrawShip();
|
||||
}
|
||||
|
||||
private void LabelAddColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
|
||||
if (_ship is DrawingContainerShip)
|
||||
{
|
||||
labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||
(_ship as DrawingContainerShip).setAddColor((Color)e.Data.GetData(typeof(Color)));
|
||||
}
|
||||
DrawShip();
|
||||
}
|
||||
}
|
||||
}
|
120
Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.resx
Normal file
120
Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.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>
|
37
Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs
Normal file
37
Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Lab1ContainersShip.DrawingObjects;
|
||||
|
||||
namespace Lab1ContainersShip.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты X объекта
|
||||
/// </summary>
|
||||
ObjectParameters GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Проверка, можно ли переместиться по нужному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool CheckCanMove(Direction direction);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(Direction direction);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Remove="ShipCollection.resx" />
|
||||
</ItemGroup>
|
||||
</Project>
|
56
Lab1ContainersShip/Lab1ContainersShip/MoveToBorder.cs
Normal file
56
Lab1ContainersShip/Lab1ContainersShip/MoveToBorder.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lab1ContainersShip.MovementStrategy
|
||||
{
|
||||
internal class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
Lab1ContainersShip/Lab1ContainersShip/MoveToCenter.cs
Normal file
58
Lab1ContainersShip/Lab1ContainersShip/MoveToCenter.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using Lab1ContainersShip.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lab1ContainersShip.MovementStrategy
|
||||
{
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
58
Lab1ContainersShip/Lab1ContainersShip/ObjectParameters.cs
Normal file
58
Lab1ContainersShip/Lab1ContainersShip/ObjectParameters.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lab1ContainersShip.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
/// </summary>
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
22
Lab1ContainersShip/Lab1ContainersShip/Program.cs
Normal file
22
Lab1ContainersShip/Lab1ContainersShip/Program.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Lab1ContainersShip
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// Главная точка входа для приложения.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormShipCollection());
|
||||
}
|
||||
}
|
||||
}
|
103
Lab1ContainersShip/Lab1ContainersShip/Properties/Resources.Designer.cs
generated
Normal file
103
Lab1ContainersShip/Lab1ContainersShip/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Lab1ContainersShip.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Lab1ContainersShip.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap photo {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("photo", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap photo1 {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("photo1", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap photo2 {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("photo2", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap photo3 {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("photo3", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
133
Lab1ContainersShip/Lab1ContainersShip/Properties/Resources.resx
Normal file
133
Lab1ContainersShip/Lab1ContainersShip/Properties/Resources.resx
Normal file
@ -0,0 +1,133 @@
|
||||
<?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>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="photo" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\photo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="photo1" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\photo1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="photo2" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\photo2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="photo3" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\photo3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
30
Lab1ContainersShip/Lab1ContainersShip/Properties/Settings.Designer.cs
generated
Normal file
30
Lab1ContainersShip/Lab1ContainersShip/Properties/Settings.Designer.cs
generated
Normal file
@ -0,0 +1,30 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Lab1ContainersShip.Properties
|
||||
{
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
BIN
Lab1ContainersShip/Lab1ContainersShip/Resources/photo.png
Normal file
BIN
Lab1ContainersShip/Lab1ContainersShip/Resources/photo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
BIN
Lab1ContainersShip/Lab1ContainersShip/Resources/photo1.png
Normal file
BIN
Lab1ContainersShip/Lab1ContainersShip/Resources/photo1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
BIN
Lab1ContainersShip/Lab1ContainersShip/Resources/photo2.png
Normal file
BIN
Lab1ContainersShip/Lab1ContainersShip/Resources/photo2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
BIN
Lab1ContainersShip/Lab1ContainersShip/Resources/photo3.png
Normal file
BIN
Lab1ContainersShip/Lab1ContainersShip/Resources/photo3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
156
Lab1ContainersShip/Lab1ContainersShip/SetGeneric.cs
Normal file
156
Lab1ContainersShip/Lab1ContainersShip/SetGeneric.cs
Normal file
@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lab1ContainersShip
|
||||
{
|
||||
public class SetGeneric<T>
|
||||
where T : class
|
||||
|
||||
{
|
||||
// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Count;
|
||||
public int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T ship)
|
||||
{
|
||||
// TODO вставка в начало набора
|
||||
if(_places.Count >= _maxCount)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_places.Insert(0, ship);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T ship, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой,
|
||||
//если нет, то
|
||||
// проверка, что после вставляемого элемента в
|
||||
//массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от
|
||||
//позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
if(_places.Count >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(position < 0 || position > _places.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(position == _places.Count)
|
||||
{
|
||||
_places.Add(ship);
|
||||
}
|
||||
else
|
||||
{
|
||||
_places.Insert(position, ship);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива
|
||||
//значение null
|
||||
if(position < _places.Count && _places.Count < _maxCount)
|
||||
{
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
if(position < _places.Count && position >= 0)
|
||||
{
|
||||
return _places[position];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public T this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < _places.Count && position >= 0)
|
||||
{
|
||||
return _places[position];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
set
|
||||
{
|
||||
|
||||
Insert(value, position);
|
||||
|
||||
}
|
||||
}
|
||||
public IEnumerable<T> GetShips(int? maxCars = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxCars.HasValue && i == maxCars.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
120
Lab1ContainersShip/Lab1ContainersShip/ShipCollection.resx
Normal file
120
Lab1ContainersShip/Lab1ContainersShip/ShipCollection.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>
|
147
Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs
Normal file
147
Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs
Normal file
@ -0,0 +1,147 @@
|
||||
using Lab1ContainersShip.DrawingObjects;
|
||||
using Lab1ContainersShip.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lab1ContainersShip
|
||||
{
|
||||
public class ShipGenericCollection <T, U>
|
||||
where T : DrawingShip
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <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;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public ShipGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(ShipGenericCollection<T, U> collect, T
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(ShipGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U GetU(int pos)
|
||||
{
|
||||
return (U)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowShips()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var ship in _collection.GetShips())
|
||||
{
|
||||
|
||||
|
||||
if (ship != null)
|
||||
{
|
||||
ship._pictureHeight = _pictureHeight;
|
||||
ship._pictureWidth = _pictureWidth;
|
||||
ship.SetPosition(((_collection._maxCount -i - 1) % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (_collection._maxCount - i-1) / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight);
|
||||
ship.DrawShip(g);
|
||||
}
|
||||
i++;
|
||||
// TODO получение объекта
|
||||
// TODO установка позиции
|
||||
// TODO прорисовка объекта
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
96
Lab1ContainersShip/Lab1ContainersShip/ShipGenericStorage.cs
Normal file
96
Lab1ContainersShip/Lab1ContainersShip/ShipGenericStorage.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using Lab1ContainersShip.DrawingObjects;
|
||||
using Lab1ContainersShip.MovementStrategy;
|
||||
|
||||
|
||||
namespace Lab1ContainersShip
|
||||
{
|
||||
internal class ShipGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, ShipGenericCollection<DrawingShip,
|
||||
DrawningObjectShip>> _shipStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _shipStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public ShipGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_shipStorages = new Dictionary<string, ShipGenericCollection<DrawingShip,
|
||||
DrawningObjectShip>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для добавления
|
||||
if (_shipStorages.ContainsKey(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_shipStorages[name] = new ShipGenericCollection<DrawingShip, DrawningObjectShip>(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_shipStorages.ContainsKey(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_shipStorages.Remove(name);
|
||||
}
|
||||
// TODO Прописать логику для удаления
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public ShipGenericCollection<DrawingShip, DrawningObjectShip>
|
||||
this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения набора
|
||||
if (_shipStorages.ContainsKey(ind))
|
||||
{
|
||||
return _shipStorages[ind];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
19
Lab1ContainersShip/Lab1ContainersShip/Status.cs
Normal file
19
Lab1ContainersShip/Lab1ContainersShip/Status.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lab1ContainersShip.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user