Сделал лаб01

This commit is contained in:
ivans 2024-06-13 11:53:21 +04:00
parent 7b7ccfde47
commit 0aae5667ec
6 changed files with 132 additions and 23 deletions

View File

@ -8,7 +8,7 @@ public class DrawingSeaplane
/// Класс-сущность
/// </summary>
public EntitySeaplane? EntitySeaplane { get; private set; }
public DrawingWindows Windows;
/// <summary>
/// Ширина окна
/// </summary>
@ -32,7 +32,7 @@ public class DrawingSeaplane
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
private readonly int _drawningSeaplaneWidth = 155;
private readonly int _drawningSeaplaneWidth = 160;
/// <summary>
/// Высота прорисовки автомобиля
@ -49,13 +49,15 @@ public class DrawingSeaplane
/// <param name="landingGear">Тип "шасси" (0 - поплавки, 1 - лодочный тип)</param>
/// <param name="radar">Признак наличия радара </param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar)
{
{
EntitySeaplane = new EntitySeaplane();
EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, landingGear, radar);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
Windows = new DrawingWindows();
Windows.WinNum = 0;
}
/// <summary>
@ -137,7 +139,7 @@ public class DrawingSeaplane
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntitySeaplane.Step > 0)
if (_startPosX.Value - EntitySeaplane.Step > 1)
{
_startPosX -= (int)EntitySeaplane.Step;
}
@ -149,7 +151,7 @@ public class DrawingSeaplane
_startPosY -= (int)EntitySeaplane.Step;
}
return true;
// вправо
//вправо
case DirectionType.Right:
if (_startPosX + (int)EntitySeaplane.Step < _pictureWidth - _drawningSeaplaneWidth)
@ -177,11 +179,12 @@ public class DrawingSeaplane
{
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Pen penKraya = new(Color.Black, 2);
Brush additionalBrush = new SolidBrush(EntitySeaplane.AdditionalColor);
Pen pen = new(Color.Black);
//Начинаем рисовать
//Полигон для хвоста
Point point1 = new Point(_startPosX.Value, _startPosY.Value);
@ -215,17 +218,6 @@ public class DrawingSeaplane
//Крыло
g.FillEllipse(brAdditional, _startPosX.Value + 45, _startPosY.Value + 43, 50, 7);
//Иллюминаторы
for (int i = 0; i < 80; i += 10)
{
g.FillEllipse(brWhity, _startPosX.Value + 30 + i, _startPosY.Value + 34, 6, 6);
}
//Поплавки
if (EntitySeaplane.LandingGear)
@ -253,7 +245,7 @@ public class DrawingSeaplane
}
//Пилоты
g.FillEllipse(brWhity, _startPosX.Value + 115, _startPosY.Value + 34, 20, 8);
Windows.DrawWindows(g, _startPosX.Value + 5, _startPosY.Value + 5);
}
}

View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectSeaplane;
public class DrawingWindows
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntitySeaplane? EntitySeaplane { get; private set; }
/// <summary>
/// Количество иллюминаторов
/// </summary>
private NumberOfWindows numberOfWindows;
public int WinNum
{
set
{
if (value == 10 || value < 15)
{
numberOfWindows = NumberOfWindows.TenWindows;
}
else if (value == 20 || (value >= 15 && value < 25))
{
numberOfWindows = NumberOfWindows.TwentyWindows;
}
else if (value == 30 || (value >= 25 && value < 31))
{
numberOfWindows = NumberOfWindows.ThirtyWindows;
}
}
}
/// <summary>
/// Прорисовка доп класса
/// </summary>
/// <param name="g"></param>
public void DrawWindows(Graphics g, int _startPosX, int _startPosY)
{
Brush brWhity = new SolidBrush(Color.GhostWhite);
switch (numberOfWindows)
{
case NumberOfWindows.TenWindows:
for (int i = 0; i < 60; i += 6)
{
g.FillEllipse(brWhity, _startPosX + 30 + i, _startPosY + 26, 4, 4);
}
break;
case NumberOfWindows.TwentyWindows:
for (int j = 0; j < 5; j += 4)
{
for (int i = 0; i < 60; i += 6)
{
g.FillEllipse(brWhity, _startPosX + 30 + i, _startPosY + 26 + j, 4, 4);
}
}
break;
case NumberOfWindows.ThirtyWindows:
for (int j = 0; j < 9; j += 4)
{
for (int i = 0; i < 60; i += 6)
{
g.FillEllipse(brWhity, _startPosX + 30 + i, _startPosY + 26 + j, 4, 4);
}
}
break;
}
}
}

View File

@ -1,4 +1,6 @@
namespace ProjectSeaplane;
using static System.Windows.Forms.LinkLabel;
namespace ProjectSeaplane;
/// <summary>
/// Класс-сущность Гидросамолета
/// </summary>
@ -49,6 +51,5 @@ public class EntitySeaplane
AdditionalColor = additionalColor;
LandingGear = landingGear;
Radar = radar;
}
}

View File

@ -34,7 +34,9 @@
buttonDown = new Button();
buttonUp = new Button();
buttonRight = new Button();
numericUpDownNumberOfWindows = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownNumberOfWindows).BeginInit();
SuspendLayout();
//
// pictureBoxSeaplane
@ -109,11 +111,23 @@
buttonRight.UseVisualStyleBackColor = false;
buttonRight.Click += ButtonMove_Click;
//
// numericUpDownNumberOfWindows
//
numericUpDownNumberOfWindows.Increment = new decimal(new int[] { 10, 0, 0, 0 });
numericUpDownNumberOfWindows.Location = new Point(93, 349);
numericUpDownNumberOfWindows.Maximum = new decimal(new int[] { 30, 0, 0, 0 });
numericUpDownNumberOfWindows.Minimum = new decimal(new int[] { 10, 0, 0, 0 });
numericUpDownNumberOfWindows.Name = "numericUpDownNumberOfWindows";
numericUpDownNumberOfWindows.Size = new Size(47, 23);
numericUpDownNumberOfWindows.TabIndex = 8;
numericUpDownNumberOfWindows.Value = new decimal(new int[] { 10, 0, 0, 0 });
//
// FormSeaplane
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(590, 379);
Controls.Add(numericUpDownNumberOfWindows);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(buttonDown);
@ -123,6 +137,7 @@
Name = "FormSeaplane";
Text = "Гидросамолет";
((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownNumberOfWindows).EndInit();
ResumeLayout(false);
}
@ -134,5 +149,6 @@
private Button buttonDown;
private Button buttonUp;
private Button buttonRight;
private NumericUpDown numericUpDownNumberOfWindows;
}
}

View File

@ -46,7 +46,7 @@
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
_drawingSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
_drawingSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
_drawingSeaplane.Windows.WinNum = (int)numericUpDownNumberOfWindows.Value;
Draw();
}
/// <summary>
@ -84,7 +84,5 @@
Draw();
}
}
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectSeaplane;
/// <summary>
/// Количество иллюминаторов
/// </summary>
public enum NumberOfWindows
{
/// <summary>
/// 10 иллюминаторов
/// </summary>
TenWindows,
/// <summary>
/// 20 иллюминаторов
/// </summary>
TwentyWindows,
/// <summary>
/// 30 иллюминаторов
/// </summary>
ThirtyWindows
}