Дописала проверки, доделала рисунок, чтобы создавались разные объекты

This commit is contained in:
Казначеева Елизавета 2023-09-26 12:43:17 +04:00
parent 19d684ffc0
commit 25753f7cac
3 changed files with 88 additions and 200 deletions

View File

@ -34,11 +34,8 @@ namespace Battleship
_drawningBattleship = new DrawningBattleship(); _drawningBattleship = new DrawningBattleship();
_drawningBattleship.Init(random.Next(100, 300), _drawningBattleship.Init(random.Next(100, 300),
random.Next(1000, 3000), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), Color.FromArgb(random.Next(0, 256), 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)),
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)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxBattleship.Width, pictureBoxBattleship.Height); pictureBoxBattleship.Width, pictureBoxBattleship.Height);
_drawningBattleship.SetPosition(random.Next(10, 100), _drawningBattleship.SetPosition(random.Next(10, 100),

View File

@ -34,35 +34,39 @@ namespace Battleship
/// <summary> /// <summary>
/// Ширина прорисовки автомобиля /// Ширина прорисовки автомобиля
/// </summary> /// </summary>
private readonly int _buttleshipWidth = 150; private readonly int _buttleshipWidth = 175;
/// <summary> /// <summary>
/// Высота прорисовки автомобиля /// Высота прорисовки автомобиля
/// </summary> /// </summary>
private readonly int _buttleshipHeight = 70; private readonly int _buttleshipHeight = 80;
/// <summary> ///// <summary>
/// Инициализация свойств ///// Инициализация свойств
/// </summary> ///// </summary>
/// <param name="speed">Скорость</param> ///// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param> ///// <param name="weight">Вес</param>
/// <param name="bodyColor">Цвет кузова</param> ///// <param name="bodyColor">Цвет кузова</param>
/// <param name="additionalColor">Дополнительный цвет</param> ///// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param> ///// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param> ///// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param> ///// <param name="sportLine">Признак наличия гоночной полосы</param>
/// <param name="width">Ширина картинки</param> ///// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param> ///// <param name="height">Высота картинки</param>
/// <returns>true - объект создан, false - проверка не пройдена, ///// <returns>true - объект создан, false - проверка не пройдена,
///нельзя создать объект в этих размерах</returns> /////нельзя создать объект в этих размерах</retu rns>
public bool Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool tower, bool section, int width, int height)
{ {
// TODO: Продумать проверки // TODO: Продумать проверки
if(width < _buttleshipWidth || height < _buttleshipHeight)
{
return false;
}
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
EntityBattleship = new EntityBattleship(); EntityBattleship = new EntityBattleship();
EntityBattleship.Init(speed, weight, bodyColor, additionalColor, EntityBattleship.Init(speed, weight, bodyColor, additionalColor,
bodyKit, wing, sportLine); tower, section);
return true; return true;
} }
/// <summary> /// <summary>
@ -73,8 +77,11 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
public void SetPosition(int x, int y) public void SetPosition(int x, int y)
{ {
// TODO: Изменение x, y // TODO: Изменение x, y
_startPosX = x; if (x >= 0 && x + _buttleshipWidth <= _pictureWidth && y >= 0 && y + _buttleshipHeight <= _pictureHeight)
_startPosY = y; {
_startPosX = x;
_startPosY = y;
}
} }
/// <summary> /// <summary>
/// Изменение направления перемещения /// Изменение направления перемещения
@ -86,6 +93,7 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
{ {
return; return;
} }
switch (direction) switch (direction)
{ {
//влево //влево
@ -104,16 +112,14 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
break; break;
// вправо // вправо
case DirectionType.Right: case DirectionType.Right:
// TODO: Продумать логику if (_startPosX + _buttleshipWidth + EntityBattleship.Step < _pictureWidth)
if (_startPosX + _buttleshipWidth + EntityBattleship.Step < 800)
{ {
_startPosX += (int)EntityBattleship.Step; _startPosX += (int)EntityBattleship.Step;
} }
break; break;
//вниз //вниз
case DirectionType.Down: case DirectionType.Down:
// TODO: Продумать логику if (_startPosY + _buttleshipHeight + EntityBattleship.Step < _pictureHeight)
if (_startPosY + _buttleshipHeight + EntityBattleship.Step < 450)
{ {
_startPosY += (int)EntityBattleship.Step; _startPosY += (int)EntityBattleship.Step;
} }
@ -134,173 +140,59 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
Brush additionalBrush = new Brush additionalBrush = new
SolidBrush(EntityBattleship.AdditionalColor); SolidBrush(EntityBattleship.AdditionalColor);
//корпус линкора //основа
Brush Brush = new Brush mainBrush = new SolidBrush(EntityBattleship.BodyColor);
SolidBrush(EntityBattleship.AdditionalColor);
Point[] hull = new Point[] Point[] hull = new Point[]
{ {
new Point(_startPosX + 40, _startPosY + 20), new Point(_startPosX + 10, _startPosY + 0),
new Point(_startPosX + 150, _startPosY + 20), new Point(_startPosX + 120, _startPosY + 0),
new Point(_startPosX + 180, _startPosY + 55), new Point(_startPosX + 160, _startPosY + 35),
new Point(_startPosX + 150, _startPosY + 90), new Point(_startPosX + 120, _startPosY + 70),
new Point(_startPosX + 40, _startPosY + 90), new Point(_startPosX + 10, _startPosY + 70),
}; };
g.FillPolygon(Brush, hull); g.FillPolygon(mainBrush, hull);
g.DrawPolygon(pen, hull); g.DrawPolygon(pen, hull);
//блоки //блоки
Brush blockBrush = new
Brush blockBrush2 = new SolidBrush(Color.DimGray);
SolidBrush(Color.Gray); g.FillRectangle(blockBrush, _startPosX + 70, _startPosY + 15, 20, 40);
g.FillRectangle(blockBrush2, _startPosX + 100, _startPosY + 35, 20, 40); g.DrawRectangle(pen, _startPosX + 70, _startPosY + 15, 20, 40);
g.DrawRectangle(pen, _startPosX + 100, _startPosY+35, 20, 40);
Brush blockBrush1 = new g.FillRectangle(additionalBrush, _startPosX + 40, _startPosY + 25, 30, 20);
SolidBrush(EntityBattleship.BodyColor); g.DrawRectangle(pen, _startPosX + 40, _startPosY + 25, 30, 20);
g.FillRectangle(blockBrush1, _startPosX + 70, _startPosY + 45, 30, 20);
g.DrawRectangle(pen, _startPosX + 70, _startPosY + 45, 30, 20);
g.FillEllipse(blockBrush1, _startPosX + 130, _startPosY + 40, 30, 30); g.FillEllipse(additionalBrush, _startPosX + 100, _startPosY + 20, 30, 30);
g.DrawEllipse(pen, _startPosX + 130, _startPosY + 40, 30, 30); g.DrawEllipse(pen, _startPosX + 100, _startPosY + 20, 30, 30);
//орудийная башня
Brush towerBrush = new
SolidBrush(EntityBattleship.AdditionalColor);
g.FillRectangle(towerBrush, _startPosX + 138, _startPosY + 48, 15, 15);
g.DrawRectangle(pen, _startPosX + 138, _startPosY + 48, 15, 15);
Brush gunBrush = new
SolidBrush(Color.Black);
g.FillRectangle(gunBrush, _startPosX + 153, _startPosY + 52, 55, 6);
g.DrawRectangle(pen, _startPosX + 153, _startPosY + 52, 55, 6);
//для ускорения //для ускорения
Brush speedBrush = new Brush speedBrush = new
SolidBrush(Color.Orange); SolidBrush(Color.Gold);
g.FillRectangle(speedBrush, _startPosX + 35, _startPosY + 30, 5, 20); g.FillRectangle(speedBrush, _startPosX + 5, _startPosY + 10, 5, 20);
g.DrawRectangle(pen, _startPosX + 35, _startPosY + 30, 5, 20); g.DrawRectangle(pen, _startPosX + 5, _startPosY + 10, 5, 20);
g.FillRectangle(speedBrush, _startPosX + 35, _startPosY + 60, 5, 20); g.FillRectangle(speedBrush, _startPosX + 5, _startPosY + 40, 5, 20);
g.DrawRectangle(pen, _startPosX + 35, _startPosY + 60, 5, 20); g.DrawRectangle(pen, _startPosX + 5, _startPosY + 40, 5, 20);
//орудийная башня
if (EntityBattleship.Tower)
{
Brush baseBrush = new SolidBrush(Color.White);
g.FillRectangle(baseBrush, _startPosX + 108, _startPosY + 28, 15, 15);
g.DrawRectangle(pen, _startPosX + 108, _startPosY + 28, 15, 15);
Brush gunBrush = new SolidBrush(Color.Black);
g.FillRectangle(gunBrush, _startPosX + 123, _startPosY + 32, 47, 6);
g.DrawRectangle(pen, _startPosX + 123, _startPosY + 32, 55, 6);
}
//отсеки под ракеты //отсеки под ракеты
Brush sectionBrush = new if (EntityBattleship.Section)
SolidBrush(Color.Gray); {
g.FillRectangle(sectionBrush, _startPosX + 50, _startPosY + 90, 40, 10); Brush sectionBrush = new
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 90, 40, 10); SolidBrush(Color.Gray);
g.FillRectangle(sectionBrush, _startPosX + 100, _startPosY + 90, 40, 10); g.FillRectangle(sectionBrush, _startPosX + 20, _startPosY + 70, 40, 10);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 90, 40, 10); g.DrawRectangle(pen, _startPosX + 20, _startPosY + 70, 40, 10);
g.FillRectangle(sectionBrush, _startPosX + 75, _startPosY + 70, 40, 10);
g.DrawRectangle(pen, _startPosX + 75, _startPosY + 70, 40, 10);
}
// обвесы
// if (EntityBattleship.BodyKit)
// {
// g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20);
// g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20,
// 20);
// g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10,
// 20, 40);
// g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15,
// 15);
// g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45,
// 15, 15);
// g.FillEllipse(additionalBrush, _startPosX + 90,
// _startPosY, 20, 20);
// g.FillEllipse(additionalBrush, _startPosX + 90,
// _startPosY + 40, 20, 20);
// g.FillRectangle(additionalBrush, _startPosX + 90,
// _startPosY + 10, 20, 40);
// g.FillRectangle(additionalBrush, _startPosX + 90,
//_startPosY + 1, 15, 15);
// g.FillRectangle(additionalBrush, _startPosX + 90,
// _startPosY + 45, 15, 15);
// g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20);
// g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20);
// g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20,
// 40);
// g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14,
// 15);
// g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45,
// 14, 15);
// g.FillEllipse(additionalBrush, _startPosX, _startPosY,
// 20, 20);
// g.FillEllipse(additionalBrush, _startPosX, _startPosY +
// 40, 20, 20);
// g.FillRectangle(additionalBrush, _startPosX + 1,
// _startPosY + 10, 25, 40);
// g.FillRectangle(additionalBrush, _startPosX + 5,
// _startPosY + 1, 15, 15);
// g.FillRectangle(additionalBrush, _startPosX + 5,
// _startPosY + 45, 15, 15);
// g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39,
// 15);
// g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45,
// 39, 15);
// g.FillRectangle(additionalBrush, _startPosX + 35,
// _startPosY + 1, 40, 15);
// g.FillRectangle(additionalBrush, _startPosX + 35,
// _startPosY + 45, 40, 15);
// }
// //границы автомобиля
// g.DrawEllipse(pen, _startPosX + 10, _startPosY + 5, 20, 20);
// g.DrawEllipse(pen, _startPosX + 10, _startPosY + 35, 20, 20);
// g.DrawEllipse(pen, _startPosX + 80, _startPosY + 5, 20, 20);
// g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20);
// g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
// g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
// 30);
// g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
// //задние фары
// Brush brRed = new SolidBrush(Color.Red);
// g.FillEllipse(brRed, _startPosX + 10, _startPosY + 5, 20, 20);
// g.FillEllipse(brRed, _startPosX + 10, _startPosY + 35, 20,
// 20);
// //передние фары
// Brush brYellow = new SolidBrush(Color.Yellow);
// g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
// 20);
// g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
// 20);
// //кузов
// Brush br = new SolidBrush(EntityBattleship.BodyColor);
// g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
// g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
// g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
// //стекла
// Brush brBlue = new SolidBrush(Color.LightBlue);
// g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 10, 5,
// 40);
// g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 10, 5,
// 40);
// g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 8, 35,
// 2);
// g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 51, 35,
// 2);
// //выделяем рамкой крышу
// g.DrawRectangle(pen, _startPosX + 35, _startPosY + 10, 35,
// 40);
// g.DrawRectangle(pen, _startPosX + 75, _startPosY + 15, 25,
// 30);
// g.DrawRectangle(pen, _startPosX + 10, _startPosY + 15, 15,
// 30);
// // спортивная линия
// if (EntityBattleship.SportLine)
// {
// g.FillRectangle(additionalBrush, _startPosX + 75,
// _startPosY + 23, 25, 15);
// g.FillRectangle(additionalBrush, _startPosX + 35,
// _startPosY + 23, 35, 15);
// g.FillRectangle(additionalBrush, _startPosX + 10,
// _startPosY + 23, 20, 15);
// }
// // крыло
// if (EntityBattleship.Wing)
// {
// g.FillRectangle(additionalBrush, _startPosX, _startPosY
// + 5, 10, 50);
// g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10,
// 50);
// }
} }
} }
} }

View File

@ -27,15 +27,15 @@ namespace Battleship
/// <summary> /// <summary>
/// Признак (опция) наличия обвеса /// Признак (опция) наличия обвеса
/// </summary> /// </summary>
public bool BodyKit { get; private set; } //public bool BodyKit { get; private set; }
// /// <summary>
// /// Признак (опция) наличия башни
// /// </summary>
public bool Tower { get; private set; }
/// <summary> /// <summary>
/// Признак (опция) наличия антикрыла /// Признак (опция) наличия секции под ракеты
/// </summary> /// </summary>
public bool Wing { get; private set; } public bool Section { get; private set; }
/// <summary>
/// Признак (опция) наличия гоночной полосы
/// </summary>
public bool SportLine { get; private set; }
/// <summary> /// <summary>
/// Шаг перемещения автомобиля /// Шаг перемещения автомобиля
/// </summary> /// </summary>
@ -48,18 +48,17 @@ namespace Battleship
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param> /// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param> /// <param name="tower">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param> /// <param name="section">Признак наличия гоночной полосы</param>
public void Init(int speed, double weight, Color bodyColor, Color public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool wing, bool sportLine) additionalColor, bool tower, bool section)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
BodyKit = bodyKit; Tower = tower;
Wing = wing; Section = section;
SportLine = sportLine;
} }
} }
} }