Создание класса Drawning, размещение элементов на форме

This commit is contained in:
malimova 2023-10-01 14:43:56 +04:00
parent 6e1fa7e9ec
commit ff4b2f7e71
15 changed files with 528 additions and 46 deletions

View File

@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project> </Project>

View File

@ -6,7 +6,11 @@ using System.Threading.Tasks;
namespace AirBomber namespace AirBomber
{ {
internal class Direction public enum DirectionType
{ {
Up = 1,
Down = 2,
Left = 3,
Right = 4
} }
} }

View File

@ -0,0 +1,211 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
public class DrawningAirBomber
{
public EntityAirBomber? EntityAirBomber { get; private set; }
private int _pictureWidth;
private int _pictureHeight;
/// <summary>
/// Левая координата прорисовки бобмбардировщика
/// </summary>
private int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки бомбардировщика
/// </summary>
private int _startPosY;
/// <summary>
/// Ширина прорисовки бомбардировщика
/// </summary>
private readonly int _bomberWidth = 110;
/// <summary>
/// Высота прорисовки бомбардировщика
/// </summary>
private readonly int _bomberHeight = 60;
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bombs">Признак наличия бомб</param>
/// <param name="fuelTanks">Признак наличия топливных баков</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 bombs, bool fuelTanks, int width, int height)
{
// TODO: Продумать проверки
_pictureWidth = width;
_pictureHeight = height;
EntityAirBomber = new EntityAirBomber();
EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, bombs, fuelTanks);
return true;
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
// TODO: Изменение x, y
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (EntityAirBomber == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX - EntityAirBomber.Step > 0)
{
_startPosX -= (int)EntityAirBomber.Step;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - EntityAirBomber.Step > 0)
{
_startPosY -= (int)EntityAirBomber.Step;
}
break;
// вправо
case DirectionType.Right:
// TODO: Продумать логику
break;
//вниз
case DirectionType.Down:
// TODO: Продумать логику
break;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{
if (EntityAirBomber == null)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new
SolidBrush(EntityAirBomber.AdditionalColor);
// обвесы
if (EntityAirBomber.Bombs)
{
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);
//задние фары
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(EntityAirBomber.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 (EntityAirBomber.FuelTanks)
{
g.FillRectangle(additionalBrush, _startPosX, _startPosY
+ 5, 10, 50);
g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10,
50);
}
}
}
}

View File

@ -24,16 +24,16 @@ namespace AirBomber
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bombs">Признак наличия бомб</param> /// <param name="bombs">Признак наличия бомб</param>
/// <param name="fueltanks">Признак наличия топливных баков</param> /// <param name="fuelTanks">Признак наличия топливных баков</param>
public void Init(int speed, double weight, Color bodyColor, Color public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bombs, bool fueltanks) additionalColor, bool bombs, bool fuelTanks)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
Bombs = bombs; Bombs = bombs;
FuelTanks = fueltanks; FuelTanks = fuelTanks;
} }
} }

View File

@ -1,39 +0,0 @@
namespace AirBomber
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 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)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// 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";
}
#endregion
}
}

View File

@ -0,0 +1,115 @@
namespace AirBomber
{
partial class FormAirBomber
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 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)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonCreate = new Button();
buttonDown = new Button();
buttonLeft = new Button();
buttonRight = new Button();
buttonUp = new Button();
SuspendLayout();
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(29, 479);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(148, 34);
buttonCreate.TabIndex = 0;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(842, 483);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 1;
buttonDown.UseVisualStyleBackColor = true;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(806, 483);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(878, 483);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 3;
buttonRight.UseVisualStyleBackColor = true;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(842, 447);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = true;
//
// FormAirBomber
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(986, 540);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonDown);
Controls.Add(buttonCreate);
Name = "FormAirBomber";
Text = "Form1";
ResumeLayout(false);
}
#endregion
private Button buttonCreate;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
private Button buttonUp;
}
}

View File

@ -1,8 +1,8 @@
namespace AirBomber namespace AirBomber
{ {
public partial class Form1 : Form public partial class FormAirBomber : Form
{ {
public Form1() public FormAirBomber()
{ {
InitializeComponent(); InitializeComponent();
} }

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -11,7 +11,7 @@ namespace AirBomber
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(new FormAirBomber());
} }
} }
} }

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AirBomber.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AirBomber.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrowDown {
get {
object obj = ResourceManager.GetObject("arrowDown", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrowLeft {
get {
object obj = ResourceManager.GetObject("arrowLeft", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrowRight {
get {
object obj = ResourceManager.GetObject("arrowRight", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrowUp {
get {
object obj = ResourceManager.GetObject("arrowUp", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -117,4 +117,17 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="arrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB