Контур гидроплана
This commit is contained in:
parent
8a3341f3ec
commit
02c51ae801
@ -11,7 +11,7 @@ namespace Hydroplane
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityHydroplane? EntitySportCar { get; private set; }
|
||||
public EntityHydroplane? EntityHydroplane { get; private set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -31,11 +31,11 @@ namespace Hydroplane
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _carWidth = 110;
|
||||
private readonly int _planeWidth = 175;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _carHeight = 60;
|
||||
private readonly int _planeHeight = 100;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
@ -43,23 +43,23 @@ namespace Hydroplane
|
||||
/// <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="boat">Признак наличия обвеса</param>
|
||||
/// <param name="bobber">Признак наличия антикрыла</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)
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool boat, bool bobber, int width, int height)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntitySportCar = new EntityHydroplane();
|
||||
EntitySportCar.Init(speed, weight, bodyColor, additionalColor,
|
||||
bodyKit, wing, sportLine);
|
||||
EntityHydroplane = new EntityHydroplane();
|
||||
EntityHydroplane.Init(speed, weight, bodyColor, additionalColor,
|
||||
boat, bobber);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
@ -71,13 +71,14 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntitySportCar == null)
|
||||
if (EntityHydroplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -85,49 +86,51 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntitySportCar.Step > 0)
|
||||
if (_startPosX - EntityHydroplane.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntitySportCar.Step;
|
||||
_startPosX -= (int)EntityHydroplane.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntitySportCar.Step > 0)
|
||||
if (_startPosY - EntityHydroplane.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntitySportCar.Step;
|
||||
_startPosY -= (int)EntityHydroplane.Step;
|
||||
}
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntitySportCar.Step + _carWidth < _pictureWidth)
|
||||
if (_startPosX + EntityHydroplane.Step + _planeWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntitySportCar.Step;
|
||||
_startPosX += (int)EntityHydroplane.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntitySportCar.Step + _carHeight < _pictureHeight)
|
||||
if (_startPosY + EntityHydroplane.Step + _planeHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntitySportCar.Step;
|
||||
_startPosY += (int)EntityHydroplane.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntitySportCar == null)
|
||||
if (EntityHydroplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(EntitySportCar.AdditionalColor);
|
||||
SolidBrush(EntityHydroplane.AdditionalColor);
|
||||
/*
|
||||
// обвесы
|
||||
if (EntitySportCar.BodyKit)
|
||||
if (EntityHydroplane.BodyKit)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20,
|
||||
@ -196,7 +199,7 @@ _startPosY + 1, 15, 15);
|
||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
|
||||
20);
|
||||
//кузов
|
||||
Brush br = new SolidBrush(EntitySportCar.BodyColor);
|
||||
Brush br = new SolidBrush(EntityHydroplane.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);
|
||||
@ -218,7 +221,7 @@ _startPosY + 1, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 15, 15,
|
||||
30);
|
||||
// спортивная линия
|
||||
if (EntitySportCar.SportLine)
|
||||
if (EntityHydroplane.SportLine)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 75,
|
||||
_startPosY + 23, 25, 15);
|
||||
@ -228,13 +231,58 @@ _startPosY + 1, 15, 15);
|
||||
_startPosY + 23, 20, 15);
|
||||
}
|
||||
// крыло
|
||||
if (EntitySportCar.Wing)
|
||||
if (EntityHydroplane.Wing)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX, _startPosY
|
||||
+ 5, 10, 50);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10,
|
||||
50);
|
||||
}
|
||||
*/
|
||||
//основа
|
||||
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 25, 125, 30);
|
||||
|
||||
//хвост
|
||||
g.DrawLine(pen, _startPosX + 5, _startPosY + 25, _startPosX + 5, _startPosY);
|
||||
g.DrawLine(pen, _startPosX + 55, _startPosY + 25, _startPosX + 5, _startPosY);
|
||||
|
||||
//нос
|
||||
g.DrawLine(pen, _startPosX + 130, _startPosY + 25, _startPosX + 160, _startPosY + 40);
|
||||
g.DrawLine(pen, _startPosX + 130, _startPosY + 55, _startPosX + 160, _startPosY + 40);
|
||||
g.DrawLine(pen, _startPosX + 130, _startPosY + 40, _startPosX + 160, _startPosY + 40);
|
||||
|
||||
//иллюминаторы
|
||||
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 30, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 30, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 30, 10, 10);
|
||||
|
||||
//крыло сбоку
|
||||
g.DrawEllipse(pen, _startPosX + 35, _startPosY + 43, 80, 7);
|
||||
|
||||
//ножки снизу
|
||||
g.DrawLine(pen, _startPosX + 65, _startPosY + 55, _startPosX + 65, _startPosY + 70);
|
||||
g.DrawLine(pen, _startPosX + 70, _startPosY + 55, _startPosX + 70, _startPosY + 70);
|
||||
g.DrawLine(pen, _startPosX + 125, _startPosY + 55, _startPosX + 125, _startPosY + 70);
|
||||
g.DrawLine(pen, _startPosX + 130, _startPosY + 55, _startPosX + 130, _startPosY + 70);
|
||||
|
||||
//лодка или колеса
|
||||
if (EntityHydroplane.Boat)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX + 55, _startPosY + 70, 100, 10);
|
||||
g.DrawLine(pen, _startPosX + 155, _startPosY + 70, _startPosX + 175, _startPosY + 70);
|
||||
g.DrawLine(pen, _startPosX + 175, _startPosY + 70, _startPosX + 155, _startPosY + 80);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 70, 15, 15);
|
||||
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 70, 15, 15);
|
||||
}
|
||||
|
||||
//поплавок
|
||||
if (EntityHydroplane.Bobber)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY + 21, 32, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,17 +25,13 @@ namespace Hydroplane
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// Признак (опция) наличия надувной лодки
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
public bool Boat { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// Признак (опция) наличия поплавка
|
||||
/// </summary>
|
||||
public bool Wing { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool SportLine { get; private set; }
|
||||
public bool Bobber { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
@ -47,19 +43,17 @@ namespace Hydroplane
|
||||
/// <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="boat">Признак наличия обвеса</param>
|
||||
/// <param name="bobber">Признак наличия антикрыла</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
additionalColor, bool boat, bool bobber)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Wing = wing;
|
||||
SportLine = sportLine;
|
||||
Boat = boat;
|
||||
Bobber = bobber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ namespace Hydroplane
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawningHydroplane? _drawningSportCar;
|
||||
private DrawningHydroplane? _drawningHydroplane;
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -16,14 +16,14 @@ namespace Hydroplane
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningSportCar == null)
|
||||
if (_drawningHydroplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxHydroplane.Width,
|
||||
pictureBoxHydroplane.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningSportCar.DrawTransport(gr);
|
||||
_drawningHydroplane.DrawTransport(gr);
|
||||
pictureBoxHydroplane.Image = bmp;
|
||||
}
|
||||
|
||||
@ -35,17 +35,16 @@ namespace Hydroplane
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningSportCar = new DrawningHydroplane();
|
||||
_drawningSportCar.Init(random.Next(100, 300),
|
||||
_drawningHydroplane = new DrawningHydroplane();
|
||||
_drawningHydroplane.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)),
|
||||
pictureBoxHydroplane.Width, pictureBoxHydroplane.Height);
|
||||
_drawningSportCar.SetPosition(random.Next(10, 100),
|
||||
_drawningHydroplane.SetPosition(random.Next(10, 100),
|
||||
random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
@ -57,7 +56,7 @@ namespace Hydroplane
|
||||
/// <param name="e"></param>
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningSportCar == null)
|
||||
if (_drawningHydroplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -65,16 +64,16 @@ namespace Hydroplane
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningSportCar.MoveTransport(DirectionType.Up);
|
||||
_drawningHydroplane.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningSportCar.MoveTransport(DirectionType.Down);
|
||||
_drawningHydroplane.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningSportCar.MoveTransport(DirectionType.Left);
|
||||
_drawningHydroplane.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningSportCar.MoveTransport(DirectionType.Right);
|
||||
_drawningHydroplane.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
|
Loading…
Reference in New Issue
Block a user