Добавление проверок на размер окна и изменения координат
This commit is contained in:
parent
d164bcbf1f
commit
dbbef18263
@ -8,71 +8,38 @@ namespace Sailboat
|
||||
{
|
||||
public class DrawingSailboat
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntitySailboat? EntitySailboat { get; private set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _boatWidth = 180;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _boatHeight = 180;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
|
||||
private readonly int _boatWidth = 160;
|
||||
private readonly int _boatHeight = 160;
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool hull, bool sail, int width, int height)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
if (width < _boatWidth || height < _boatHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntitySailboat = new EntitySailboat();
|
||||
EntitySailboat.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine);
|
||||
EntitySailboat.Init(speed, weight, bodyColor, additionalColor, hull, sail);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
// TODO: Изменение x, y
|
||||
if (x < 0 || x + _boatWidth > _pictureWidth)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0 || y + _boatHeight > _pictureHeight)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntitySailboat == null)
|
||||
@ -81,28 +48,24 @@ namespace Sailboat
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntitySailboat.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntitySailboat.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntitySailboat.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntitySailboat.Step;
|
||||
}
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntitySailboat.Step + _boatWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntitySailboat.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntitySailboat.Step + _boatHeight < _pictureHeight)
|
||||
{
|
||||
@ -111,103 +74,43 @@ namespace Sailboat
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntitySailboat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Pen pen = new(Color.Black, 4);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(EntitySailboat.AdditionalColor);
|
||||
// обвесы
|
||||
/*if (EntitySailboat.BodyKit)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20,
|
||||
20);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10,
|
||||
20, 40);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15,
|
||||
15);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45,
|
||||
15, 15);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 90,
|
||||
_startPosY, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 90,
|
||||
_startPosY + 40, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 90,
|
||||
_startPosY + 10, 20, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 90,
|
||||
_startPosY + 1, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 90,
|
||||
_startPosY + 45, 15, 15);
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20,
|
||||
40);
|
||||
g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14,
|
||||
15);
|
||||
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45,
|
||||
14, 15);
|
||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY,
|
||||
20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY +
|
||||
40, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 1,
|
||||
_startPosY + 10, 25, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 5,
|
||||
_startPosY + 1, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 5,
|
||||
_startPosY + 45, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39,
|
||||
15);
|
||||
g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45,
|
||||
39, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 35,
|
||||
_startPosY + 1, 40, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 35,
|
||||
_startPosY + 45, 40, 15);
|
||||
}
|
||||
|
||||
//границы автомобиля
|
||||
g.DrawEllipse(pen, _startPosX + 10, _startPosY + 5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
|
||||
30);
|
||||
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);*/
|
||||
|
||||
//усиленный корпус парусника
|
||||
Point[] hullCooler = new Point[]
|
||||
if (EntitySailboat.Hull)
|
||||
{
|
||||
new Point(_startPosX + 30, _startPosY + 100),
|
||||
new Point(_startPosX + 150, _startPosY + 100),
|
||||
new Point(_startPosX + 190, _startPosY + 140),
|
||||
new Point(_startPosX + 150, _startPosY + 180),
|
||||
new Point(_startPosX + 30, _startPosY + 180)
|
||||
};
|
||||
g.FillPolygon(additionalBrush, hullCooler);
|
||||
g.DrawPolygon(pen, hullCooler);
|
||||
Point[] hullCooler = new Point[]
|
||||
{
|
||||
new Point(_startPosX, _startPosY + 80),
|
||||
new Point(_startPosX + 120, _startPosY + 80),
|
||||
new Point(_startPosX + 160, _startPosY + 120),
|
||||
new Point(_startPosX + 120, _startPosY + 160),
|
||||
new Point(_startPosX, _startPosY + 160)
|
||||
};
|
||||
g.FillPolygon(additionalBrush, hullCooler);
|
||||
g.DrawPolygon(pen, hullCooler);
|
||||
}
|
||||
|
||||
|
||||
//основной корпус парусника
|
||||
|
||||
Brush Brush = new
|
||||
SolidBrush(EntitySailboat.BodyColor);
|
||||
|
||||
Point[] hull = new Point[]
|
||||
{
|
||||
new Point(_startPosX + 40, _startPosY + 110),
|
||||
new Point(_startPosX + 140, _startPosY + 110),
|
||||
new Point(_startPosX + 170, _startPosY + 140),
|
||||
new Point(_startPosX + 140, _startPosY + 170),
|
||||
new Point(_startPosX + 40, _startPosY + 170)
|
||||
new Point(_startPosX + 10, _startPosY + 90),
|
||||
new Point(_startPosX + 110, _startPosY + 90),
|
||||
new Point(_startPosX + 140, _startPosY + 120),
|
||||
new Point(_startPosX + 110, _startPosY + 150),
|
||||
new Point(_startPosX + 10, _startPosY + 150)
|
||||
};
|
||||
g.FillPolygon(Brush, hull);
|
||||
g.DrawPolygon(pen, hull);
|
||||
@ -215,22 +118,25 @@ namespace Sailboat
|
||||
Brush addBrush = new
|
||||
SolidBrush(Color.Green);
|
||||
|
||||
g.FillEllipse(addBrush, _startPosX + 50, _startPosY + 120, 90, 40);
|
||||
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 120, 90, 40);
|
||||
g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 90, 40);
|
||||
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40);
|
||||
|
||||
//парус
|
||||
Brush sailBrush = new
|
||||
SolidBrush(Color.Cyan);
|
||||
|
||||
Point[] sail = new Point[]
|
||||
if (EntitySailboat.Sail)
|
||||
{
|
||||
new Point(_startPosX + 95, _startPosY + 20),
|
||||
new Point(_startPosX + 160, _startPosY + 140),
|
||||
new Point(_startPosX + 45, _startPosY + 140)
|
||||
};
|
||||
g.FillPolygon(sailBrush, sail);
|
||||
g.DrawPolygon(pen, sail);
|
||||
g.DrawLine(pen, new Point(_startPosX + 95, _startPosY + 140), new Point(_startPosX + 95, _startPosY + 20));
|
||||
Brush sailBrush = new
|
||||
SolidBrush(EntitySailboat.AdditionalColor);
|
||||
|
||||
Point[] sail = new Point[]
|
||||
{
|
||||
new Point(_startPosX + 65, _startPosY),
|
||||
new Point(_startPosX + 130, _startPosY + 120),
|
||||
new Point(_startPosX + 15, _startPosY + 120)
|
||||
};
|
||||
g.FillPolygon(sailBrush, sail);
|
||||
g.DrawPolygon(pen, sail);
|
||||
g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 120), new Point(_startPosX + 65, _startPosY));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,17 +25,13 @@ namespace Sailboat
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// Признак (опция) наличия усиленного корпуса
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
public bool Hull { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// Признак (опция) наличия паруса
|
||||
/// </summary>
|
||||
public bool Wing { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool SportLine { get; private set; }
|
||||
public bool Sail { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
@ -47,19 +43,17 @@ namespace Sailboat
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
/// <param name="hull">Признак наличия усиленного корпуса</param>
|
||||
/// <param name="sail">Признак наличия паруса</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
additionalColor, bool hull, bool sail)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Wing = wing;
|
||||
SportLine = sportLine;
|
||||
Hull = hull;
|
||||
Sail = sail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
14
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
@ -43,7 +43,7 @@
|
||||
this.pictureBoxSailboat.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxSailboat.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxSailboat.Name = "pictureBoxSailboat";
|
||||
this.pictureBoxSailboat.Size = new System.Drawing.Size(1466, 741);
|
||||
this.pictureBoxSailboat.Size = new System.Drawing.Size(882, 453);
|
||||
this.pictureBoxSailboat.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxSailboat.TabIndex = 0;
|
||||
this.pictureBoxSailboat.TabStop = false;
|
||||
@ -51,7 +51,7 @@
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(12, 683);
|
||||
this.buttonCreate.Location = new System.Drawing.Point(12, 395);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(127, 46);
|
||||
this.buttonCreate.TabIndex = 1;
|
||||
@ -64,7 +64,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage")));
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(1294, 691);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(710, 403);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 2;
|
||||
@ -76,7 +76,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(1343, 646);
|
||||
this.buttonUp.Location = new System.Drawing.Point(759, 358);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 3;
|
||||
@ -88,7 +88,7 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage")));
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(1393, 691);
|
||||
this.buttonRight.Location = new System.Drawing.Point(809, 403);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 4;
|
||||
@ -100,7 +100,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage")));
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(1343, 691);
|
||||
this.buttonDown.Location = new System.Drawing.Point(759, 403);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 5;
|
||||
@ -111,7 +111,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1466, 741);
|
||||
this.ClientSize = new System.Drawing.Size(882, 453);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
|
@ -23,14 +23,9 @@ namespace Sailboat
|
||||
{
|
||||
Random random = new();
|
||||
_drawingSailboat = new DrawingSailboat();
|
||||
_drawingSailboat.Init(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
_drawingSailboat.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailboat.Width, pictureBoxSailboat.Height);
|
||||
Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailboat.Width, pictureBoxSailboat.Height);
|
||||
_drawingSailboat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user