lab 1 complicate is done

This commit is contained in:
vladimir_zinovev 2023-12-14 23:51:30 +04:00
parent df69837593
commit 6c4b3a3447
6 changed files with 105 additions and 13 deletions

View File

@ -13,6 +13,7 @@ namespace ProjectTank
/// Класс-сущность
/// </summary>
public EntityTank? _EntityTank { get; private set; }
public DrawningWheelers? DrawningWheelersVariation;
/// <summary>
/// Ширина окна
/// </summary>
@ -48,7 +49,7 @@ namespace ProjectTank
/// <param name="height">Высота картинки</param>
/// <returns>true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах</returns>
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor,
bool gun, bool machineGun, int width, int height)
bool gun, bool machineGun, int width, int height, int _numWheelers)
{
_pictureWidth = width;
_pictureHeight = height;
@ -58,7 +59,9 @@ namespace ProjectTank
return false;
}
_EntityTank = new EntityTank();
_EntityTank.Init(speed, weight, gun, machineGun, bodyColor, additionalColor);
_EntityTank.Init(speed, weight, gun, machineGun, bodyColor, additionalColor, _numWheelers);
DrawningWheelersVariation = new DrawningWheelers();
DrawningWheelersVariation.SomeProperty = _numWheelers;
return true;
}
/// <summary>
@ -132,7 +135,6 @@ namespace ProjectTank
return;
}
Pen pen = new(Color.Black, 3);
Pen penGray = new(Color.Gray, 4);
Brush grayColorBrush = new SolidBrush(Color.Gray);
Brush blackColorBrush = new SolidBrush(Color.Black);
Brush additionalBrush = new SolidBrush(_EntityTank.AdditionalColor);
@ -142,14 +144,11 @@ namespace ProjectTank
// гусеницы
g.DrawEllipse(pen, _startPosX+14, _startPosY+44, 151, 31);
g.FillEllipse(blackColorBrush, _startPosX + 15, _startPosY + 45, 150, 30);
g.DrawEllipse(penGray, _startPosX + 24, _startPosY + 54, 10, 10);
g.DrawEllipse(penGray, _startPosX + 144, _startPosY + 54, 10, 10);
g.DrawEllipse(penGray, _startPosX + 44, _startPosY + 59, 10, 10);
g.DrawEllipse(penGray, _startPosX + 124, _startPosY + 59, 10, 10);
g.DrawEllipse(penGray, _startPosX + 64, _startPosY + 61, 10, 10);
g.DrawEllipse(penGray, _startPosX + 104, _startPosY + 61, 10, 10);
g.DrawEllipse(penGray, _startPosX + 84, _startPosY + 62, 10, 10);
// Кузов
//катки
DrawningWheelersVariation.Draw(_startPosX, _startPosY, g);
// Кузов
g.DrawRectangle(pen, _startPosX + 19, _startPosY + 34, 141, 21);
g.FillRectangle(bodyBrush, _startPosX+20, _startPosY+35, 140, 20);

View File

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTank
{
public class DrawningWheelers
{
private WheelersDirection numWheelers;
public int? SomeProperty
{
set
{
switch (value)
{
case 4:
numWheelers = WheelersDirection.FourthWheelers;
break;
case 5:
numWheelers = WheelersDirection.FifthWheelers;
break;
case 6:
numWheelers = WheelersDirection.SixthWheelers;
break;
default:
numWheelers = WheelersDirection.FourthWheelers;
MessageBox.Show("Неверное количество катков!");
break;
}
}
}
public void Draw(int _startPosX, int _startPosY, Graphics g)
{
Pen penGray = new(Color.Gray, 4);
if (numWheelers == WheelersDirection.FourthWheelers)
{
g.DrawEllipse(penGray, _startPosX + 24, _startPosY + 54, 10, 10);
g.DrawEllipse(penGray, _startPosX + 64, _startPosY + 59, 10, 10);
g.DrawEllipse(penGray, _startPosX + 104, _startPosY + 59, 10, 10);
g.DrawEllipse(penGray, _startPosX + 144, _startPosY + 54, 10, 10);
}
if (numWheelers == WheelersDirection.FifthWheelers)
{
g.DrawEllipse(penGray, _startPosX + 24, _startPosY + 54, 10, 10);
g.DrawEllipse(penGray, _startPosX + 54, _startPosY + 59, 10, 10);
g.DrawEllipse(penGray, _startPosX + 84, _startPosY + 61, 10, 10);
g.DrawEllipse(penGray, _startPosX + 114, _startPosY + 59, 10, 10);
g.DrawEllipse(penGray, _startPosX + 144, _startPosY + 54, 10, 10);
}
if (numWheelers == WheelersDirection.SixthWheelers)
{
g.DrawEllipse(penGray, _startPosX + 24, _startPosY + 54, 10, 10);
g.DrawEllipse(penGray, _startPosX + 48, _startPosY + 59, 10, 10);
g.DrawEllipse(penGray, _startPosX + 72, _startPosY + 61, 10, 10);
g.DrawEllipse(penGray, _startPosX + 96, _startPosY + 61, 10, 10);
g.DrawEllipse(penGray, _startPosX + 120, _startPosY + 59, 10, 10);
g.DrawEllipse(penGray, _startPosX + 144, _startPosY + 54, 10, 10);
}
}
}
}

View File

@ -37,6 +37,7 @@ namespace ProjectTank
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; }
public int NumWheelers { get; private set; }
/// <summary>
/// Расчет шага по карте
@ -54,7 +55,7 @@ namespace ProjectTank
/// <param name="machineGun">Признак наличия пулемета</param>
///
public void Init(int speed, double weight, bool gun,
bool machineGun, Color bodyColor, Color additionalColor)
bool machineGun, Color bodyColor, Color additionalColor, int numWheelers)
{
Speed = speed;
Weight = weight;
@ -62,6 +63,7 @@ namespace ProjectTank
AdditionalColor = additionalColor;
Gun = gun;
MachineGun = machineGun;
NumWheelers= numWheelers;
}
}
}

View File

@ -44,7 +44,7 @@ namespace ProjectTank
_drawningTank.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
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)),
pictureBoxTanks.Width, pictureBoxTanks.Height);
pictureBoxTanks.Width, pictureBoxTanks.Height, random.Next(4, 7));
_drawningTank.SetPosition(random.Next(0, 100), random.Next(0, 100));
Draw();
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTank
{
public enum WheelersDirection
{
/// <summary>
/// Четыре катка
/// </summary>
FourthWheelers,
/// <summary>
/// Пять катков
/// </summary>
FifthWheelers,
/// <summary>
/// Шесть катков
/// </summary>
SixthWheelers
}
}