ISEbd-22. Baygulov A.A. Lab work 1 (hard) #4

Closed
tellsense wants to merge 7 commits from laba1_H into main
5 changed files with 111 additions and 5 deletions
Showing only changes of commit 71063352db - Show all commits

View File

@ -13,8 +13,9 @@ namespace ProjectElectricLocomotive
private int _pictureHeight;
private int _startPosX;
private int _startPosY;
private readonly int _locomWidth = 80;
private readonly int _locomWidth = 150;
private readonly int _locomHeight = 52;
private DrawningWheels drawningWheels;
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Цвет кузова</param>
@ -24,7 +25,7 @@ namespace ProjectElectricLocomotive
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph, bool compartment, int width, int height)
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph, bool compartment, int wheels, int width, int height)
{
if (width < _locomWidth || height < _locomHeight)
{
@ -33,8 +34,13 @@ namespace ProjectElectricLocomotive
_pictureWidth = width;
_pictureHeight = height;
EntityElectricLocomotive = new EntityElectricLocomotive();
EntityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, pantograph, compartment);
EntityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, pantograph, compartment, wheels);
drawningWheels = new DrawningWheels();
drawningWheels.SetAmount(wheels);
return true;
}
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
@ -168,6 +174,38 @@ namespace ProjectElectricLocomotive
g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 45, 10, 10);
g.FillEllipse(blackBrush, _startPosX + 65, _startPosY + 45, 10, 10);
// Вагон
g.FillPolygon(additionalBrush, new Point[]
{
new Point(_startPosX + 90, _startPosY + 25),
new Point(_startPosX + 95, _startPosY + 20),
new Point(_startPosX + 145, _startPosY + 20),
new Point(_startPosX + 150, _startPosY + 25),
new Point(_startPosX + 150, _startPosY + 45),
new Point(_startPosX + 90, _startPosY + 45),
new Point(_startPosX + 90, _startPosY + 25),
}
);
g.DrawPolygon(pen, new Point[]
{
new Point(_startPosX + 90, _startPosY + 25),
new Point(_startPosX + 95, _startPosY + 20),
new Point(_startPosX + 145, _startPosY + 20),
new Point(_startPosX + 150, _startPosY + 25),
new Point(_startPosX + 150, _startPosY + 45),
new Point(_startPosX + 90, _startPosY + 45),
new Point(_startPosX + 90, _startPosY + 25),
}
);
//Окна
g.DrawLine(pen, _startPosX + 80, _startPosY + 40, _startPosX + 90, _startPosY + 40);
g.FillRectangle(windows, _startPosX + 95, _startPosY + 30, 10, 5);
g.FillRectangle(windows, _startPosX + 115, _startPosY + 30, 10, 5);
g.FillRectangle(windows, _startPosX + 135, _startPosY + 30, 10, 5);
//Колеса
drawningWheels.DrawWheels(g, _startPosX, _startPosY);
}
}
}

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive
{
internal class DrawningWheels
{
private Wheels amount;
public void SetAmount(int a)
Review

Требовалось сделать свойство числовое

Требовалось сделать свойство числовое
{
if (a == 2)
{
amount = Wheels.Two;
}
else if (a == 3)
{
amount = Wheels.Three;
}
else if (a == 4)
{
amount = Wheels.Four;
}
}
public void DrawWheels(Graphics g, int _startPosX, int _startPosY)
{
Brush wheelsColor = new SolidBrush(Color.Black);
if (amount == Wheels.Two)
g.FillEllipse(wheelsColor, _startPosX + 90, _startPosY + 45, 10, 10);
g.FillEllipse(wheelsColor, _startPosX + 100, _startPosY + 45, 10, 10);
if (amount == Wheels.Three)
{
g.FillEllipse(wheelsColor, _startPosX + 90, _startPosY + 45, 10, 10);
Review

Имеется дублирующийся код

Имеется дублирующийся код
g.FillEllipse(wheelsColor, _startPosX + 100, _startPosY + 45, 10, 10);
g.FillEllipse(wheelsColor, _startPosX + 140, _startPosY + 45, 10, 10);
}
if (amount == Wheels.Four)
{
g.FillEllipse(wheelsColor, _startPosX + 90, _startPosY + 45, 10, 10);
g.FillEllipse(wheelsColor, _startPosX + 100, _startPosY + 45, 10, 10);
g.FillEllipse(wheelsColor, _startPosX + 140, _startPosY + 45, 10, 10);
g.FillEllipse(wheelsColor, _startPosX + 130, _startPosY + 45, 10, 10);
}
}
}
}

View File

@ -14,6 +14,7 @@ namespace ProjectElectricLocomotive
public Color AdditionalColor { get; private set; }
public bool Pantograph { get; private set; }
public bool Compartment { get; private set; }
public int Wheels { get; private set; }
public double Step => (double)Speed * 100 / Weight;
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес локомотива</param>
@ -21,7 +22,7 @@ namespace ProjectElectricLocomotive
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="pantograph">Признак наличия токоприемника</param>
/// <param name="compartment">Признак наличия отсеков под электрические батареи</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph, bool compartment)
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph, bool compartment, int wheels)
{
Speed = speed;
Weight = weight;
@ -29,6 +30,7 @@ namespace ProjectElectricLocomotive
AdditionalColor = additionalColor;
Pantograph = pantograph;
Compartment = compartment;
Wheels = wheels;
}
}
}

View File

@ -30,7 +30,8 @@ namespace ProjectElectricLocomotive
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)),
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
random.Next(1, 5),
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height) ; ;
_drawningElectricLocomotive.SetPosition(random.Next(1, 100), random.Next(1, 100));
Draw();
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive
{
public enum Wheels
{
Two,
Three,
Four
}
}