Нарисовала парусник

This commit is contained in:
Полина Чубыкина 2023-09-22 17:19:54 +04:00
parent 568549df04
commit e7832c9d05
5 changed files with 108 additions and 59 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Sailboat
{
internal enum DirectionType
public enum DirectionType
{
/// <summary>
/// Вверх

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Sailboat
{
internal class DrawingSailboat
public class DrawingSailboat
{
/// <summary>
/// Класс-сущность
@ -31,11 +31,11 @@ namespace Sailboat
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
private readonly int _carWidth = 110;
private readonly int _boatWidth = 180;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
private readonly int _carHeight = 60;
private readonly int _boatHeight = 180;
/// <summary>
/// Инициализация свойств
/// </summary>
@ -97,11 +97,17 @@ namespace Sailboat
break;
// вправо
case DirectionType.Right:
// TODO: Продумать логику
if (_startPosX + EntitySailboat.Step + _boatWidth < _pictureWidth)
{
_startPosX += (int)EntitySailboat.Step;
}
break;
//вниз
case DirectionType.Down:
// TODO: Продумать логику
if (_startPosY + EntitySailboat.Step + _boatHeight < _pictureHeight)
{
_startPosY += (int)EntitySailboat.Step;
}
break;
}
}
@ -119,7 +125,7 @@ namespace Sailboat
Brush additionalBrush = new
SolidBrush(EntitySailboat.AdditionalColor);
// обвесы
if (EntitySailboat.BodyKit)
/*if (EntitySailboat.BodyKit)
{
g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20);
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20,
@ -167,6 +173,7 @@ namespace Sailboat
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);
@ -175,58 +182,42 @@ namespace Sailboat
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);
//задние фары
Brush brRed = new SolidBrush(Color.Red);
g.FillEllipse(brRed, _startPosX + 10, _startPosY + 5, 20, 20);
g.FillEllipse(brRed, _startPosX + 10, _startPosY + 35, 20,
20);
//передние фары
Brush brYellow = new SolidBrush(Color.Yellow);
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
20);
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
20);
//кузов
Brush br = new SolidBrush(EntitySailboat.BodyColor);
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
//стекла
Brush brBlue = new SolidBrush(Color.LightBlue);
g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 10, 5,
40);
g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 10, 5,
40);
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 8, 35,
2);
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 51, 35,
2);
//выделяем рамкой крышу
g.DrawRectangle(pen, _startPosX + 35, _startPosY + 10, 35,
40);
g.DrawRectangle(pen, _startPosX + 75, _startPosY + 15, 25,
30);
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 15, 15,
30);
// спортивная линия
if (EntitySailboat.SportLine)
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);*/
//основной корпус парусника
Point[] hull = new Point[]
{
g.FillRectangle(additionalBrush, _startPosX + 75,
_startPosY + 23, 25, 15);
g.FillRectangle(additionalBrush, _startPosX + 35,
_startPosY + 23, 35, 15);
g.FillRectangle(additionalBrush, _startPosX + 10,
_startPosY + 23, 20, 15);
}
// крыло
if (EntitySailboat.Wing)
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)
};
g.DrawPolygon(pen, hull);
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 120, 90, 40);
//усиленный корпус парусника
Point[] hullCooler = new Point[]
{
g.FillRectangle(additionalBrush, _startPosX, _startPosY
+ 5, 10, 50);
g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10,
50);
}
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.DrawPolygon(pen, hullCooler);
//парус
g.DrawLine(pen, new Point(_startPosX + 95, _startPosY + 140),new Point (_startPosX + 95, _startPosY + 20));
Point[] sail = new Point[]
{
new Point(_startPosX + 95, _startPosY + 20),
new Point(_startPosX + 160, _startPosY + 140),
new Point(_startPosX + 45, _startPosY + 140)
};
g.DrawPolygon(pen, sail);
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Sailboat
{
internal class EntitySailboat
public class EntitySailboat
{
/// <summary>
/// Скорость

View File

@ -57,6 +57,7 @@
this.buttonCreate.TabIndex = 1;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonLeft
//
@ -68,6 +69,7 @@
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 2;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonUp
//
@ -79,6 +81,7 @@
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonRight
//
@ -90,6 +93,7 @@
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 4;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonDown
//
@ -101,6 +105,7 @@
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
//
// FormSailboat
//

View File

@ -2,9 +2,62 @@ namespace Sailboat
{
public partial class FormSailboat : Form
{
private DrawingSailboat? _drawingSailboat;
public FormSailboat()
{
InitializeComponent();
}
private void Draw()
{
if (_drawingSailboat == null)
{
return;
}
Bitmap bmp = new(pictureBoxSailboat.Width,
pictureBoxSailboat.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingSailboat.DrawTransport(gr);
pictureBoxSailboat.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
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)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailboat.Width, pictureBoxSailboat.Height);
_drawingSailboat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingSailboat == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingSailboat.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawingSailboat.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawingSailboat.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawingSailboat.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
}
}
}