Kasatkin S.P. LabWork_Hard01 #1

Closed
Sem730 wants to merge 2 commits from LabWork01 into main
6 changed files with 154 additions and 16 deletions
Showing only changes of commit 2578801ab2 - Show all commits

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLocomotive_Hard
{
internal enum CountWheel
{
Two = 2,
Three = 3,
Four = 4,
}
}

View File

@ -15,6 +15,7 @@ namespace ProjectLocomotive_Hard
/// Класс-сущность
/// </summary>
public EntityLocomotive Locomotivе { private set; get; }
public DrawningLocomotiveWheel DrawningWheel { get; private set; }
/// <summary>
/// Левая координата отрисовки локомотива
/// </summary>
@ -34,7 +35,7 @@ namespace ProjectLocomotive_Hard
/// <summary>
/// Ширина отрисовки локомотива
/// </summary>
private readonly int _LocWidth = 80;
private readonly int _LocWidth = 140;
/// <summary>
/// Высота отрисовки локомотива
/// </summary>
@ -49,6 +50,8 @@ namespace ProjectLocomotive_Hard
{
Locomotivе = new EntityLocomotive();
Locomotivе.Init(speed, weight, bodyColor);
DrawningWheel = new();
DrawningWheel.SetCountWheel = 4;
}
/// <summary>
/// Установка позиции автомобиля
@ -128,7 +131,6 @@ namespace ProjectLocomotive_Hard
}
Pen pen = new(Color.Black);
// кузов электролокомотива (верхняя часть)
//g.DrawRectangle(pen, _startPosX - 1, _startPosY - 1, 80, 30);
g.DrawLine(pen, _startPosX + 7, _startPosY, _startPosX + 80, _startPosY);
g.DrawLine(pen, _startPosX + 80, _startPosY, _startPosX + 80, _startPosY + 15);
g.DrawLine(pen, _startPosX + 80, _startPosY + 15, _startPosX + 2, _startPosY + 15);
@ -153,6 +155,12 @@ namespace ProjectLocomotive_Hard
g.DrawLine(pen, _startPosX + 30, _startPosY + 8, _startPosX + 30, _startPosY + 25);
g.DrawLine(pen, _startPosX + 30, _startPosY + 25, _startPosX + 20, _startPosY + 25);
g.DrawLine(pen, _startPosX + 20, _startPosY + 25, _startPosX + 20, _startPosY + 6);
//тележка
g.DrawLine(pen, _startPosX + 80, _startPosY + 25, _startPosX + 140, _startPosY + 25);
g.DrawLine(pen, _startPosX + 140, _startPosY + 25, _startPosX + 140, _startPosY + 10);
g.DrawLine(pen, _startPosX + 140, _startPosY + 10, _startPosX + 90, _startPosY + 10);
g.DrawLine(pen, _startPosX + 90, _startPosY + 10, _startPosX + 90, _startPosY + 25);
DrawningWheel.DrawningWheel(g, _startPosX, _startPosY);
}
/// <summary>
/// Смена границ формы отрисовки

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLocomotive_Hard
{
/// <summary>
/// Класс-дополнение к отвечающий за число колёс и их отрисовку
/// </summary>
internal class DrawningLocomotiveWheel
{
/// <summary>Приватное поле содержащие текущее количество палуб</summary>
private CountWheel _countWheel;
/// <summary>
/// Открытое свойство, через которое можно в поле-перечисление занести значение
/// </summary>
public int SetCountWheel
{
set
{
switch (value)
{
case 2:
_countWheel = CountWheel.Two;
break;
case 3:
_countWheel = CountWheel.Three;
break;
case 4:
_countWheel = CountWheel.Four;
break;
default:
_countWheel = CountWheel.Two;
break;
}
}
}
/// <summary>Отрисовывает колёса</summary>
/// <param name="g">The g.</param>
///// <param name="colorDecks">Цвет колёс.</param>
/// <param name="PosX">начальная позиция по x</param>
/// <param name="PosY">начальная позиция по y</param>
public void DrawningWheel(Graphics g, float PosX, float PosY)
{
if ((int)_countWheel == 2)
{
Brush brr = new SolidBrush(Color.Green);
g.FillEllipse(brr, PosX + 95, PosY + 25, 15, 15);
g.FillEllipse(brr, PosX + 120, PosY + 25, 15, 15);
}
if ((int)_countWheel == 3)
{
Brush brr = new SolidBrush(Color.Blue);
g.FillEllipse(brr, PosX + 92, PosY + 25, 13, 13);
g.FillEllipse(brr, PosX + 110, PosY + 25, 13, 13);
g.FillEllipse(brr, PosX + 128, PosY + 25, 13, 13);
}
if ((int)_countWheel == 4)
{
Brush brr = new SolidBrush(Color.HotPink);
g.FillEllipse(brr, PosX + 90, PosY + 25, 10, 10);
g.FillEllipse(brr, PosX + 103, PosY + 25, 10, 10);
g.FillEllipse(brr, PosX + 116, PosY + 25, 10, 10);
g.FillEllipse(brr, PosX + 129, PosY + 25, 10, 10);
}
}
}
}

View File

@ -38,8 +38,12 @@
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.labelDecksCount = new System.Windows.Forms.Label();
this.countDecksBox = new System.Windows.Forms.NumericUpDown();
this.toolStripStatusCountDecks = new System.Windows.Forms.ToolStripStatusLabel();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
this.statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.countDecksBox)).BeginInit();
this.SuspendLayout();
//
// pictureBoxLocomotive
@ -47,14 +51,14 @@
this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0);
this.pictureBoxLocomotive.Name = "pictureBoxLocomotive";
this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 418);
this.pictureBoxLocomotive.Size = new System.Drawing.Size(959, 418);
this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxLocomotive.TabIndex = 0;
this.pictureBoxLocomotive.TabStop = false;
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(12, 375);
this.buttonCreate.Location = new System.Drawing.Point(404, 370);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(93, 30);
this.buttonCreate.TabIndex = 2;
@ -67,7 +71,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ProjectLocomotive_Hard.Properties.Resources.up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(675, 339);
this.buttonUp.Location = new System.Drawing.Point(834, 339);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 3;
@ -80,7 +84,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectLocomotive_Hard.Properties.Resources.left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(639, 374);
this.buttonLeft.Location = new System.Drawing.Point(798, 374);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4;
@ -93,7 +97,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ProjectLocomotive_Hard.Properties.Resources.down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(675, 373);
this.buttonDown.Location = new System.Drawing.Point(834, 373);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 6;
@ -106,7 +110,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectLocomotive_Hard.Properties.Resources.right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(711, 375);
this.buttonRight.Location = new System.Drawing.Point(870, 375);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5;
@ -138,17 +142,56 @@
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.toolStripStatusLabelBodyColor,
this.toolStripStatusCountDecks});
this.statusStrip.Location = new System.Drawing.Point(0, 418);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 32);
this.statusStrip.Size = new System.Drawing.Size(959, 32);
this.statusStrip.TabIndex = 1;
//
// labelDecksCount
//
this.labelDecksCount.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.labelDecksCount.AutoSize = true;
this.labelDecksCount.Location = new System.Drawing.Point(13, 373);
this.labelDecksCount.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labelDecksCount.Name = "labelDecksCount";
this.labelDecksCount.Size = new System.Drawing.Size(162, 25);
this.labelDecksCount.TabIndex = 9;
this.labelDecksCount.Text = "Количество колёс:";
//
// countDecksBox
//
this.countDecksBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.countDecksBox.Location = new System.Drawing.Point(195, 367);
this.countDecksBox.Margin = new System.Windows.Forms.Padding(4);
this.countDecksBox.Maximum = new decimal(new int[] {
4,
0,
0,
0});
this.countDecksBox.Name = "countDecksBox";
this.countDecksBox.Size = new System.Drawing.Size(188, 31);
this.countDecksBox.TabIndex = 10;
this.countDecksBox.Value = new decimal(new int[] {
2,
0,
0,
0});
//
// toolStripStatusCountDecks
//
this.toolStripStatusCountDecks.Name = "toolStripStatusCountDecks";
this.toolStripStatusCountDecks.Size = new System.Drawing.Size(162, 25);
this.toolStripStatusCountDecks.Text = "Количество колёс:";
//
// FormLocomotive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.ClientSize = new System.Drawing.Size(959, 450);
this.Controls.Add(this.countDecksBox);
this.Controls.Add(this.labelDecksCount);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
@ -161,9 +204,9 @@
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.countDecksBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
@ -178,5 +221,8 @@
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private StatusStrip statusStrip;
private Label labelDecksCount;
private NumericUpDown countDecksBox;
private ToolStripStatusLabel toolStripStatusCountDecks;
}
}

View File

@ -13,12 +13,10 @@ namespace ProjectLocomotive_Hard
public partial class FormLocomotive : Form
{
private DrawningLocomotive _elloc;
public FormLocomotive()
{
InitializeComponent();
}
/// <summary>
/// Метод прорисовки электролокомотива
/// </summary>
@ -34,16 +32,17 @@ namespace ProjectLocomotive_Hard
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_elloc = new DrawningLocomotive();
_elloc.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_elloc.DrawningWheel.SetCountWheel = ((int)countDecksBox.Value);
_elloc.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_elloc.Locomotivе.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_elloc.Locomotivе.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {_elloc.Locomotivе.BodyColor.Name}";
toolStripStatusCountDecks.Text = $"Количество колёс: {(int)countDecksBox.Value}";
Draw();
}
/// <summary>

View File

@ -14,5 +14,4 @@ namespace ProjectLocomotive_Hard
Application.Run(new FormLocomotive());
}
}
}