PIbd-21_KozyrevSS_GasolineT.../Lab/DrawGasolineTanker.cs

113 lines
4.0 KiB
C#
Raw Permalink Normal View History

2023-09-26 19:15:17 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab
{
public class DrawGasolineTanker
{
public BaseCar? GasolineTanker { get; private set; }
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
private int _startPosY;
private readonly int _carWidth = 100;
private readonly int _carHeight = 80;
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
{
_pictureHeight = height;
_pictureWidth = width;
GasolineTanker = new BaseCar();
GasolineTanker.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine);
return true;
}
public void SetPosition(int x, int y)
{
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(Direction direction)
{
if (GasolineTanker == null)
return;
switch (direction)
{
case Direction.Left:
{
if (_startPosX - GasolineTanker.Step > 0)
{
_startPosX -= (int)GasolineTanker.Step;
}
}
break;
case Direction.Up:
{
if (_startPosY - GasolineTanker.Step > 0)
{
_startPosY -= (int)GasolineTanker.Step;
}
}
break;
case Direction.Right:
{
if (_startPosX + _carWidth + GasolineTanker.Step < _pictureWidth)
{
_startPosX += (int)GasolineTanker.Step;
}
}
break;
case Direction.Down:
{
if (_startPosY + GasolineTanker.Step + _carHeight < _pictureHeight)
{
_startPosY += (int)GasolineTanker.Step;
}
}
break;
}
}
public void DrawTransport(Graphics g)
{
if (GasolineTanker == null)
return;
Pen pen = new(GasolineTanker.BodyColor, 2);
Brush brush = new SolidBrush(GasolineTanker.BodyColor);
if (GasolineTanker.BodyKit)
{
Brush bodyBrush = new SolidBrush(GasolineTanker.AdditionalColor);
g.FillEllipse(bodyBrush, 10 + _startPosX, 10 + _startPosY, 70, 30);
}
// Отрисовка корпуса
g.FillRectangle(brush, 10 + _startPosX, 40 + _startPosY, 90, 20);
g.FillRectangle(brush, 80 + _startPosX, 10 + _startPosY, 20, 40);
// Отрисовка колесиков
g.FillEllipse(brush, 10 + _startPosX, 60 + _startPosY, 20, 20);
g.FillEllipse(brush, 30 + _startPosX, 60 + _startPosY, 20, 20);
g.FillEllipse(brush, 80 + _startPosX, 60 + _startPosY, 20, 20);
if (GasolineTanker.SportLine)
{
Brush lineBrush = new SolidBrush(GasolineTanker.AdditionalColor);
g.FillRectangle(lineBrush, 15 + _startPosX, 45 + _startPosY, 20, 5);
g.FillRectangle(lineBrush, 40 + _startPosX, 45 + _startPosY, 20, 5);
g.FillRectangle(lineBrush, 65 + _startPosX, 45 + _startPosY, 20, 5);
}
if (GasolineTanker.Wing)
{
Brush lightBrush = new SolidBrush(GasolineTanker.AdditionalColor);
g.FillRectangle(lightBrush, 87 + _startPosX, 5 + _startPosY, 5, 5);
}
}
}
}