Compare commits

..

No commits in common. "lab5" and "main" have entirely different histories.
lab5 ... main

32 changed files with 0 additions and 2705 deletions

View File

@ -1,150 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
internal abstract class AbstractMap
{
IDrawingObject _drawingObject = null;
protected int[,] _map = null;
//ширина и высота карты
protected int _width;
protected int _height;
//ширина и высота ячейки
protected float _size_x;
protected float _size_y;
protected readonly Random _random = new();
protected readonly int _freeRoad = 0;
protected readonly int _barrier = 1;
public Bitmap CreateMap(int width, int height, IDrawingObject drawningObject)
{
_width = width;
_height = height;
_drawingObject = drawningObject;
GenerateMap();
while (!SetObjectOnMap())
{
GenerateMap();
}
return DrawMapWithObject();
}
public Bitmap MoveObject(Direction direction)
{
(float leftX, float topY, float rightX, float bottomY) = _drawingObject.GetCurrentPosition();
float boatWidth = rightX - leftX;
float boatHeight = bottomY - topY;
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
switch (direction)
{
case Direction.Up:
if (_size_y * (j + 1) >= topY - _drawingObject.Step && _size_y * (j + 1) < topY && _size_x * (i + 1) > leftX
&& _size_x * (i + 1) <= rightX)
{
return DrawMapWithObject();
}
break;
case Direction.Down:
if (_size_y * j <= bottomY + _drawingObject.Step && _size_y * j > bottomY && _size_x * (i + 1) > leftX
&& _size_x * (i + 1) <= rightX)
{
return DrawMapWithObject();
}
break;
case Direction.Left:
if (_size_x * (i + 1) >= leftX - _drawingObject.Step && _size_x * (i + 1) < leftX && _size_y * (j + 1) < bottomY
&& _size_y * (j + 1) >= topY)
{
return DrawMapWithObject();
}
break;
case Direction.Right:
if (_size_x * i <= rightX + _drawingObject.Step && _size_x * i > leftX && _size_y * (j + 1) < bottomY
&& _size_y * (j + 1) >= topY)
{
return DrawMapWithObject();
}
break;
}
}
}
}
if (true)
{
_drawingObject.MoveObject(direction);
}
return DrawMapWithObject();
}
private bool SetObjectOnMap()
{
(float leftX, float topY, float rightX, float bottomY) = _drawingObject.GetCurrentPosition();
if (_drawingObject == null || _map == null)
{
return false;
}
float boatWidth = rightX - leftX;
float boatHeight = bottomY - topY;
int x = _random.Next(0, 10);
int y = _random.Next(0, 10);
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
if (_map[i, j] == _barrier)
{
if (x + boatWidth >= _size_x * i && x <= _size_x * i && y + boatHeight > _size_y * j && y <= _size_y * j)
{
return false;
}
}
}
}
_drawingObject.SetObject(x, y, _width, _height);
return true;
}
private Bitmap DrawMapWithObject()
{
Bitmap bmp = new(_width, _height);
if (_drawingObject == null || _map == null)
{
return bmp;
}
Graphics gr = Graphics.FromImage(bmp);
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
if (_map[i, j] == _freeRoad)
{
DrawRoadPart(gr, i, j);
}
else if (_map[i, j] == _barrier)
{
DrawBarrierPart(gr, i, j);
}
}
}
_drawingObject.DrawingObject(gr);
return bmp;
}
protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
}
}

View File

@ -1,47 +0,0 @@
using System;
using System.Drawing;
namespace Sailboat
{
public class Boat
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public float Weight { get; private set; }
/// <summary>
/// Цвет кузова
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public float Step => Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса автомобиля
/// </summary>
/// <param name="speed"></param>
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <returns></returns>
public Boat(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor;
}
public void ChangeBaseColor(Color newBaseColor)
{
BodyColor = newBaseColor;
}
}
}

View File

@ -1,10 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
public delegate void BoatDelegate(DrawingBoat boat);
}

View File

@ -1,211 +0,0 @@

namespace Sailboat
{
partial class BoatForm
{
/// <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.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripLabel_speed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripLabel_weight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripLabel_color = new System.Windows.Forms.ToolStripStatusLabel();
this.pictureBoxBoat = new System.Windows.Forms.PictureBox();
this.btn_create = new System.Windows.Forms.Button();
this.btn_right = new System.Windows.Forms.Button();
this.btn_down = new System.Windows.Forms.Button();
this.btn_up = new System.Windows.Forms.Button();
this.btn_left = new System.Windows.Forms.Button();
this.btn_create_sailboat = new System.Windows.Forms.Button();
this.btn_select = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit();
this.SuspendLayout();
//
// statusStrip1
//
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripLabel_speed,
this.toolStripLabel_weight,
this.toolStripLabel_color});
this.statusStrip1.Location = new System.Drawing.Point(0, 424);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(800, 26);
this.statusStrip1.TabIndex = 0;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripLabel_speed
//
this.toolStripLabel_speed.Name = "toolStripLabel_speed";
this.toolStripLabel_speed.Size = new System.Drawing.Size(76, 20);
this.toolStripLabel_speed.Text = "Скорость:";
//
// toolStripLabel_weight
//
this.toolStripLabel_weight.Name = "toolStripLabel_weight";
this.toolStripLabel_weight.Size = new System.Drawing.Size(36, 20);
this.toolStripLabel_weight.Text = "Вес:";
//
// toolStripLabel_color
//
this.toolStripLabel_color.Name = "toolStripLabel_color";
this.toolStripLabel_color.Size = new System.Drawing.Size(45, 20);
this.toolStripLabel_color.Text = "Цвет:";
//
// pictureBoxBoat
//
this.pictureBoxBoat.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxBoat.Location = new System.Drawing.Point(0, 0);
this.pictureBoxBoat.Name = "pictureBoxBoat";
this.pictureBoxBoat.Size = new System.Drawing.Size(800, 424);
this.pictureBoxBoat.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxBoat.TabIndex = 1;
this.pictureBoxBoat.TabStop = false;
this.pictureBoxBoat.Resize += new System.EventHandler(this.btn_move_Click);
//
// btn_create
//
this.btn_create.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_create.Location = new System.Drawing.Point(13, 13);
this.btn_create.Name = "btn_create";
this.btn_create.Size = new System.Drawing.Size(94, 29);
this.btn_create.TabIndex = 2;
this.btn_create.Text = "Создать";
this.btn_create.UseVisualStyleBackColor = true;
this.btn_create.Click += new System.EventHandler(this.btn_create_Click);
//
// btn_right
//
this.btn_right.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_right.BackgroundImage = global::Sailboat.Properties.Resources.right;
this.btn_right.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btn_right.Location = new System.Drawing.Point(694, 392);
this.btn_right.Name = "btn_right";
this.btn_right.Size = new System.Drawing.Size(94, 29);
this.btn_right.TabIndex = 4;
this.btn_right.UseVisualStyleBackColor = true;
this.btn_right.Click += new System.EventHandler(this.btn_move_Click);
//
// btn_down
//
this.btn_down.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_down.BackgroundImage = global::Sailboat.Properties.Resources.down;
this.btn_down.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btn_down.Location = new System.Drawing.Point(594, 392);
this.btn_down.Name = "btn_down";
this.btn_down.Size = new System.Drawing.Size(94, 29);
this.btn_down.TabIndex = 5;
this.btn_down.UseVisualStyleBackColor = true;
this.btn_down.Click += new System.EventHandler(this.btn_move_Click);
//
// btn_up
//
this.btn_up.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_up.BackgroundImage = global::Sailboat.Properties.Resources.up;
this.btn_up.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btn_up.Location = new System.Drawing.Point(594, 357);
this.btn_up.Name = "btn_up";
this.btn_up.Size = new System.Drawing.Size(94, 29);
this.btn_up.TabIndex = 6;
this.btn_up.UseVisualStyleBackColor = true;
this.btn_up.Click += new System.EventHandler(this.btn_move_Click);
//
// btn_left
//
this.btn_left.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_left.BackgroundImage = global::Sailboat.Properties.Resources.left;
this.btn_left.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btn_left.Location = new System.Drawing.Point(494, 391);
this.btn_left.Name = "btn_left";
this.btn_left.Size = new System.Drawing.Size(94, 29);
this.btn_left.TabIndex = 7;
this.btn_left.UseVisualStyleBackColor = true;
this.btn_left.Click += new System.EventHandler(this.btn_move_Click);
//
// btn_create_sailboat
//
this.btn_create_sailboat.Location = new System.Drawing.Point(113, 13);
this.btn_create_sailboat.Name = "btn_create_sailboat";
this.btn_create_sailboat.Size = new System.Drawing.Size(150, 29);
this.btn_create_sailboat.TabIndex = 8;
this.btn_create_sailboat.Text = "Создать парусник";
this.btn_create_sailboat.UseVisualStyleBackColor = true;
this.btn_create_sailboat.Click += new System.EventHandler(this.btn_create_sailboat_Click);
//
// btn_select
//
this.btn_select.Location = new System.Drawing.Point(13, 391);
this.btn_select.Name = "btn_select";
this.btn_select.Size = new System.Drawing.Size(94, 29);
this.btn_select.TabIndex = 9;
this.btn_select.Text = "Выбрать";
this.btn_select.UseVisualStyleBackColor = true;
this.btn_select.Click += new System.EventHandler(this.btn_select_Click);
//
// BoatForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.btn_select);
this.Controls.Add(this.btn_create_sailboat);
this.Controls.Add(this.btn_left);
this.Controls.Add(this.btn_up);
this.Controls.Add(this.btn_down);
this.Controls.Add(this.btn_right);
this.Controls.Add(this.btn_create);
this.Controls.Add(this.pictureBoxBoat);
this.Controls.Add(this.statusStrip1);
this.Name = "BoatForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "BoatForm";
this.Click += new System.EventHandler(this.btn_move_Click);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripLabel_speed;
private System.Windows.Forms.ToolStripStatusLabel toolStripLabel_weight;
private System.Windows.Forms.ToolStripStatusLabel toolStripLabel_color;
private System.Windows.Forms.PictureBox pictureBoxBoat;
private System.Windows.Forms.Button btn_create;
private System.Windows.Forms.Button btn_right;
private System.Windows.Forms.Button btn_down;
private System.Windows.Forms.Button btn_up;
private System.Windows.Forms.Button btn_left;
private System.Windows.Forms.Button btn_create_sailboat;
private System.Windows.Forms.Button btn_select;
}
}

View File

@ -1,124 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sailboat
{
public partial class BoatForm : Form
{
private DrawingBoat _boat;
/// <summary>
/// Выбранный объект
/// </summary>
public DrawingBoat SelectedBoat { get; private set; }
public BoatForm()
{
InitializeComponent();
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_create_Click(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_boat = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
_boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxBoat.Width, pictureBoxBoat.Height);
SetData();
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Создать парусник"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_create_sailboat_Click(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color edgeColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
edgeColor = dialogDop.Color;
}
_boat = new DrawingSailboat(rnd.Next(100, 300), rnd.Next(1000, 2000), color, edgeColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
_boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxBoat.Width, pictureBoxBoat.Height);
SetData();
Draw();
}
/// <summary>
/// Обработка нажатия стрелок
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_move_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "btn_up":
_boat?.MoveTransport(Direction.Up);
break;
case "btn_down":
_boat?.MoveTransport(Direction.Down);
break;
case "btn_left":
_boat?.MoveTransport(Direction.Left);
break;
case "btn_right":
_boat?.MoveTransport(Direction.Right);
break;
}
Draw();
}
/// <summary>
/// Метод прорисовки машины
/// </summary>
private void Draw()
{
Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height);
Graphics gr = Graphics.FromImage(bmp);
_boat?.DrawTransport(gr);
pictureBoxBoat.Image = bmp;
}
/// <summary>
/// Метод прорисовки машины
/// </summary>
private void SetData()
{
Random rnd = new();
toolStripLabel_color.Text = $"Скорость: {_boat.Boat.Speed}";
toolStripLabel_weight.Text = $"Вес: {_boat.Boat.Weight}";
toolStripLabel_color.Text = $"Цвет: { _boat.Boat.BodyColor.Name}";
}
private void btn_select_Click(object sender, EventArgs e)
{
SelectedBoat = _boat;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -1,63 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
/// <summary>
/// Направление перемещения
/// </summary>
public enum Direction
{
None = 0,
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -1,177 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawingBoat
{
/// <summary>
/// Класс-сущность
/// </summary>
public Boat Boat{ protected set; get; }
/// <summary>`
/// Левая координата отрисовки автомобиля
/// </summary>
protected float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки автомобиля
/// </summary>
protected float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private int? _pictureWidth = null;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private int? _pictureHeight = null;
/// <summary>
/// Ширина отрисовки автомобиля
/// </summary>
private readonly int _boatWidth = 125;
/// <summary>
/// Высота отрисовки автомобиля
/// </summary>
private readonly int _boatHeight = 40;
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
public DrawingBoat(int speed, float weight, Color bodyColor)
{
Boat = new Boat(speed, weight, bodyColor);
}
public DrawingBoat(int speed, float weight, Color bodyColor, int boatHeight, int boatWith):
this(speed, weight, bodyColor)
{
_boatHeight = boatHeight;
_boatWidth = boatWith;
}
/// <summary>
/// Установка позиции автомобиля
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public void SetPosition(int x, int y, int width, int height)
{
if (x >= 0 && y >= 0 && x < width - _boatWidth && y < height - _boatHeight)
{
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(Direction direction)
{
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
{
return;
}
switch (direction)
{
// вправо
case Direction.Right:
if (_startPosX + _boatWidth + ((int)Boat.Step) < _pictureWidth)
{
_startPosX += ((int)Boat.Step);
}
break;
//влево
case Direction.Left:
if (_startPosX > ((int)Boat.Step))
{
_startPosX -= ((int)Boat.Step);
}
break;
//вверх
case Direction.Up:
if (_startPosY > ((int)Boat.Step))
{
_startPosY -= ((int)Boat.Step);
}
break;
//вниз
case Direction.Down:
if (_startPosY + _boatHeight + ((int)Boat.Step) < _pictureHeight)
{
_startPosY += ((int)Boat.Step);
}
break;
}
}
/// <summary>
/// Отрисовка лодки
/// </summary>
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
Pen pen = new(Color.Black);
//корма
g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 70, _startPosY);
g.DrawLine(pen, _startPosX, _startPosY, _startPosX, _startPosY+40);
g.DrawLine(pen, _startPosX, _startPosY + 40, _startPosX + 70, _startPosY+40);
//нос
g.DrawLine(pen, _startPosX + 70, _startPosY + 40, _startPosX + 120, _startPosY+20);
g.DrawLine(pen, _startPosX + 70, _startPosY, _startPosX + 120, _startPosY+20);
//внутренность
Rectangle rect = new Rectangle((int)_startPosX + 5, (int)_startPosY + 5, 60, 30);
g.DrawRectangle(pen, rect);
Brush br = new SolidBrush(Boat.BodyColor);
g.FillRectangle(br, rect);
}
/// <summary>
/// Смена границ формы отрисовки
/// </summary>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _boatWidth || _pictureHeight <= _boatHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _boatWidth > _pictureWidth)
{
_startPosX = _pictureWidth.Value - _boatWidth;
}
if (_startPosY + _boatHeight > _pictureHeight)
{
_startPosY = _pictureHeight.Value - _boatHeight;
}
}
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _boatWidth, _startPosY + _boatHeight);
}
}
}

View File

@ -1,40 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
class DrawingObjectBoat : IDrawingObject
{
private DrawingBoat _boat;
public DrawingObjectBoat(DrawingBoat boat)
{
_boat = boat;
}
public float Step => _boat?.Boat?.Step ?? 0;
public void DrawingObject(Graphics g)
{
_boat.DrawTransport(g);
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _boat?.GetCurrentPosition() ?? default;
}
void IDrawingObject.MoveObject(Direction direction)
{
_boat?.MoveTransport(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_boat.SetPosition(x, y, width, height);
}
}
}

View File

@ -1,63 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
class DrawingSailboat : DrawingBoat
{
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="sail">Признак наличия паруса</param>
/// <param name="extendedBody">Признак наличия усиленного корпуса</param>
public DrawingSailboat(int speed, float weight, Color bodyColor, Color edgeColor, bool sail, bool extendedBody) :
base(speed, weight, bodyColor, 80, 135)
{
Boat = new Sailboat(speed, weight, bodyColor, edgeColor, sail, extendedBody);
}
public override void DrawTransport(Graphics g)
{
if (Boat is not Sailboat sailboat)
{
return;
}
Pen pen = new(Color.Black);
Brush brush = new SolidBrush(sailboat.EdgeColor);
_startPosY += 40;
_startPosX += 20;
base.DrawTransport(g);
_startPosY -= 40;
_startPosX -= 20;
if (sailboat.Sail)
{
g.DrawLine(pen, _startPosX + 40, _startPosY, _startPosX + 60, _startPosY + 60);
g.DrawLine(pen, _startPosX + 40, _startPosY, _startPosX + 70, _startPosY + 30);
g.DrawLine(pen, _startPosX + 70, _startPosY + 30, _startPosX + 60, _startPosY + 55);
}
if (sailboat.ExtendedBody)
{
//корма
g.FillRectangle(brush, _startPosX + 15, _startPosY + 38, 70, 5);
g.FillRectangle(brush, _startPosX + 15, _startPosY + 78, 70, 5);
g.FillRectangle(brush, _startPosX + 15, _startPosY + 38, 5, 40);
//усиленный нос
g.FillRectangle(brush, _startPosX + 133, _startPosY + 55, 10, 10);
}
}
}
}

View File

@ -1,353 +0,0 @@

namespace Sailboat
{
partial class FormBoatConfig
{
/// <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.labelSailboat = new System.Windows.Forms.Label();
this.labelBoat = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.checkBoxSail = new System.Windows.Forms.CheckBox();
this.checkBoxExtendedBody = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.labelWeight = new System.Windows.Forms.Label();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelSpeed = new System.Windows.Forms.Label();
this.panelObject = new System.Windows.Forms.Panel();
this.labelDopColor = new System.Windows.Forms.Label();
this.labelBaseColor = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOK = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.panelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.labelSailboat);
this.groupBox1.Controls.Add(this.labelBoat);
this.groupBox1.Controls.Add(this.groupBoxColors);
this.groupBox1.Controls.Add(this.checkBoxSail);
this.groupBox1.Controls.Add(this.checkBoxExtendedBody);
this.groupBox1.Controls.Add(this.numericUpDownWeight);
this.groupBox1.Controls.Add(this.labelWeight);
this.groupBox1.Controls.Add(this.numericUpDownSpeed);
this.groupBox1.Controls.Add(this.labelSpeed);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(645, 262);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Параметры";
//
// labelSailboat
//
this.labelSailboat.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSailboat.Location = new System.Drawing.Point(512, 190);
this.labelSailboat.Name = "labelSailboat";
this.labelSailboat.Size = new System.Drawing.Size(117, 53);
this.labelSailboat.TabIndex = 8;
this.labelSailboat.Text = "Продвинутый";
this.labelSailboat.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSailboat.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
//
// labelBoat
//
this.labelBoat.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelBoat.Location = new System.Drawing.Point(379, 190);
this.labelBoat.Name = "labelBoat";
this.labelBoat.Size = new System.Drawing.Size(106, 53);
this.labelBoat.TabIndex = 7;
this.labelBoat.Text = "Простой";
this.labelBoat.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBoat.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.panelPurple);
this.groupBoxColors.Controls.Add(this.panelBlack);
this.groupBoxColors.Controls.Add(this.panelGray);
this.groupBoxColors.Controls.Add(this.panelYellow);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelWhite);
this.groupBoxColors.Location = new System.Drawing.Point(379, 27);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(250, 150);
this.groupBoxColors.TabIndex = 6;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(175, 83);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(50, 50);
this.panelPurple.TabIndex = 6;
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(119, 83);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(50, 50);
this.panelBlack.TabIndex = 5;
//
// panelGray
//
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(63, 83);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(50, 50);
this.panelGray.TabIndex = 1;
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(175, 27);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(50, 50);
this.panelYellow.TabIndex = 4;
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(119, 26);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(50, 50);
this.panelBlue.TabIndex = 3;
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(7, 27);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(50, 50);
this.panelRed.TabIndex = 2;
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(63, 26);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(50, 50);
this.panelGreen.TabIndex = 1;
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(7, 83);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(50, 50);
this.panelWhite.TabIndex = 0;
//
// checkBoxSail
//
this.checkBoxSail.AutoSize = true;
this.checkBoxSail.Location = new System.Drawing.Point(21, 190);
this.checkBoxSail.Name = "checkBoxSail";
this.checkBoxSail.Size = new System.Drawing.Size(206, 24);
this.checkBoxSail.TabIndex = 5;
this.checkBoxSail.Text = "Признак наличия паруса";
this.checkBoxSail.UseVisualStyleBackColor = true;
//
// checkBoxExtendedBody
//
this.checkBoxExtendedBody.AutoSize = true;
this.checkBoxExtendedBody.Location = new System.Drawing.Point(21, 143);
this.checkBoxExtendedBody.Name = "checkBoxExtendedBody";
this.checkBoxExtendedBody.Size = new System.Drawing.Size(283, 24);
this.checkBoxExtendedBody.TabIndex = 4;
this.checkBoxExtendedBody.Text = "Признак наличия усиления корпуса";
this.checkBoxExtendedBody.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(113, 93);
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(150, 27);
this.numericUpDownWeight.TabIndex = 3;
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(21, 95);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(33, 20);
this.labelWeight.TabIndex = 2;
this.labelWeight.Text = "Вес";
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(113, 40);
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(150, 27);
this.numericUpDownSpeed.TabIndex = 1;
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(21, 40);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(73, 20);
this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = "Скорость";
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.labelDopColor);
this.panelObject.Controls.Add(this.labelBaseColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(663, 23);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(305, 203);
this.panelObject.TabIndex = 2;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter);
//
// labelDopColor
//
this.labelDopColor.AllowDrop = true;
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelDopColor.Location = new System.Drawing.Point(168, 12);
this.labelDopColor.Name = "labelDopColor";
this.labelDopColor.Size = new System.Drawing.Size(106, 50);
this.labelDopColor.TabIndex = 9;
this.labelDopColor.Text = "Доп. цвет";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelBaseColor_DragEnter);
//
// labelBaseColor
//
this.labelBaseColor.AllowDrop = true;
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelBaseColor.Location = new System.Drawing.Point(27, 12);
this.labelBaseColor.Name = "labelBaseColor";
this.labelBaseColor.Size = new System.Drawing.Size(106, 50);
this.labelBaseColor.TabIndex = 8;
this.labelBaseColor.Text = "Цвет";
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelBaseColor_DragEnter);
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(16, 68);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(271, 118);
this.pictureBoxObject.TabIndex = 0;
this.pictureBoxObject.TabStop = false;
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(664, 233);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(141, 29);
this.buttonCancel.TabIndex = 3;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonOK
//
this.buttonOK.Location = new System.Drawing.Point(831, 233);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(137, 29);
this.buttonOK.TabIndex = 4;
this.buttonOK.Text = "ОК";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
//
// FormBoatConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1255, 313);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBox1);
this.Name = "FormBoatConfig";
this.Text = "Создание объекта";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.panelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.CheckBox checkBoxSail;
private System.Windows.Forms.CheckBox checkBoxExtendedBody;
private System.Windows.Forms.NumericUpDown numericUpDownWeight;
private System.Windows.Forms.Label labelWeight;
private System.Windows.Forms.NumericUpDown numericUpDownSpeed;
private System.Windows.Forms.Label labelSpeed;
private System.Windows.Forms.GroupBox groupBoxColors;
private System.Windows.Forms.Panel panelBlack;
private System.Windows.Forms.Panel panelGray;
private System.Windows.Forms.Panel panelYellow;
private System.Windows.Forms.Panel panelBlue;
private System.Windows.Forms.Panel panelRed;
private System.Windows.Forms.Panel panelGreen;
private System.Windows.Forms.Panel panelWhite;
private System.Windows.Forms.Panel panelPurple;
private System.Windows.Forms.Label labelSailboat;
private System.Windows.Forms.Label labelBoat;
private System.Windows.Forms.Panel panelObject;
private System.Windows.Forms.Label labelDopColor;
private System.Windows.Forms.Label labelBaseColor;
private System.Windows.Forms.PictureBox pictureBoxObject;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Button buttonOK;
}
}

View File

@ -1,118 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sailboat
{
public partial class FormBoatConfig : Form
{
DrawingBoat _boat = null;
private event BoatDelegate EventAddBoat;
public FormBoatConfig()
{
InitializeComponent();
panelBlack.MouseDown += panelColor_MouseDown;
panelWhite.MouseDown += panelColor_MouseDown;
panelGreen.MouseDown += panelColor_MouseDown;
panelYellow.MouseDown += panelColor_MouseDown;
panelRed.MouseDown += panelColor_MouseDown;
panelBlue.MouseDown += panelColor_MouseDown;
panelPurple.MouseDown += panelColor_MouseDown;
panelGray.MouseDown += panelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
public void AddEvent(BoatDelegate ev)
{
if (EventAddBoat == null)
{
EventAddBoat = new BoatDelegate(ev);
}
else
{
EventAddBoat += ev;
}
}
private void DrawBoat()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_boat?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_boat?.DrawTransport(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))
{
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 "labelBoat":
_boat = new DrawingBoat((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
break;
case "labelSailboat":
_boat = new DrawingSailboat((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxSail.Checked, checkBoxExtendedBody.Checked);
break;
}
DrawBoat();
}
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
_boat?.Boat.ChangeBaseColor((Color)e.Data.GetData(typeof(Color)));
DrawBoat();
}
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
if (_boat?.Boat is Sailboat sailboat)
{
sailboat.ChangeDopColor((Color)e.Data.GetData(typeof(Color)));
DrawBoat();
}
}
private void buttonOK_Click(object sender, EventArgs e)
{
EventAddBoat?.Invoke(_boat);
Close();
}
private void labelBaseColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void panelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
}
}

View File

@ -1,60 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,279 +0,0 @@

namespace Sailboat
{
partial class FormMapWithSetBoats
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.btn_delete_map = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.btn_add_map = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxMapSelector = new System.Windows.Forms.ComboBox();
this.btn_left = new System.Windows.Forms.Button();
this.btn_up = new System.Windows.Forms.Button();
this.btn_down = new System.Windows.Forms.Button();
this.btn_right = new System.Windows.Forms.Button();
this.btn_show_map = new System.Windows.Forms.Button();
this.btn_show_storage = new System.Windows.Forms.Button();
this.btn_remove_boat = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.btn_add_boat = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBoxTools
//
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.btn_left);
this.groupBoxTools.Controls.Add(this.btn_up);
this.groupBoxTools.Controls.Add(this.btn_down);
this.groupBoxTools.Controls.Add(this.btn_right);
this.groupBoxTools.Controls.Add(this.btn_show_map);
this.groupBoxTools.Controls.Add(this.btn_show_storage);
this.groupBoxTools.Controls.Add(this.btn_remove_boat);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.btn_add_boat);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(707, 0);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(250, 609);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты";
//
// groupBoxMaps
//
this.groupBoxMaps.Controls.Add(this.btn_delete_map);
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.btn_add_map);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Controls.Add(this.comboBoxMapSelector);
this.groupBoxMaps.Location = new System.Drawing.Point(3, 23);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Size = new System.Drawing.Size(247, 276);
this.groupBoxMaps.TabIndex = 12;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты";
//
// btn_delete_map
//
this.btn_delete_map.Location = new System.Drawing.Point(3, 241);
this.btn_delete_map.Name = "btn_delete_map";
this.btn_delete_map.Size = new System.Drawing.Size(232, 29);
this.btn_delete_map.TabIndex = 4;
this.btn_delete_map.Text = "Удалить карту";
this.btn_delete_map.UseVisualStyleBackColor = true;
this.btn_delete_map.Click += new System.EventHandler(this.btn_delete_map_Click);
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 20;
this.listBoxMaps.Location = new System.Drawing.Point(0, 125);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(235, 104);
this.listBoxMaps.TabIndex = 3;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// btn_add_map
//
this.btn_add_map.Location = new System.Drawing.Point(3, 90);
this.btn_add_map.Name = "btn_add_map";
this.btn_add_map.Size = new System.Drawing.Size(232, 29);
this.btn_add_map.TabIndex = 2;
this.btn_add_map.Text = "Добавить карту";
this.btn_add_map.UseVisualStyleBackColor = true;
this.btn_add_map.Click += new System.EventHandler(this.btn_add_map_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(3, 23);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(232, 27);
this.textBoxNewMapName.TabIndex = 0;
//
// comboBoxMapSelector
//
this.comboBoxMapSelector.FormattingEnabled = true;
this.comboBoxMapSelector.Items.AddRange(new object[] {
"Простая карта",
"Водная карта"});
this.comboBoxMapSelector.Location = new System.Drawing.Point(3, 56);
this.comboBoxMapSelector.Name = "comboBoxMapSelector";
this.comboBoxMapSelector.Size = new System.Drawing.Size(232, 28);
this.comboBoxMapSelector.TabIndex = 1;
//
// btn_left
//
this.btn_left.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_left.BackgroundImage = global::Sailboat.Properties.Resources.left;
this.btn_left.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btn_left.Location = new System.Drawing.Point(19, 552);
this.btn_left.Name = "btn_left";
this.btn_left.Size = new System.Drawing.Size(70, 40);
this.btn_left.TabIndex = 11;
this.btn_left.UseVisualStyleBackColor = true;
this.btn_left.Click += new System.EventHandler(this.btn_move_Click);
//
// btn_up
//
this.btn_up.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_up.BackgroundImage = global::Sailboat.Properties.Resources.up;
this.btn_up.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btn_up.Location = new System.Drawing.Point(95, 506);
this.btn_up.Name = "btn_up";
this.btn_up.Size = new System.Drawing.Size(75, 40);
this.btn_up.TabIndex = 10;
this.btn_up.UseVisualStyleBackColor = true;
this.btn_up.Click += new System.EventHandler(this.btn_move_Click);
//
// btn_down
//
this.btn_down.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_down.BackgroundImage = global::Sailboat.Properties.Resources.down;
this.btn_down.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btn_down.Location = new System.Drawing.Point(95, 552);
this.btn_down.Name = "btn_down";
this.btn_down.Size = new System.Drawing.Size(75, 40);
this.btn_down.TabIndex = 9;
this.btn_down.UseVisualStyleBackColor = true;
this.btn_down.Click += new System.EventHandler(this.btn_move_Click);
//
// btn_right
//
this.btn_right.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_right.BackgroundImage = global::Sailboat.Properties.Resources.right;
this.btn_right.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btn_right.Location = new System.Drawing.Point(174, 552);
this.btn_right.Name = "btn_right";
this.btn_right.Size = new System.Drawing.Size(70, 40);
this.btn_right.TabIndex = 8;
this.btn_right.UseVisualStyleBackColor = true;
this.btn_right.Click += new System.EventHandler(this.btn_move_Click);
//
// btn_show_map
//
this.btn_show_map.Location = new System.Drawing.Point(6, 471);
this.btn_show_map.Name = "btn_show_map";
this.btn_show_map.Size = new System.Drawing.Size(232, 29);
this.btn_show_map.TabIndex = 6;
this.btn_show_map.Text = "Посмотреть карту";
this.btn_show_map.UseVisualStyleBackColor = true;
this.btn_show_map.Click += new System.EventHandler(this.btn_show_map_Click);
//
// btn_show_storage
//
this.btn_show_storage.Location = new System.Drawing.Point(6, 436);
this.btn_show_storage.Name = "btn_show_storage";
this.btn_show_storage.Size = new System.Drawing.Size(232, 29);
this.btn_show_storage.TabIndex = 5;
this.btn_show_storage.Text = "Посмотреть хранилище";
this.btn_show_storage.UseVisualStyleBackColor = true;
this.btn_show_storage.Click += new System.EventHandler(this.btn_show_storage_Click);
//
// btn_remove_boat
//
this.btn_remove_boat.Location = new System.Drawing.Point(6, 391);
this.btn_remove_boat.Name = "btn_remove_boat";
this.btn_remove_boat.Size = new System.Drawing.Size(232, 29);
this.btn_remove_boat.TabIndex = 4;
this.btn_remove_boat.Text = "Удалить лодку";
this.btn_remove_boat.UseVisualStyleBackColor = true;
this.btn_remove_boat.Click += new System.EventHandler(this.btn_remove_boat_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 358);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(232, 27);
this.maskedTextBoxPosition.TabIndex = 3;
//
// btn_add_boat
//
this.btn_add_boat.Location = new System.Drawing.Point(6, 305);
this.btn_add_boat.Name = "btn_add_boat";
this.btn_add_boat.Size = new System.Drawing.Size(232, 29);
this.btn_add_boat.TabIndex = 2;
this.btn_add_boat.Text = "Добавить лодку";
this.btn_add_boat.UseVisualStyleBackColor = true;
this.btn_add_boat.Click += new System.EventHandler(this.btn_add_boat_Click);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(707, 609);
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
//
// FormMapWithSetBoats
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(957, 609);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetBoats";
this.Text = "FormMapWithSetBoats";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBoxTools;
private System.Windows.Forms.Button btn_show_map;
private System.Windows.Forms.Button btn_show_storage;
private System.Windows.Forms.Button btn_remove_boat;
private System.Windows.Forms.MaskedTextBox maskedTextBoxPosition;
private System.Windows.Forms.Button btn_add_boat;
private System.Windows.Forms.ComboBox comboBoxMapSelector;
private System.Windows.Forms.PictureBox pictureBox;
private System.Windows.Forms.Button btn_left;
private System.Windows.Forms.Button btn_up;
private System.Windows.Forms.Button btn_down;
private System.Windows.Forms.Button btn_right;
private System.Windows.Forms.GroupBox groupBoxMaps;
private System.Windows.Forms.TextBox textBoxNewMapName;
private System.Windows.Forms.Button btn_delete_map;
private System.Windows.Forms.ListBox listBoxMaps;
private System.Windows.Forms.Button btn_add_map;
}
}

View File

@ -1,177 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sailboat
{
public partial class FormMapWithSetBoats : Form
{
private readonly Dictionary<string, AbstractMap> _mapsDict = new Dictionary<string, AbstractMap>() {
{ "Простая карта", new SimpleMap() },
{ "Водная карта", new WaterMap() }
};
private readonly MapsCollection _mapsCollection;
public FormMapWithSetBoats()
{
InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxMapSelector.Items.Clear();
foreach (var item in _mapsDict)
{
comboBoxMapSelector.Items.Add(item.Key);
}
}
private void ReloadMaps()
{
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
}
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{
listBoxMaps.SelectedIndex = index;
}
}
private void btn_add_boat_Click(object sender, EventArgs e)
{
var formBoatConfig = new FormBoatConfig();
formBoatConfig.AddEvent(InsertBoatCheck);
formBoatConfig.Show();
}
private void btn_remove_boat_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void btn_show_storage_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void btn_show_map_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
private void btn_move_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "btn_up":
dir = Direction.Up;
break;
case "btn_down":
dir = Direction.Down;
break;
case "btn_left":
dir = Direction.Left;
break;
case "btn_right":
dir = Direction.Right;
break;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
private void btn_add_map_Click(object sender, EventArgs e)
{
if (comboBoxMapSelector.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapsDict.ContainsKey(comboBoxMapSelector.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxMapSelector.Text]);
ReloadMaps();
}
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void btn_delete_map_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
private void InsertBoatCheck(DrawingBoat _boat)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
DrawingObjectBoat boat = new(_boat);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat >= 0)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
}

View File

@ -1,60 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,41 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
interface IDrawingObject
{
/// <summary>
/// Шаг перемещения объекта
/// </summary>
public float Step { get; }
/// <summary>
/// Установка позиции объекта
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина полотна</param>
/// <param name="height">Высота полотна</param>
void SetObject(int x, int y, int width, int height);
/// <summary>
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
/// <returns></returns>
void MoveObject(Direction direction);
/// <summary>
/// Отрисовка объекта
/// </summary>
/// <param name="g"></param>
void DrawingObject(Graphics g);
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
}
}

View File

@ -1,136 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
class MapWithSetBoatsGeneric<T, U> where T : class, IDrawingObject
where U : AbstractMap
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeHeight = 90;
private readonly SetBoatsGeneric<T> _setBoats;
private readonly U _map;
public MapWithSetBoatsGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setBoats = new SetBoatsGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
public static int operator +(MapWithSetBoatsGeneric<T, U> map, T boat)
{
return map._setBoats.Insert(boat);
}
public static T operator -(MapWithSetBoatsGeneric<T, U> map, int position)
{
return map._setBoats.Remove(position);
}
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawBoats(gr);
return bmp;
}
public Bitmap ShowOnMap()
{
Shaking();
foreach (var bus in _setBoats.GetBoats())
{
return _map.CreateMap(_pictureWidth, _pictureHeight, bus);
}
return new(_pictureWidth, _pictureHeight);
}
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new(_pictureWidth, _pictureHeight);
}
private void Shaking()
{
int j = _setBoats.Count - 1;
for (int i = 0; i < _setBoats.Count; i++)
{
if (_setBoats[i] == null)
{
for (; j > i; j--)
{
var boat = _setBoats[j];
if (boat != null)
{
_setBoats.Insert(boat, i);
_setBoats.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Brown, 3);
g.FillRectangle(Brushes.Aqua, 0, 0, _pictureWidth, _pictureHeight);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
private void DrawBoats(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int currentWidth = 0;
int currentHeight = 0;
foreach (var boat in _setBoats.GetBoats())
{
boat?.SetObject(currentWidth * _placeSizeWidth,
currentHeight * _placeSizeHeight,
_pictureWidth, _pictureHeight);
boat?.DrawingObject(g);
if (currentWidth < width - 1)
{
currentWidth++;
}
else
{
currentHeight++;
currentWidth = 0;
}
if (currentHeight > height) return;
}
}
}
}

View File

@ -1,46 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
internal class MapsCollection
{
readonly Dictionary<string, MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap>> _mapStorages;
public List<string> Keys => _mapStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddMap(string name, AbstractMap map)
{
if (Keys.Contains(name)) return;
_mapStorages.Add(name, new MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
public void DelMap(string name)
{
_mapStorages.Remove(name);
}
public MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap> this[string ind]
{
get
{
_mapStorages.TryGetValue(ind, out var result);
return result;
}
}
}
}

View File

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sailboat
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMapWithSetBoats());
}
}
}

View File

@ -1,103 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Sailboat.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.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("Sailboat.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 down {
get {
object obj = ResourceManager.GetObject("down", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap left {
get {
object obj = ResourceManager.GetObject("left", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap up {
get {
object obj = ResourceManager.GetObject("up", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap right {
get {
object obj = ResourceManager.GetObject("right", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -1,133 +0,0 @@
<?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="left" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="down" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="right" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -1,42 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
internal class Sailboat : Boat
{
/// <summary>
/// Признак наличия усиленного корпуса
/// </summary>
public bool ExtendedBody { get; private set; }
/// <summary>
/// Признак наличия паруса
/// </summary>
public bool Sail { get; private set; }
public Color EdgeColor { get; private set; }
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="sail">Признак наличия паруса</param>
/// <param name="extendedBody">Признак наличия усиленного корпуса</param>
public Sailboat(int speed, float weight, Color bodyColor, Color edgeColor, bool sail, bool extendedBody) :
base(speed, weight, bodyColor)
{
EdgeColor = edgeColor;
Sail = sail;
ExtendedBody = extendedBody;
}
public void ChangeDopColor(Color newEdgeColor)
{
EdgeColor = newEdgeColor;
}
}
}

View File

@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>

View File

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31911.196
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sailboat", "Sailboat.csproj", "{D137904C-BFCA-4389-B485-24E34C8B861A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D137904C-BFCA-4389-B485-24E34C8B861A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D137904C-BFCA-4389-B485-24E34C8B861A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D137904C-BFCA-4389-B485-24E34C8B861A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D137904C-BFCA-4389-B485-24E34C8B861A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EA90E930-2691-4BB1-A346-74B5662B0250}
EndGlobalSection
EndGlobal

View File

@ -1,81 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
class SetBoatsGeneric<T> where T : class
{
private readonly List<T> _places;
public int Count => _places.Count;
private readonly int _maxCount;
private int BusyPlaces = 0;
public SetBoatsGeneric(int count)
{
_maxCount = count;
_places = new List<T>();
}
public int Insert(T boat)
{
return Insert(boat, 0);
}
public int Insert(T boat, int position)
{
if (position < 0 || position >= _maxCount || BusyPlaces == _maxCount)
{
return -1;
}
BusyPlaces++;
_places.Insert(position, boat);
return position;
}
public T Remove(int position)
{
if (position < 0 || position >= _maxCount)
{
return null;
}
BusyPlaces--;
T boat = _places[position];
_places.RemoveAt(position);
return boat;
}
public T this[int position]
{
get
{
if (position < 0 || position >= _maxCount) return null;
return _places[position];
}
set
{
Insert(value, position);
}
}
public IEnumerable<T> GetBoats()
{
foreach (var boat in _places)
{
if (boat != null)
{
yield return boat;
}
else
{
yield break;
}
}
}
}
}

View File

@ -1,57 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
/// <summary>
/// Простая реализация абсрактного класса AbstractMap
/// </summary>
internal class SimpleMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Black);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.Gray);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void GenerateMap()
{
_map = new int[100, 100];
_size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1);
int counter = 0;
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
_map[i, j] = _freeRoad;
}
}
while (counter < 50)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
}
}
}
}

View File

@ -1,56 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
internal class WaterMap : AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.Black);
private readonly Brush wavesColor = new SolidBrush(Color.Blue);
private readonly Brush deepColor = new SolidBrush(Color.DarkBlue);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
Random rnd = new Random();
if (rnd.Next(0, 7) == 6)
{
g.FillRectangle(wavesColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
else
{
g.FillRectangle(deepColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
}
protected override void GenerateMap()
{
_map = new int[100, 100];
_size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1);
int counter = 0;
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
_map[i, j] = _freeRoad;
}
}
while (counter < 50)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
}
}
}
}