Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
756f0c10b9 | ||
|
|
bad8d47c56 | ||
|
|
bd494d4f70 | ||
|
|
2f8114f6f8 |
@@ -1,128 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectBoat_bae
|
|
||||||
{
|
|
||||||
public class Drawing
|
|
||||||
{
|
|
||||||
|
|
||||||
// Класс-сущность
|
|
||||||
public ProjectBoat_bae? Boat { get; private set; }
|
|
||||||
|
|
||||||
// Ширина окна
|
|
||||||
private int? _pictureWidth = null;
|
|
||||||
|
|
||||||
// Высота окна
|
|
||||||
private int? _pictureHeight = null;
|
|
||||||
private int _startPosX;
|
|
||||||
private int _startPosY;
|
|
||||||
private readonly int _BoatWidth = 110;
|
|
||||||
private readonly int _BoatHeight = 60;
|
|
||||||
|
|
||||||
public bool Init(int speed, double weight, Color bodyColor, Color
|
|
||||||
additionalColor, bool body,
|
|
||||||
int width, int height)
|
|
||||||
{
|
|
||||||
if (width >= _BoatWidth || height >= _BoatHeight)
|
|
||||||
{
|
|
||||||
_pictureWidth = width;
|
|
||||||
_pictureHeight = height;
|
|
||||||
Boat = new ProjectBoat_bae();
|
|
||||||
Boat.Init(speed,weight, bodyColor, additionalColor,body );
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Установка позиции(запоминаем значение)
|
|
||||||
public void SetPosition(int x, int y)
|
|
||||||
{
|
|
||||||
if (x < 0 || x + _BoatWidth > _pictureWidth)
|
|
||||||
{
|
|
||||||
x = 0;
|
|
||||||
}
|
|
||||||
if (y < 0 || y + _BoatHeight > _pictureHeight)
|
|
||||||
{
|
|
||||||
y = 0;
|
|
||||||
}
|
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Изменение направления перемещения
|
|
||||||
public void MoveTransport(DiretionType direction)
|
|
||||||
{
|
|
||||||
if (Boat == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (direction)
|
|
||||||
{
|
|
||||||
//влево
|
|
||||||
case DiretionType.Left:
|
|
||||||
if (_startPosX - Boat.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosX -= (int)Boat.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вверх
|
|
||||||
case DiretionType.Up:
|
|
||||||
if (_startPosY - Boat.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosY -= (int)Boat.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
// вправо
|
|
||||||
case DiretionType.Right:
|
|
||||||
if (_startPosX + _BoatWidth + Boat.Step < _pictureWidth)
|
|
||||||
{
|
|
||||||
_startPosX += (int)Boat.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вниз
|
|
||||||
case DiretionType.Down:
|
|
||||||
if (_startPosY + _BoatHeight + Boat.Step < _pictureHeight)
|
|
||||||
{
|
|
||||||
_startPosY += (int)Boat.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Прорисовка объекта
|
|
||||||
public void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if (Boat == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Pen pen = new(Color.Black);
|
|
||||||
Brush additionalBrush = new
|
|
||||||
SolidBrush(Boat.AdditionalColor);
|
|
||||||
|
|
||||||
// корпус лодки
|
|
||||||
|
|
||||||
if (Boat.body)
|
|
||||||
{
|
|
||||||
//корпус
|
|
||||||
Brush br = new SolidBrush(Boat.BodyColor);
|
|
||||||
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
|
|
||||||
|
|
||||||
//мотор
|
|
||||||
Brush brRed = new SolidBrush(Boat.BodyColor);
|
|
||||||
g.FillEllipse(brRed, _startPosX + 7, _startPosY + 12, 35, 35);
|
|
||||||
|
|
||||||
|
|
||||||
//стекла
|
|
||||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
|
||||||
g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 10, 5,
|
|
||||||
40);
|
|
||||||
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 8, 35, 2);
|
|
||||||
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 51, 35, 2);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
167
ProjectBoat_bae/ProjectBoat_bae/DrawningObjects/DrawningBoat.cs
Normal file
167
ProjectBoat_bae/ProjectBoat_bae/DrawningObjects/DrawningBoat.cs
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using ProjectBoat_bae;
|
||||||
|
using ProjectBoat_bae.Entities;
|
||||||
|
using ProjectBoat_bae.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.DrawningObjects
|
||||||
|
{
|
||||||
|
public class Drawningboat
|
||||||
|
{
|
||||||
|
// Получение объекта IMoveableObject из объекта DrawningCar
|
||||||
|
public IMoveableObject GetMoveableObject => new
|
||||||
|
DrawningObjectBoat(this);
|
||||||
|
|
||||||
|
// Класс-сущность
|
||||||
|
public EntityBoat? EntityBoat { get; protected set; }
|
||||||
|
|
||||||
|
// Ширина окна
|
||||||
|
private int _pictureWidth;
|
||||||
|
|
||||||
|
// Высота окна
|
||||||
|
private int _pictureHeight;
|
||||||
|
|
||||||
|
// Левая координата прорисовки
|
||||||
|
protected int _startPosX;
|
||||||
|
|
||||||
|
// Верхняя кооридната прорисовки
|
||||||
|
protected int _startPosY;
|
||||||
|
|
||||||
|
// Ширина прорисовки
|
||||||
|
protected readonly int _boatWidth = 80;
|
||||||
|
|
||||||
|
// Высота прорисовки
|
||||||
|
protected readonly int _boatHeight = 50;
|
||||||
|
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
public int GetWidth => _boatWidth;
|
||||||
|
public int GetHeight => _boatHeight;
|
||||||
|
|
||||||
|
// Конструктор
|
||||||
|
public Drawningboat(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height)
|
||||||
|
{
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
if (width < _pictureWidth || height < _pictureHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EntityBoat = new EntityBoat(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Drawningboat(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height, int boatWidth, int boatHeight)
|
||||||
|
{
|
||||||
|
if (width < _boatWidth || height < _boatHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_boatWidth = boatWidth;
|
||||||
|
_boatHeight = boatHeight;
|
||||||
|
EntityBoat = new EntityBoat(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Установка позиции
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
_startPosX = Math.Min(x, _pictureWidth - _boatWidth);
|
||||||
|
_startPosY = Math.Min(y, _pictureHeight - _boatHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Прорисовка объекта
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityBoat == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
//корпус
|
||||||
|
Brush br = new SolidBrush(EntityBoat.BodyColor);
|
||||||
|
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
|
||||||
|
|
||||||
|
//мотор
|
||||||
|
Brush brRed = new SolidBrush(EntityBoat.BodyColor);
|
||||||
|
g.FillEllipse(brRed, _startPosX + 7, _startPosY + 12, 35, 35);
|
||||||
|
|
||||||
|
//стекла
|
||||||
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||||
|
g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 10, 5,
|
||||||
|
40);
|
||||||
|
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 8, 35, 2);
|
||||||
|
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 51, 35, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка, что объект может переместится по указанному направлению
|
||||||
|
public bool CanMove(DiretionType direction)
|
||||||
|
{
|
||||||
|
if (EntityBoat == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
DiretionType.Left => _startPosX - EntityBoat.Step > 0,
|
||||||
|
//вверх
|
||||||
|
DiretionType.Up => _startPosY - EntityBoat.Step > 0,
|
||||||
|
// вправо
|
||||||
|
DiretionType.Right => _startPosX + EntityBoat.Step < _pictureWidth,
|
||||||
|
//вниз
|
||||||
|
DiretionType.Down => _startPosY + EntityBoat.Step < _pictureHeight,
|
||||||
|
_ => false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Изменение направления перемещения
|
||||||
|
public void MoveTransport(DiretionType direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction) || EntityBoat == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case DiretionType.Left:
|
||||||
|
if (_startPosX - EntityBoat.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityBoat.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case DiretionType.Up:
|
||||||
|
if (_startPosY - EntityBoat.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityBoat.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// вправо
|
||||||
|
case DiretionType.Right:
|
||||||
|
if (_startPosX + EntityBoat.Step + _boatWidth < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityBoat.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case DiretionType.Down:
|
||||||
|
if (_startPosY + EntityBoat.Step + _boatHeight < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityBoat.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using ProjectBoat_bae.Entities;
|
||||||
|
namespace ProjectBoat_bae.DrawningObjects
|
||||||
|
{
|
||||||
|
public class DrawningMotorBoat : Drawningboat
|
||||||
|
{
|
||||||
|
|
||||||
|
public DrawningMotorBoat(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool body, bool wing,
|
||||||
|
int width, int height) : base(speed, weight, bodyColor, width, height, 110, 60)
|
||||||
|
|
||||||
|
{
|
||||||
|
if (EntityBoat != null)
|
||||||
|
{
|
||||||
|
EntityBoat = new EntityMotorBoat(speed, weight, bodyColor,
|
||||||
|
additionalColor, body, wing);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityBoat is not EntityMotorBoat Boat)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(Boat.AdditionalColor);
|
||||||
|
Brush br = new SolidBrush(EntityBoat.BodyColor);
|
||||||
|
Brush brRed = new SolidBrush(EntityBoat.BodyColor);
|
||||||
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||||
|
|
||||||
|
if (Boat.Body)
|
||||||
|
{
|
||||||
|
//вёсла
|
||||||
|
g.FillRectangle(brRed, _startPosX + 35, _startPosY - 5, 5, 65);
|
||||||
|
g.FillRectangle(brRed, _startPosX + 28, _startPosY + 60, 12, 8);
|
||||||
|
g.FillRectangle(brRed, _startPosX + 28, _startPosY - 5, 12, 8);
|
||||||
|
}
|
||||||
|
base.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
ProjectBoat_bae/ProjectBoat_bae/Entities/EntityBoat.cs
Normal file
24
ProjectBoat_bae/ProjectBoat_bae/Entities/EntityBoat.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.Entities
|
||||||
|
{
|
||||||
|
public class EntityBoat
|
||||||
|
{
|
||||||
|
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
|
||||||
|
public EntityBoat(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
ProjectBoat_bae/ProjectBoat_bae/Entities/EntityMotorBoat.cs
Normal file
22
ProjectBoat_bae/ProjectBoat_bae/Entities/EntityMotorBoat.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.Entities
|
||||||
|
{
|
||||||
|
public class EntityMotorBoat : EntityBoat
|
||||||
|
{
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
public bool Body { get; private set; }
|
||||||
|
public bool Wing { get; private set; }
|
||||||
|
public EntityMotorBoat(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool body, bool wing) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
Body = body;
|
||||||
|
Wing = wing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
94
ProjectBoat_bae/ProjectBoat_bae/Form1.Designer.cs
generated
94
ProjectBoat_bae/ProjectBoat_bae/Form1.Designer.cs
generated
@@ -30,11 +30,15 @@
|
|||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBoat));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBoat));
|
||||||
pictureBox1 = new PictureBox();
|
pictureBox1 = new PictureBox();
|
||||||
buttonCreate = new Button();
|
|
||||||
button_bottom = new Button();
|
button_bottom = new Button();
|
||||||
button_top = new Button();
|
button_top = new Button();
|
||||||
button_right = new Button();
|
button_right = new Button();
|
||||||
button_left = new Button();
|
button_left = new Button();
|
||||||
|
buttonClick = new Button();
|
||||||
|
buttonClickMotorBoat = new Button();
|
||||||
|
buttonStep = new Button();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonSelectBoat_Click = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@@ -43,21 +47,10 @@
|
|||||||
pictureBox1.Dock = DockStyle.Fill;
|
pictureBox1.Dock = DockStyle.Fill;
|
||||||
pictureBox1.Location = new Point(0, 0);
|
pictureBox1.Location = new Point(0, 0);
|
||||||
pictureBox1.Name = "pictureBox1";
|
pictureBox1.Name = "pictureBox1";
|
||||||
pictureBox1.Size = new Size(878, 444);
|
pictureBox1.Size = new Size(1178, 644);
|
||||||
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
|
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
pictureBox1.TabIndex = 0;
|
pictureBox1.TabIndex = 0;
|
||||||
pictureBox1.TabStop = false;
|
pictureBox1.TabStop = false;
|
||||||
pictureBox1.Click += pictureBox1_Click;
|
|
||||||
//
|
|
||||||
// buttonCreate
|
|
||||||
//
|
|
||||||
buttonCreate.Location = new Point(25, 379);
|
|
||||||
buttonCreate.Name = "buttonCreate";
|
|
||||||
buttonCreate.Size = new Size(112, 34);
|
|
||||||
buttonCreate.TabIndex = 1;
|
|
||||||
buttonCreate.Text = "Создать";
|
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreate.Click += buttonClick;
|
|
||||||
//
|
//
|
||||||
// button_bottom
|
// button_bottom
|
||||||
//
|
//
|
||||||
@@ -65,7 +58,7 @@
|
|||||||
button_bottom.BackColor = SystemColors.ButtonHighlight;
|
button_bottom.BackColor = SystemColors.ButtonHighlight;
|
||||||
button_bottom.BackgroundImage = (Image)resources.GetObject("button_bottom.BackgroundImage");
|
button_bottom.BackgroundImage = (Image)resources.GetObject("button_bottom.BackgroundImage");
|
||||||
button_bottom.BackgroundImageLayout = ImageLayout.Zoom;
|
button_bottom.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
button_bottom.Location = new Point(782, 391);
|
button_bottom.Location = new Point(1082, 591);
|
||||||
button_bottom.Name = "button_bottom";
|
button_bottom.Name = "button_bottom";
|
||||||
button_bottom.Size = new Size(30, 30);
|
button_bottom.Size = new Size(30, 30);
|
||||||
button_bottom.TabIndex = 2;
|
button_bottom.TabIndex = 2;
|
||||||
@@ -78,7 +71,7 @@
|
|||||||
button_top.BackColor = SystemColors.ButtonHighlight;
|
button_top.BackColor = SystemColors.ButtonHighlight;
|
||||||
button_top.BackgroundImage = (Image)resources.GetObject("button_top.BackgroundImage");
|
button_top.BackgroundImage = (Image)resources.GetObject("button_top.BackgroundImage");
|
||||||
button_top.BackgroundImageLayout = ImageLayout.Zoom;
|
button_top.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
button_top.Location = new Point(782, 349);
|
button_top.Location = new Point(1082, 549);
|
||||||
button_top.Name = "button_top";
|
button_top.Name = "button_top";
|
||||||
button_top.Size = new Size(30, 30);
|
button_top.Size = new Size(30, 30);
|
||||||
button_top.TabIndex = 3;
|
button_top.TabIndex = 3;
|
||||||
@@ -91,7 +84,7 @@
|
|||||||
button_right.BackColor = SystemColors.ButtonHighlight;
|
button_right.BackColor = SystemColors.ButtonHighlight;
|
||||||
button_right.BackgroundImage = (Image)resources.GetObject("button_right.BackgroundImage");
|
button_right.BackgroundImage = (Image)resources.GetObject("button_right.BackgroundImage");
|
||||||
button_right.BackgroundImageLayout = ImageLayout.Zoom;
|
button_right.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
button_right.Location = new Point(814, 373);
|
button_right.Location = new Point(1114, 573);
|
||||||
button_right.Name = "button_right";
|
button_right.Name = "button_right";
|
||||||
button_right.Size = new Size(30, 30);
|
button_right.Size = new Size(30, 30);
|
||||||
button_right.TabIndex = 4;
|
button_right.TabIndex = 4;
|
||||||
@@ -104,27 +97,81 @@
|
|||||||
button_left.BackColor = SystemColors.ButtonHighlight;
|
button_left.BackColor = SystemColors.ButtonHighlight;
|
||||||
button_left.BackgroundImage = (Image)resources.GetObject("button_left.BackgroundImage");
|
button_left.BackgroundImage = (Image)resources.GetObject("button_left.BackgroundImage");
|
||||||
button_left.BackgroundImageLayout = ImageLayout.Zoom;
|
button_left.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
button_left.Location = new Point(751, 372);
|
button_left.Location = new Point(1051, 572);
|
||||||
button_left.Name = "button_left";
|
button_left.Name = "button_left";
|
||||||
button_left.Size = new Size(30, 30);
|
button_left.Size = new Size(30, 30);
|
||||||
button_left.TabIndex = 5;
|
button_left.TabIndex = 5;
|
||||||
button_left.UseVisualStyleBackColor = false;
|
button_left.UseVisualStyleBackColor = false;
|
||||||
button_left.Click += buttonMove_Click;
|
button_left.Click += buttonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonClick
|
||||||
|
//
|
||||||
|
buttonClick.Location = new Point(12, 598);
|
||||||
|
buttonClick.Name = "buttonClick";
|
||||||
|
buttonClick.Size = new Size(233, 34);
|
||||||
|
buttonClick.TabIndex = 6;
|
||||||
|
buttonClick.Text = "Создать лодку";
|
||||||
|
buttonClick.UseVisualStyleBackColor = true;
|
||||||
|
buttonClick.Click += buttonClick_Click;
|
||||||
|
//
|
||||||
|
// buttonClickMotorBoat
|
||||||
|
//
|
||||||
|
buttonClickMotorBoat.Location = new Point(261, 598);
|
||||||
|
buttonClickMotorBoat.Name = "buttonClickMotorBoat";
|
||||||
|
buttonClickMotorBoat.Size = new Size(233, 34);
|
||||||
|
buttonClickMotorBoat.TabIndex = 7;
|
||||||
|
buttonClickMotorBoat.Text = "Создать моторную лодку";
|
||||||
|
buttonClickMotorBoat.UseVisualStyleBackColor = true;
|
||||||
|
buttonClickMotorBoat.Click += buttonClickMotorBoat_Click;
|
||||||
|
//
|
||||||
|
// buttonStep
|
||||||
|
//
|
||||||
|
buttonStep.Location = new Point(1093, 45);
|
||||||
|
buttonStep.Name = "buttonStep";
|
||||||
|
buttonStep.Size = new Size(73, 36);
|
||||||
|
buttonStep.TabIndex = 8;
|
||||||
|
buttonStep.Text = "шаг";
|
||||||
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStep.Click += buttonStep_Click;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.BackColor = SystemColors.ControlLight;
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
|
||||||
|
comboBoxStrategy.Location = new Point(984, 6);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(182, 33);
|
||||||
|
comboBoxStrategy.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// buttonSelectBoat_Click
|
||||||
|
//
|
||||||
|
buttonSelectBoat_Click.Location = new Point(517, 598);
|
||||||
|
buttonSelectBoat_Click.Name = "buttonSelectBoat_Click";
|
||||||
|
buttonSelectBoat_Click.Size = new Size(233, 34);
|
||||||
|
buttonSelectBoat_Click.TabIndex = 10;
|
||||||
|
buttonSelectBoat_Click.Text = "Выбранная лодка";
|
||||||
|
buttonSelectBoat_Click.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectBoat_Click.Click += this.buttonSelectBoat_Click_Click;
|
||||||
|
//
|
||||||
// FormBoat
|
// FormBoat
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(878, 444);
|
ClientSize = new Size(1178, 644);
|
||||||
|
Controls.Add(buttonSelectBoat_Click);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
|
Controls.Add(buttonStep);
|
||||||
|
Controls.Add(buttonClickMotorBoat);
|
||||||
|
Controls.Add(buttonClick);
|
||||||
Controls.Add(button_left);
|
Controls.Add(button_left);
|
||||||
Controls.Add(button_right);
|
Controls.Add(button_right);
|
||||||
Controls.Add(button_top);
|
Controls.Add(button_top);
|
||||||
Controls.Add(button_bottom);
|
Controls.Add(button_bottom);
|
||||||
Controls.Add(buttonCreate);
|
|
||||||
Controls.Add(pictureBox1);
|
Controls.Add(pictureBox1);
|
||||||
Name = "FormBoat";
|
Name = "FormBoat";
|
||||||
Text = "Form1";
|
Text = "Form1";
|
||||||
Load += Form1_Load;
|
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
@@ -133,10 +180,15 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBox1;
|
private PictureBox pictureBox1;
|
||||||
private Button buttonCreate;
|
|
||||||
private Button button_bottom;
|
private Button button_bottom;
|
||||||
private Button button_top;
|
private Button button_top;
|
||||||
private Button button_right;
|
private Button button_right;
|
||||||
private Button button_left;
|
private Button button_left;
|
||||||
|
private Button buttonClick;
|
||||||
|
private Button buttonClickMotorBoat;
|
||||||
|
private Button buttonStep;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button button1;
|
||||||
|
private Button buttonSelectBoat_Click;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,53 @@
|
|||||||
|
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 ProjectBoat_bae.Entities;
|
||||||
|
using ProjectBoat_bae.MovementStrategy;
|
||||||
|
using ProjectBoat_bae.DrawningObjects;
|
||||||
|
|
||||||
namespace ProjectBoat_bae
|
namespace ProjectBoat_bae
|
||||||
{
|
{
|
||||||
public partial class FormBoat : Form
|
public partial class FormBoat : Form
|
||||||
{
|
{
|
||||||
// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
private Drawing? _drawningBoat;
|
private Drawningboat? _drawingBoat;
|
||||||
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
public Drawningboat? SelectedBoat { get; private set; }
|
||||||
|
|
||||||
public FormBoat()
|
public FormBoat()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
SelectedBoat = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningBoat == null)
|
if (_drawingBoat == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBox1.Width,
|
Bitmap bmp = new(pictureBox1.Width,
|
||||||
pictureBox1.Height);
|
pictureBox1.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningBoat.DrawTransport(gr);
|
_drawingBoat.DrawTransport(gr);
|
||||||
pictureBox1.Image = bmp;
|
pictureBox1.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningBoat == null)
|
if (_drawingBoat == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -36,47 +55,98 @@ namespace ProjectBoat_bae
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "button_top":
|
case "button_top":
|
||||||
_drawningBoat.MoveTransport(DiretionType.Up);
|
_drawingBoat.MoveTransport(DiretionType.Up);
|
||||||
break;
|
break;
|
||||||
case "button_bottom":
|
case "button_bottom":
|
||||||
_drawningBoat.MoveTransport(DiretionType.Down);
|
_drawingBoat.MoveTransport(DiretionType.Down);
|
||||||
break;
|
break;
|
||||||
case "button_left":
|
case "button_left":
|
||||||
_drawningBoat.MoveTransport(DiretionType.Left);
|
_drawingBoat.MoveTransport(DiretionType.Left);
|
||||||
break;
|
break;
|
||||||
case "button_right":
|
case "button_right":
|
||||||
_drawningBoat.MoveTransport(DiretionType.Right);
|
_drawingBoat.MoveTransport(DiretionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
private void buttonClickMotorBoat_Click(object sender, EventArgs e)
|
||||||
private void buttonClick(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawningBoat = new Drawing();
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
_drawningBoat.Init(random.Next(100, 300), random.Next(1000, 3000),
|
ColorDialog dialog = new();
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
{
|
||||||
//Convert.ToBoolean(random.Next(0, 2)),
|
color = dialog.Color;
|
||||||
Convert.ToBoolean(random.Next(0, 2)), pictureBox1.Width, pictureBox1.Height);
|
}
|
||||||
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialogAddColor = new();
|
||||||
|
if (dialogAddColor.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogAddColor.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawingBoat = new DrawningMotorBoat(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);
|
||||||
|
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void buttonClick_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawingBoat = new Drawningboat(random.Next(100, 300), random.Next(1000, 3000), color, pictureBox1.Width, pictureBox1.Height);
|
||||||
|
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form1_Load(object sender, EventArgs e)
|
private void buttonStep_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (_drawingBoat == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||||
|
switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(new DrawningObjectBoat(_drawingBoat), 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 pictureBox1_Click(object sender, EventArgs e)
|
private void buttonSelectBoat_Click_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
SelectedBoat = _drawingBoat;
|
||||||
}
|
DialogResult = DialogResult.OK;
|
||||||
|
|
||||||
private void button_top_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
124
ProjectBoat_bae/ProjectBoat_bae/FormBoatCollection.Designer.cs
generated
Normal file
124
ProjectBoat_bae/ProjectBoat_bae/FormBoatCollection.Designer.cs
generated
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
namespace ProjectBoat_bae
|
||||||
|
{
|
||||||
|
partial class FormBoatCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
buttonAddBoat_Click = new Button();
|
||||||
|
buttonRemoveBoat_Click = new Button();
|
||||||
|
buttonRefreshCollection_Click = new Button();
|
||||||
|
textBox1 = new TextBox();
|
||||||
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(1176, 647);
|
||||||
|
pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
|
pictureBoxCollection.TabIndex = 0;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonAddBoat_Click
|
||||||
|
//
|
||||||
|
buttonAddBoat_Click.Location = new Point(955, 73);
|
||||||
|
buttonAddBoat_Click.Name = "buttonAddBoat_Click";
|
||||||
|
buttonAddBoat_Click.Size = new Size(201, 47);
|
||||||
|
buttonAddBoat_Click.TabIndex = 1;
|
||||||
|
buttonAddBoat_Click.Text = "Добавить лодку";
|
||||||
|
buttonAddBoat_Click.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddBoat_Click.Click += buttonAddBoat_Click_Click;
|
||||||
|
//
|
||||||
|
// buttonRemoveBoat_Click
|
||||||
|
//
|
||||||
|
buttonRemoveBoat_Click.Location = new Point(955, 345);
|
||||||
|
buttonRemoveBoat_Click.Name = "buttonRemoveBoat_Click";
|
||||||
|
buttonRemoveBoat_Click.Size = new Size(201, 46);
|
||||||
|
buttonRemoveBoat_Click.TabIndex = 2;
|
||||||
|
buttonRemoveBoat_Click.Text = "Удалить лодку";
|
||||||
|
buttonRemoveBoat_Click.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemoveBoat_Click.Click += buttonRemoveBoat_Click_Click;
|
||||||
|
//
|
||||||
|
// buttonRefreshCollection_Click
|
||||||
|
//
|
||||||
|
buttonRefreshCollection_Click.Location = new Point(955, 421);
|
||||||
|
buttonRefreshCollection_Click.Name = "buttonRefreshCollection_Click";
|
||||||
|
buttonRefreshCollection_Click.Size = new Size(201, 50);
|
||||||
|
buttonRefreshCollection_Click.TabIndex = 3;
|
||||||
|
buttonRefreshCollection_Click.Text = "Обновить коллекцию";
|
||||||
|
buttonRefreshCollection_Click.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefreshCollection_Click.Click += buttonRefreshCollection_Click_Click;
|
||||||
|
//
|
||||||
|
// textBox1
|
||||||
|
//
|
||||||
|
textBox1.BackColor = SystemColors.MenuBar;
|
||||||
|
textBox1.Location = new Point(955, 12);
|
||||||
|
textBox1.Name = "textBox1";
|
||||||
|
textBox1.Size = new Size(150, 31);
|
||||||
|
textBox1.TabIndex = 4;
|
||||||
|
textBox1.Text = "Инструменты";
|
||||||
|
textBox1.TextAlign = HorizontalAlignment.Center;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Location = new Point(979, 293);
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(150, 31);
|
||||||
|
maskedTextBoxNumber.TabIndex = 5;
|
||||||
|
maskedTextBoxNumber.Text = "_";
|
||||||
|
//
|
||||||
|
// FormBoatCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1178, 644);
|
||||||
|
Controls.Add(maskedTextBoxNumber);
|
||||||
|
Controls.Add(textBox1);
|
||||||
|
Controls.Add(buttonRefreshCollection_Click);
|
||||||
|
Controls.Add(buttonRemoveBoat_Click);
|
||||||
|
Controls.Add(buttonAddBoat_Click);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Name = "FormBoatCollection";
|
||||||
|
Text = "FormBoatCollection";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private Button buttonAddBoat_Click;
|
||||||
|
private Button buttonRemoveBoat_Click;
|
||||||
|
private Button buttonRefreshCollection_Click;
|
||||||
|
private TextBox textBox1;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
76
ProjectBoat_bae/ProjectBoat_bae/FormBoatCollection.cs
Normal file
76
ProjectBoat_bae/ProjectBoat_bae/FormBoatCollection.cs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
using ProjectBoat_bae.DrawningObjects;
|
||||||
|
using ProjectBoat_bae.Generics;
|
||||||
|
using ProjectBoat_bae.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae
|
||||||
|
{
|
||||||
|
public partial class FormBoatCollection : Form
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly BoatsGenericCollection<Drawningboat, DrawningObjectBoat> _boats;
|
||||||
|
|
||||||
|
public FormBoatCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_boats = new BoatsGenericCollection<Drawningboat, DrawningObjectBoat>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Добавление объекта в набор
|
||||||
|
private void buttonAddBoat_Click_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormBoat form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_boats + form.SelectedBoat != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = _boats.ShowBoats();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Удаление объекта из набора
|
||||||
|
private void buttonRemoveBoat_Click_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = -1;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
}
|
||||||
|
catch (Exception ex) { }
|
||||||
|
if (_boats - pos)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = _boats.ShowBoats();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonRefreshCollection_Click_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _boats.ShowBoats();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
120
ProjectBoat_bae/ProjectBoat_bae/FormBoatCollection.resx
Normal file
120
ProjectBoat_bae/ProjectBoat_bae/FormBoatCollection.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>
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectBoat_bae.MovementStrategy;
|
||||||
|
using ProjectBoat_bae.DrawningObjects;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.Generics
|
||||||
|
{
|
||||||
|
internal class BoatsGenericCollection <T, U>
|
||||||
|
where T : Drawningboat
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
// Ширина окна прорисовки
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
// Высота окна прорисовки
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 160;
|
||||||
|
|
||||||
|
// Размер занимаемого объектом места (высота)
|
||||||
|
private readonly int _placeSizeHeight = 160;
|
||||||
|
|
||||||
|
// Набор объектов
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
|
||||||
|
// Конструктор
|
||||||
|
public BoatsGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Перегрузка оператора сложения
|
||||||
|
public static int operator +(BoatsGenericCollection<T, U> collect, T?
|
||||||
|
obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Перегрузка оператора вычитания
|
||||||
|
public static bool operator -(BoatsGenericCollection<T, U> collect, int
|
||||||
|
pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection.Get(pos);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получение объекта IMoveableObject
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Вывод всего набора объектов
|
||||||
|
public Bitmap ShowBoats()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Метод отрисовки фона
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Метод прорисовки объектов
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
Drawningboat boat = _collection.Get(i);
|
||||||
|
|
||||||
|
if (boat != null)
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
boat.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
|
||||||
|
boat.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
66
ProjectBoat_bae/ProjectBoat_bae/Generics/SetGeneric.cs
Normal file
66
ProjectBoat_bae/ProjectBoat_bae/Generics/SetGeneric.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.Generics
|
||||||
|
{
|
||||||
|
internal class SetGeneric<T> where T : class
|
||||||
|
{
|
||||||
|
private readonly T?[] _places;
|
||||||
|
|
||||||
|
public int Count => _places.Length;
|
||||||
|
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T?[count];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T boat)
|
||||||
|
{
|
||||||
|
if (_places[Count - 1] != null)
|
||||||
|
return -1;
|
||||||
|
return Insert(boat, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T boat, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return -1;
|
||||||
|
if (_places[position] != null)
|
||||||
|
{
|
||||||
|
int indexEnd = position + 1;
|
||||||
|
while (_places[indexEnd] != null)
|
||||||
|
{
|
||||||
|
indexEnd++;
|
||||||
|
}
|
||||||
|
for (int i = indexEnd + 1; i > position; i--)
|
||||||
|
{
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
_places[position] = boat;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _places.Count())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_places[position] = null;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _places.Count())
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.MovementStrategy
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
|
||||||
|
// Перемещаемый объект
|
||||||
|
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
|
||||||
|
// Статус перемещения
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
// Ширина поля
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
// Высота поля
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
// Статус перемещения
|
||||||
|
public Status GetStatus() { return _state; }
|
||||||
|
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int
|
||||||
|
height)
|
||||||
|
{
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
_state = Status.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = Status.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Шаг перемещения
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Перемещение влево
|
||||||
|
protected bool MoveLeft() => MoveTo(DiretionType.Left);
|
||||||
|
|
||||||
|
// Перемещение вправо
|
||||||
|
protected bool MoveRight() => MoveTo(DiretionType.Right);
|
||||||
|
|
||||||
|
// Перемещение вверх
|
||||||
|
protected bool MoveUp() => MoveTo(DiretionType.Up);
|
||||||
|
|
||||||
|
// Перемещение вниз
|
||||||
|
protected bool MoveDown() => MoveTo(DiretionType.Down);
|
||||||
|
|
||||||
|
// Параметры объекта
|
||||||
|
protected ObjectParameters? GetObjectParameters =>
|
||||||
|
_moveableObject?.GetObjectPosition;
|
||||||
|
|
||||||
|
// Шаг объекта
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
// Перемещение к цели
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
// Достигнута ли цель
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
// Попытка перемещения в требуемом направлении
|
||||||
|
private bool MoveTo(DiretionType directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using ProjectBoat_bae;
|
||||||
|
using ProjectBoat_bae.Entities;
|
||||||
|
using ProjectBoat_bae.DrawningObjects;
|
||||||
|
namespace ProjectBoat_bae.MovementStrategy
|
||||||
|
{
|
||||||
|
// Реализация интерфейса для работы с объектом DrawningBoat!
|
||||||
|
public class DrawningObjectBoat : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly Drawningboat? _drawingBoat = null;
|
||||||
|
|
||||||
|
public DrawningObjectBoat(Drawningboat drawingBoat)
|
||||||
|
{
|
||||||
|
_drawingBoat = drawingBoat;
|
||||||
|
}
|
||||||
|
//!
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawingBoat == null || _drawingBoat.EntityBoat == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawingBoat.GetPosX,
|
||||||
|
_drawingBoat.GetPosY, _drawingBoat.GetWidth, _drawingBoat.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawingBoat?.EntityBoat?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(DiretionType direction) => _drawingBoat?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(DiretionType direction) => _drawingBoat?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
// Получение координаты X объекта
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
|
// Шаг объектa
|
||||||
|
int GetStep { get; }
|
||||||
|
|
||||||
|
// Проверка, можно ли переместиться по нужному направлению
|
||||||
|
bool CheckCanMove(DiretionType direction);
|
||||||
|
|
||||||
|
// Изменение направления пермещения объекта
|
||||||
|
void MoveObject(DiretionType direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.MovementStrategy
|
||||||
|
{
|
||||||
|
public 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 = FieldWidth - objParams.RightBorder;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
var diffY = FieldHeight - objParams.DownBorder;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.MovementStrategy
|
||||||
|
{
|
||||||
|
// Параметры-координаты объекта
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
ProjectBoat_bae/ProjectBoat_bae/MovementStrategy/Status.cs
Normal file
15
ProjectBoat_bae/ProjectBoat_bae/MovementStrategy/Status.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBoat_bae.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ namespace ProjectBoat_bae
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormBoat());
|
Application.Run(new FormBoatCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@ namespace ProjectBoat_bae
|
|||||||
{
|
{
|
||||||
public class ProjectBoat_bae
|
public class ProjectBoat_bae
|
||||||
{
|
{
|
||||||
|
|
||||||
public int Speed { get; private set; }
|
public int Speed { get; private set; }
|
||||||
|
|
||||||
public double Weight { get; private set; }
|
public double Weight { get; private set; }
|
||||||
@@ -21,17 +20,33 @@ namespace ProjectBoat_bae
|
|||||||
|
|
||||||
public bool body { get; private set; }
|
public bool body { get; private set; }
|
||||||
|
|
||||||
|
public bool Wing { get; private set; }
|
||||||
|
|
||||||
|
public bool SportLine { get; private set; }
|
||||||
|
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация полей объекта-класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed"
|
||||||
|
/// <param name="weight"
|
||||||
|
/// <param name="bodyColor"
|
||||||
|
/// <param name="additionalColor"
|
||||||
|
/// <param name="bodyKit"
|
||||||
|
/// <param name="wing"
|
||||||
|
/// <param name="sportLine"
|
||||||
|
|
||||||
//объект
|
//объект
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
public void Init(int speed, double weight, Color bodyColor, Color
|
||||||
additionalColor, bool bodyKit)
|
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
body = bodyKit;
|
body = bodyKit;
|
||||||
|
Wing = wing;
|
||||||
|
SportLine = sportLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.7.34031.279
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "evm_4laba", "evm_4laba\evm_4laba.csproj", "{7CFA474E-08C2-459C-AC2B-35D9B2179EA2}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{7CFA474E-08C2-459C-AC2B-35D9B2179EA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{7CFA474E-08C2-459C-AC2B-35D9B2179EA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{7CFA474E-08C2-459C-AC2B-35D9B2179EA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{7CFA474E-08C2-459C-AC2B-35D9B2179EA2}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {CDA146C8-F7AF-41AE-A3DD-591AFE057184}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace BinaryCalculator
|
|
||||||
{
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
|
||||||
// Ввод пользователем данных
|
|
||||||
Console.WriteLine("Введите исходную систему счисления (2-16):");
|
|
||||||
int baseNumber = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.WriteLine("Введите первое число:");
|
|
||||||
string binaryNumber1 = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.WriteLine("Введите второе число:");
|
|
||||||
string binaryNumber2 = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.WriteLine("Введите операцию (+, -, *, /):");
|
|
||||||
char operation = Convert.ToChar(Console.ReadLine());
|
|
||||||
|
|
||||||
|
|
||||||
// Преобразование чисел в двоичную систему счисления
|
|
||||||
int decimalNumber1 = Convert.ToInt32(binaryNumber1, baseNumber);
|
|
||||||
int decimalNumber2 = Convert.ToInt32(binaryNumber2, baseNumber);
|
|
||||||
|
|
||||||
// Выполнение арифметической операции
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
switch (operation)
|
|
||||||
{
|
|
||||||
case '+':
|
|
||||||
result = decimalNumber1 + decimalNumber2;
|
|
||||||
break;
|
|
||||||
case '-':
|
|
||||||
result = decimalNumber1 - decimalNumber2;
|
|
||||||
break;
|
|
||||||
case '*':
|
|
||||||
result = decimalNumber1 * decimalNumber2;
|
|
||||||
break;
|
|
||||||
case '/':
|
|
||||||
result = decimalNumber1 / decimalNumber2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Console.WriteLine("Неправильно указана операция.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Вывод результата в двоичной системе счисления
|
|
||||||
string binaryResult = Convert.ToString(result, 2);
|
|
||||||
Console.WriteLine("Результат: " + binaryResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.7.34031.279
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "evm_laba3", "evm_laba3\evm_laba3.csproj", "{BE1E2078-C452-4E42-BBBB-3AC3141E9744}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{BE1E2078-C452-4E42-BBBB-3AC3141E9744}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{BE1E2078-C452-4E42-BBBB-3AC3141E9744}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{BE1E2078-C452-4E42-BBBB-3AC3141E9744}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{BE1E2078-C452-4E42-BBBB-3AC3141E9744}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {5A26F9BF-589C-4D50-995E-D6FA981231E6}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
@@ -1,296 +0,0 @@
|
|||||||
//using System;
|
|
||||||
|
|
||||||
//namespace NumberConverter
|
|
||||||
//{
|
|
||||||
// class Program
|
|
||||||
// {
|
|
||||||
// static void Main(string[] args)
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// Console.WriteLine("Введите исходную систему счисления (2-16):");
|
|
||||||
// int sourceBase = int.Parse(Console.ReadLine());
|
|
||||||
|
|
||||||
// Console.WriteLine("Введите конечную систему счисления (2-16):");
|
|
||||||
// int targetBase = int.Parse(Console.ReadLine());
|
|
||||||
|
|
||||||
// Console.WriteLine("Введите число в исходной системе счисления:");
|
|
||||||
// string number = Console.ReadLine();
|
|
||||||
|
|
||||||
// int decimalNumber = ConvertToDecimal(number, sourceBase);
|
|
||||||
|
|
||||||
// string targetNumber = ConvertFromDecimal(decimalNumber, targetBase);
|
|
||||||
|
|
||||||
// Console.WriteLine("Результат: " + targetNumber);
|
|
||||||
|
|
||||||
// //string result = Convert.ToString(decimalNumber, targetBase);
|
|
||||||
|
|
||||||
// //result = result.PadLeft(8, '0'); // дополняем до 8 символов
|
|
||||||
// // //Console.WriteLine("Результат ПК: " + result);
|
|
||||||
// //Console.WriteLine("Результат ПК: " + result);
|
|
||||||
|
|
||||||
// }
|
|
||||||
// catch (FormatException)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine("Ошибка: введенное значение имеет неверный формат.");
|
|
||||||
// }
|
|
||||||
// catch (ArgumentOutOfRangeException)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine("Ошибка: значение системы счисления должно быть от 2 до 16.");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //в 10
|
|
||||||
// static int ConvertToDecimal(string number, int sourceBase) //число в 10
|
|
||||||
// {
|
|
||||||
// bool isNegative = false;
|
|
||||||
// if (number.StartsWith("-"))
|
|
||||||
// {
|
|
||||||
// isNegative = true;
|
|
||||||
// number = number.Substring(1);//извлекает подстроку
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //с конца числа каждая цифра умножается на на степень систем, а потом суммируются значения
|
|
||||||
// int decimalNumber = 0;
|
|
||||||
// int power = 0;
|
|
||||||
// for (int i = number.Length - 1; i >= 0; i--)
|
|
||||||
// {
|
|
||||||
// int digitValue;
|
|
||||||
// if (char.IsDigit(number[i]))
|
|
||||||
// {
|
|
||||||
// digitValue = number[i] - '0';
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// digitValue = number[i] - 'A' + 10;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //Math.Pow - в степень
|
|
||||||
// decimalNumber += digitValue * (int)Math.Pow(sourceBase, power);
|
|
||||||
// power++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //конвертирует в пк
|
|
||||||
// static string ConvertTwosComplement(int num)
|
|
||||||
// {
|
|
||||||
// string binary = Convert.ToString(num, 2);
|
|
||||||
// char[] binaryArr = binary.PadLeft(8, '0').ToCharArray();
|
|
||||||
// for (int i = 0; i < binaryArr.Length; i++)
|
|
||||||
// {
|
|
||||||
// binaryArr[i] = binaryArr[i] == '0' ? '1' : '0';
|
|
||||||
// }
|
|
||||||
|
|
||||||
// int twosComplement = Convert.ToInt32(new string(binaryArr), 2) + 1;
|
|
||||||
// return Convert.ToString(twosComplement, 2).PadLeft(8, '0');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return isNegative ? -decimalNumber : decimalNumber;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //из 10
|
|
||||||
// static string ConvertFromDecimal(int decimalNumber, int targetBase)//10 d lheue.
|
|
||||||
// {
|
|
||||||
// bool isNegative = false;
|
|
||||||
// if (decimalNumber < 0)
|
|
||||||
// {
|
|
||||||
// isNegative = true;
|
|
||||||
// decimalNumber = -decimalNumber;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //остаток от деления записывается как цифра
|
|
||||||
// string targetNumber = "";
|
|
||||||
// while (decimalNumber != 0)
|
|
||||||
// {
|
|
||||||
// int remainder = decimalNumber % targetBase;
|
|
||||||
// char digit;
|
|
||||||
// if (remainder < 10)
|
|
||||||
// {
|
|
||||||
// digit = (char)(remainder + '0');
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// digit = (char)(remainder - 10 + 'A');
|
|
||||||
// }
|
|
||||||
// targetNumber = digit + targetNumber;
|
|
||||||
// decimalNumber /= targetBase;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (isNegative)
|
|
||||||
// {
|
|
||||||
// return "-" + targetNumber;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// return targetNumber;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//using System;
|
|
||||||
|
|
||||||
//public class NumberConverter
|
|
||||||
//{
|
|
||||||
// public static void Main(string[] args)
|
|
||||||
// {
|
|
||||||
// Console.Write("Введите число: ");
|
|
||||||
// string number = Console.ReadLine();
|
|
||||||
|
|
||||||
// Console.Write("Введите первоначальную систему: (2 - 16): ");
|
|
||||||
// int origBase = Int32.Parse(Console.ReadLine());
|
|
||||||
|
|
||||||
// Console.Write("Введите конечную систему: (2 - 16): ");
|
|
||||||
// int finalBase = Int32.Parse(Console.ReadLine());
|
|
||||||
|
|
||||||
// bool isNegative = number.StartsWith('-');//убирает минус чтобы конвертировать
|
|
||||||
// if (isNegative) number = number.Substring(1);
|
|
||||||
|
|
||||||
// //преоразование в 10
|
|
||||||
// int decimalNum = Convert.ToInt32(number, origBase);
|
|
||||||
|
|
||||||
// if (isNegative && finalBase == 2)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine("С минусом -" + Convert.ToString(decimalNum, finalBase));
|
|
||||||
// Console.WriteLine("ПК: " + ConvertTwosComplement(decimalNum));
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// string finalNum = Convert.ToString(decimalNum, finalBase);
|
|
||||||
// if (isNegative) finalNum = "-" + finalNum;
|
|
||||||
// Console.WriteLine($"{finalBase}-число: {finalNum.ToUpper()}");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //конвертирует в пк
|
|
||||||
// private static string ConvertTwosComplement(int num)
|
|
||||||
// {
|
|
||||||
// string binary = Convert.ToString(num, 2);
|
|
||||||
// char[] binaryArr = binary.PadLeft(8, '0').ToCharArray();
|
|
||||||
// for (int i = 0; i < binaryArr.Length; i++)
|
|
||||||
// {
|
|
||||||
// binaryArr[i] = binaryArr[i] == '0' ? '1' : '0';
|
|
||||||
// }
|
|
||||||
|
|
||||||
// int twosComplement = Convert.ToInt32(new string(binaryArr), 2) + 1;
|
|
||||||
// return Convert.ToString(twosComplement, 2).PadLeft(8, '0');
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using static System.Net.Mime.MediaTypeNames;
|
|
||||||
|
|
||||||
namespace AVM_3_laba
|
|
||||||
{
|
|
||||||
internal class Program
|
|
||||||
{
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
|
||||||
Console.Write("Введите исходную систему счисления (2-16): ");
|
|
||||||
int input = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
if ((input > 16) || (input < 2))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Введите сс от 2 до 16!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.Write("Введите конечную систему счисления (2-16): ");
|
|
||||||
int output = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
if ((output > 16) || (output < 2))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Введите сс от 2 до 16!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.Write("Введите число в исходной системе счисления: ");
|
|
||||||
string number = Console.ReadLine();
|
|
||||||
|
|
||||||
bool minus = false;
|
|
||||||
if (number[0] == '-')
|
|
||||||
{
|
|
||||||
number = number.Substring(1);
|
|
||||||
minus = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int decimalNumber = ConvertToDecimal(number, input);
|
|
||||||
int result = ConvertToOutput(decimalNumber, output);
|
|
||||||
|
|
||||||
if (minus) { result = -result; };
|
|
||||||
|
|
||||||
Console.WriteLine(result);
|
|
||||||
|
|
||||||
if (minus && output == 2)
|
|
||||||
{
|
|
||||||
Console.WriteLine(directСode(result * -1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ConvertToDecimal(string number, int input)
|
|
||||||
{
|
|
||||||
string numberString = number.ToString();
|
|
||||||
int decimalNumber = 0;
|
|
||||||
int power = 0; // степень числа
|
|
||||||
string digits = "0123456789ABCDEF";
|
|
||||||
|
|
||||||
for (int i = numberString.Length - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
char digit = numberString[i]; // берем текущую цифру
|
|
||||||
|
|
||||||
// Проверка на недопустимые символы
|
|
||||||
if (!digits.Contains(digit))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Неверный формат числа!");
|
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int value = digits.IndexOf(digit);
|
|
||||||
|
|
||||||
// Проверка на недопустимую цифру для выбранной системы счисления
|
|
||||||
if (value >= input)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Неверный формат числа!");
|
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
|
||||||
decimalNumber += value * (int)Math.Pow(input, power++);
|
|
||||||
}
|
|
||||||
return decimalNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ConvertToOutput(int number, int output)
|
|
||||||
{
|
|
||||||
string digits = "0123456789ABCDEF";
|
|
||||||
string result = "";
|
|
||||||
|
|
||||||
while (number > 0)
|
|
||||||
{
|
|
||||||
int remainder = number % output;
|
|
||||||
result = digits[remainder] + result;
|
|
||||||
number /= output;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Convert.ToInt32(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
static string directСode(int result)
|
|
||||||
{
|
|
||||||
string resultString = result.ToString();
|
|
||||||
int discharge = 8;
|
|
||||||
int countNumber = resultString.Length;
|
|
||||||
|
|
||||||
while (countNumber >= discharge)
|
|
||||||
{
|
|
||||||
discharge *= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int numberOfZeros = discharge - countNumber - 1;
|
|
||||||
|
|
||||||
string finalResultString = "1" + string.Concat(Enumerable.Repeat("0", numberOfZeros)) + resultString;
|
|
||||||
|
|
||||||
return finalResultString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
Reference in New Issue
Block a user