Polevoy S.V Lab_work1 #1
117
SelfPropelledArtilleryUnit/DrawingArtillery.cs
Normal file
117
SelfPropelledArtilleryUnit/DrawingArtillery.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class DrawingArtillery
|
||||
|
||||
{
|
||||
public EntityArtillery Artillery { private set; get; }
|
||||
private float _startPosX;
|
||||
private float _startPosY;
|
||||
private int? _pictureWidth = null;
|
||||
private int? _pictureHeight = null;
|
||||
private readonly int _artilleryWidth = 80;
|
||||
private readonly int _artilleryHeight = 50;
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Artillery = new EntityArtillery();
|
||||
Artillery.Init(speed, weight, bodyColor);
|
||||
}
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x < 0 || x + _artilleryWidth >= width)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (y < 0 || y + _artilleryHeight >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Right:
|
||||
if (_startPosX + _artilleryWidth + Artillery.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += Artillery.Step;
|
||||
}
|
||||
break;
|
||||
|
||||
case Direction.Left:
|
||||
if (_startPosX - Artillery.Step >= 0)
|
||||
{
|
||||
_startPosX -= Artillery.Step;
|
||||
}
|
||||
break;
|
||||
|
||||
case Direction.Up:
|
||||
if (_startPosY - Artillery.Step >= 0)
|
||||
{
|
||||
_startPosY -= Artillery.Step;
|
||||
}
|
||||
break;
|
||||
|
||||
case Direction.Down:
|
||||
if (_startPosY + _artilleryHeight + Artillery.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += Artillery.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Brush brush = new SolidBrush(Artillery?.BodyColor ?? Color.Black);
|
||||
g.FillRectangle(brush, _startPosX + _artilleryWidth / 8 * 2, _startPosY, _artilleryWidth / 8 * 4, _artilleryWidth / 5);
|
||||
g.FillRectangle(brush, _startPosX, _startPosY + _artilleryHeight / 5, _artilleryWidth, _artilleryHeight / 3);
|
||||
|
||||
Pen blackPen = new(Color.Black);
|
||||
g.DrawEllipse(blackPen, _startPosX, _startPosY + _artilleryHeight * 2 / 5, _artilleryWidth, _artilleryHeight * 2 / 5);
|
||||
g.DrawEllipse(blackPen, _startPosX + _artilleryWidth / 20, _startPosY + _artilleryHeight * 7 / 15, _artilleryWidth * 4 / 20, _artilleryHeight * 10 / 32);
|
||||
g.DrawEllipse(blackPen, _startPosX + _artilleryWidth * 5 / 20, _startPosY + _artilleryHeight * 9 / 16, _artilleryWidth * 3 / 20, _artilleryHeight * 8 / 32);
|
||||
g.DrawEllipse(blackPen, _startPosX + _artilleryWidth * 8 / 20, _startPosY + _artilleryHeight * 10 / 16, _artilleryWidth * 2 / 20, _artilleryHeight * 6 / 32);
|
||||
g.DrawEllipse(blackPen, _startPosX + _artilleryWidth * 10 / 20, _startPosY + _artilleryHeight * 10 / 16, _artilleryWidth * 2 / 20, _artilleryHeight * 6 / 32);
|
||||
g.DrawEllipse(blackPen, _startPosX + _artilleryWidth * 12 / 20, _startPosY + _artilleryHeight * 9 / 16, _artilleryWidth * 3 / 20, _artilleryHeight * 8 / 32);
|
||||
g.DrawEllipse(blackPen, _startPosX + _artilleryWidth * 15 / 20, _startPosY + _artilleryHeight * 7 / 15, _artilleryWidth * 4 / 20, _artilleryHeight * 10 / 32);
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureWidth <= _artilleryWidth || _pictureHeight <= _artilleryHeight)
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
return;
|
||||
}
|
||||
if (_startPosX + _artilleryWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth.Value - _artilleryWidth;
|
||||
}
|
||||
if (_startPosY + _artilleryHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight.Value - _artilleryHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Имя класса не соответствует заданию