PIbd-13_Fomichev_V.S_LabWork01 Simple #1

Closed
slavaxom9k wants to merge 13 commits from labwork01 into main
7 changed files with 380 additions and 44 deletions
Showing only changes of commit 1043d3d164 - Show all commits

View File

@ -1,14 +1,14 @@
namespace AntiAircraftGun
{
partial class Form1
partial class AntiAircraftGun
{
/// <summary>
/// Required designer variable.
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// 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)
@ -23,15 +23,22 @@
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
SuspendLayout();
//
// AntiAircraftGun
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Name = "AntiAircraftGun";
Text = "Зенитная установка";
Load += AntiAircraftGun_Load;
ResumeLayout(false);
}
#endregion

View File

@ -0,0 +1,25 @@
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;
namespace AntiAircraftGun
{
public partial class AntiAircraftGun : Form
{
public AntiAircraftGun()
{
InitializeComponent();
}
private void AntiAircraftGun_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -1,17 +1,17 @@
<?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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -0,0 +1,24 @@

namespace AntiAircraftGun;
/// <summary>
/// Направление перемещения
/// </summary>
public enum DirectionType
Review

Имя файла не соответствует имени элемента проекта

Имя файла не соответствует имени элемента проекта
{
/// <summary>
/// Вверх
/// </summary>
Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4,
}

View File

@ -0,0 +1,232 @@
namespace AntiAircraftGun;
/// <summary>
/// Класс отвечающий за прорисовку и перемещение объекта - сущности
/// </summary>
public class DrawingAntiAircraftGun
{
/// <summary>
/// Класс - сущность
/// </summary>
public EntityAntiAircraftGun? EntityAntiAircraftGun { get; 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 _drawningGunWidth = 130;
/// <summary>
/// Высота прорисовки гидросамолета
/// </summary>
private readonly int _drawningGunHeight = 50;
/// <summary>
/// Инициализация полей объекта-класса гидросамолета
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Наличие обвеса</param>
/// <param name="tower">Наличие башни</param>
/// <param name="radar">Наличие радара</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tower, bool radar)
{
EntityAntiAircraftGun = new EntityAntiAircraftGun();
EntityAntiAircraftGun.Init(speed, weight, bodyColor, additionalColor, bodyKit, tower, radar);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// Установка границ поля
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
public bool SetPictureSize(int width, int height)
{
// TODO проверка, что объект "влезает" в размеры поля
// если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена
if (width < _drawningGunWidth || height < _drawningGunHeight) { return false; };
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX != null || _startPosY != null)
{
if (_startPosX + _drawningGunWidth > _pictureWidth)
{
_startPosX = -_drawningGunWidth + _pictureWidth;
}
else if (_startPosX < 0)
{
_startPosX = 0;
}
if (_startPosY + _drawningGunHeight > _pictureHeight)
{
_startPosY = -_drawningGunHeight + _pictureHeight;
}
else if (_startPosY < 0)
{
_startPosY = 0;
}
}
return true;
}
/// <summary>
/// Установка позиций
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void SetPosition(int x, int y)
{
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
// то надо изменить координаты, чтобы он оставался в этих границах
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
if (x + _drawningGunWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningGunWidth;
}
else if (x < 0)
{
_startPosX = 0;
}
else
{
_startPosX = x;
}
if (y + _drawningGunHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningGunHeight;
}
else if (y < 0)
{
_startPosY = 0;
}
else
{
_startPosY = y;
}
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
/// <returns></returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityAntiAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
switch (direction)
{
case DirectionType.Left:
if (_startPosX.Value - EntityAntiAircraftGun.Step > 0)
{
_startPosX -= (int)EntityAntiAircraftGun.Step;
}
return true;
case DirectionType.Right:
if (_startPosX.Value + _drawningGunWidth + EntityAntiAircraftGun.Step < _pictureWidth)
{
_startPosX += (int)EntityAntiAircraftGun.Step;
}
return true;
case DirectionType.Down:
if (_startPosY.Value + _drawningGunHeight + EntityAntiAircraftGun.Step < _pictureHeight)
{
_startPosY += (int)EntityAntiAircraftGun.Step;
}
return true;
case DirectionType.Up: //вверх
if (_startPosY - EntityAntiAircraftGun.Step > 0)
{
_startPosY -= (int)EntityAntiAircraftGun.Step;
}
return true;
default:
return false;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{
if (EntityAntiAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Pen additionalpen = new(EntityAntiAircraftGun.AdditionalColor);
//корпус гидросамолета
Brush br = new SolidBrush(EntityAntiAircraftGun.BodyColor);
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 20, 100, 20);
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 20, 100, 20);
//крыло
Brush darkBrush = new SolidBrush(Color.Black);
g.FillRectangle(darkBrush, _startPosX.Value + 27, _startPosY.Value + 29, 40, 3);
//хвостовое крыло
g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 20, _startPosX.Value, _startPosY.Value);
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value + 20, _startPosY.Value + 20);
//заднее поперечное крыло
Brush additionalBrush = new SolidBrush(EntityAntiAircraftGun.AdditionalColor);
g.FillEllipse(darkBrush, _startPosX.Value - 7, _startPosY.Value + 15, 20, 5);
//нос самолёта
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 130, _startPosY.Value + 30);
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 40, _startPosX.Value + 130, _startPosY.Value + 30);
g.DrawLine(pen, _startPosX.Value + 130, _startPosY.Value + 30, _startPosX.Value + 100, _startPosY.Value + 30);
//задние шасси
g.DrawLine(pen, _startPosX.Value + 21, _startPosY.Value + 40, _startPosX.Value + 21, _startPosY.Value + 45);
g.FillEllipse(darkBrush, _startPosX.Value + 15, _startPosY.Value + 45, 6, 6);
g.FillEllipse(darkBrush, _startPosX.Value + 21, _startPosY.Value + 45, 6, 6);
//переднее шасси
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 40, _startPosX.Value + 90, _startPosY.Value + 45);
g.FillEllipse(darkBrush, _startPosX.Value + 87, _startPosY.Value + 45, 6, 6);
// поплавки
if (EntityAntiAircraftGun.Tower)
{
Brush br2 = new SolidBrush(Color.Red);
g.FillRectangle(br2, _startPosX.Value + 10, _startPosY.Value + 48, 90, 5);
}
// надувная лодка
if (EntityAntiAircraftGun.Radar)
{
g.FillRectangle(additionalBrush, _startPosX.Value + 38, _startPosY.Value + 38, 22, 8);
}
}
}

View File

@ -0,0 +1,58 @@
namespace AntiAircraftGun;
/// <summary>
/// Класс-сущность Зенитная установка
/// </summary>
public class EntityAntiAircraftGun
{ /// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Дополниетльный цвет
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Наличие обвеса
/// </summary>
public bool BodyKit { get; private set; }
/// <summary>
/// Наличие башни
/// </summary>
public bool Tower { get; private set; }
/// <summary>
/// Наличие радара
/// </summary>
public bool Radar { get; private set; }
/// <summary>
/// Шаг перемещения гидросамолета
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса гидросамолета
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Наличие обвеса</param>
/// <param name="tower">Наличие башни</param>
/// <param name="radar">Наличие радара</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tower, bool radar)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
BodyKit = bodyKit;
Tower = tower;
Radar = radar;
}
}

View File

@ -1,10 +0,0 @@
namespace AntiAircraftGun
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}