PIbd-23-Mamadosimov-Z-Sh-Se.../Lab1/SelfPropelledArtilleryUnit/DrawningTank.cs
Ziyoviddin Mamadosimov 95b7b05dc7 Lab1
2023-10-13 10:51:06 +04:00

201 lines
7.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using SelfPropelledArtilleryUnit;
using System.Windows.Forms;
namespace SelfPropelledArtilleryUnit
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
class DrawningTank
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityTank? EntityTank { get; private 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 _tankWidth = 135;
/// <summary>
/// Высота прорисовки танка
/// </summary>
private readonly int _tankHeight = 75;
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="machine_gun">Признак наличия пулемета</param>
/// <param name="cannon">Признак наличия пушки</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 machine_gun, bool cannon, int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_tankHeight >= height)
{
return false;
}
if (_tankWidth >= width)
{
return false;
}
EntityTank = new EntityTank();
EntityTank.Init(speed, weight, bodyColor, additionalColor, machine_gun, cannon);
return true;
//EntityTank myTank = new EntityTank();
//myTank.Init(50, 75.5, Color.Green, Color.Black, true, false, true);
//return true;
}
public void SetPosition(int x, int y)
{
if (x < 0 || x > _pictureWidth - _tankWidth)
{
x = 0;
}
if (y < 0 || y > _pictureHeight - _tankHeight)
{
y = 0;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(Direction direction)
{
if (EntityTank == null)
{
return;
}
switch (direction)
{
//влево
case Direction.Left:
if (_startPosX - EntityTank.Step > 0)
{
_startPosX -= (int)EntityTank.Step;
}
break;
//вверх
case Direction.Up:
if (_startPosY - EntityTank.Step > 0)
{
_startPosY -= (int)EntityTank.Step;
}
break;
// вправо
case Direction.Right:
if (_startPosX + EntityTank.Step < _pictureWidth - _tankWidth)
{
_startPosX += (int)EntityTank.Step;
}
break;
//вниз
case Direction.Down:
if (_startPosY + EntityTank.Step < _pictureHeight - _tankHeight)
{
_startPosY += (int)EntityTank.Step;
}
break;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{
if (EntityTank == null)
{
return;
}
Pen penBlack = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityTank.AdditionalColor);
// пулемет
if (EntityTank.Machine_gun)
{
//залповая усутановка
g.FillRectangle(additionalBrush, _startPosX + 15, _startPosY + 20, 20, 40);
g.DrawLine(penBlack, _startPosX + 5, _startPosY + 20, _startPosX + 15, _startPosY + 25);
}
//гусеницы
Brush brBlack = new SolidBrush(Color.Black);
Brush brBody = new SolidBrush(EntityTank.BodyColor);
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 50, 20, 20);
g.FillEllipse(brBlack, _startPosX + 30, _startPosY + 50, 20, 20);
g.FillEllipse(brBlack, _startPosX + 55, _startPosY + 50, 20, 20);
g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 50, 20, 20);
g.FillEllipse(brBlack, _startPosX + 105, _startPosY + 50, 20, 20);
g.DrawEllipse(penBlack, _startPosX + 10, _startPosY + 55, 113, 20);
//пушка
Point[] pointsGun = new Point[4];
pointsGun[0].X = _startPosX + 85; pointsGun[0].Y = _startPosY + 25;
pointsGun[1].X = _startPosX + 80; pointsGun[1].Y = _startPosY + 30;
pointsGun[2].X = _startPosX - 15; pointsGun[2].Y = _startPosY + 5;
pointsGun[3].X = _startPosX - 10; pointsGun[3].Y = _startPosY + 0;
g.FillPolygon(brBody, pointsGun);
g.DrawPolygon(penBlack, pointsGun);
//корпус
Point[] pointsCorp = new Point[4];
pointsCorp[0].X = _startPosX; pointsCorp[0].Y = _startPosY + 60;
pointsCorp[1].X = _startPosX + 10; pointsCorp[1].Y = _startPosY + 30;
pointsCorp[2].X = _startPosX + 130; pointsCorp[2].Y = _startPosY + 30;
pointsCorp[3].X = _startPosX + 135; pointsCorp[3].Y = _startPosY + 60;
g.FillPolygon(brBody, pointsCorp);
g.DrawPolygon(penBlack, pointsCorp);
//башня
Point[] pointsHead = new Point[4];
pointsHead[0].X = _startPosX + 60; pointsHead[0].Y = _startPosY + 30;
pointsHead[1].X = _startPosX + 65; pointsHead[1].Y = _startPosY + 15;
pointsHead[2].X = _startPosX + 90; pointsHead[2].Y = _startPosY + 15;
pointsHead[3].X = _startPosX + 95; pointsHead[3].Y = _startPosY + 30;
g.FillPolygon(brBody, pointsHead);
g.DrawPolygon(penBlack, pointsHead);
}
}
}