Дописала проверки, доделала рисунок, чтобы создавались разные объекты
This commit is contained in:
parent
19d684ffc0
commit
25753f7cac
@ -34,11 +34,8 @@ namespace Battleship
|
||||
_drawningBattleship = new DrawningBattleship();
|
||||
_drawningBattleship.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)),
|
||||
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)),
|
||||
pictureBoxBattleship.Width, pictureBoxBattleship.Height);
|
||||
_drawningBattleship.SetPosition(random.Next(10, 100),
|
||||
|
@ -34,35 +34,39 @@ namespace Battleship
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _buttleshipWidth = 150;
|
||||
|
||||
private readonly int _buttleshipWidth = 175;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _buttleshipHeight = 70;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</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 bodyKit, bool wing, bool sportLine, int width, int height)
|
||||
private readonly int _buttleshipHeight = 80;
|
||||
///// <summary>
|
||||
///// Инициализация свойств
|
||||
///// </summary>
|
||||
///// <param name="speed">Скорость</param>
|
||||
///// <param name="weight">Вес</param>
|
||||
///// <param name="bodyColor">Цвет кузова</param>
|
||||
///// <param name="additionalColor">Дополнительный цвет</param>
|
||||
///// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
///// <param name="wing">Признак наличия антикрыла</param>
|
||||
///// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
///// <param name="width">Ширина картинки</param>
|
||||
///// <param name="height">Высота картинки</param>
|
||||
///// <returns>true - объект создан, false - проверка не пройдена,
|
||||
/////нельзя создать объект в этих размерах</retu rns>
|
||||
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool tower, bool section, int width, int height)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
if(width < _buttleshipWidth || height < _buttleshipHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityBattleship = new EntityBattleship();
|
||||
EntityBattleship.Init(speed, weight, bodyColor, additionalColor,
|
||||
bodyKit, wing, sportLine);
|
||||
EntityBattleship.Init(speed, weight, bodyColor, additionalColor,
|
||||
tower, section);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -73,8 +77,11 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
// TODO: Изменение x, y
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
if (x >= 0 && x + _buttleshipWidth <= _pictureWidth && y >= 0 && y + _buttleshipHeight <= _pictureHeight)
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
@ -86,6 +93,7 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
@ -104,16 +112,14 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
// TODO: Продумать логику
|
||||
if (_startPosX + _buttleshipWidth + EntityBattleship.Step < 800)
|
||||
if (_startPosX + _buttleshipWidth + EntityBattleship.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityBattleship.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
// TODO: Продумать логику
|
||||
if (_startPosY + _buttleshipHeight + EntityBattleship.Step < 450)
|
||||
if (_startPosY + _buttleshipHeight + EntityBattleship.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityBattleship.Step;
|
||||
}
|
||||
@ -134,173 +140,59 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(EntityBattleship.AdditionalColor);
|
||||
|
||||
//корпус линкора
|
||||
Brush Brush = new
|
||||
SolidBrush(EntityBattleship.AdditionalColor);
|
||||
//основа
|
||||
Brush mainBrush = new SolidBrush(EntityBattleship.BodyColor);
|
||||
Point[] hull = new Point[]
|
||||
{
|
||||
new Point(_startPosX + 40, _startPosY + 20),
|
||||
new Point(_startPosX + 150, _startPosY + 20),
|
||||
new Point(_startPosX + 180, _startPosY + 55),
|
||||
new Point(_startPosX + 150, _startPosY + 90),
|
||||
new Point(_startPosX + 40, _startPosY + 90),
|
||||
new Point(_startPosX + 10, _startPosY + 0),
|
||||
new Point(_startPosX + 120, _startPosY + 0),
|
||||
new Point(_startPosX + 160, _startPosY + 35),
|
||||
new Point(_startPosX + 120, _startPosY + 70),
|
||||
new Point(_startPosX + 10, _startPosY + 70),
|
||||
};
|
||||
g.FillPolygon(Brush, hull);
|
||||
g.FillPolygon(mainBrush, hull);
|
||||
g.DrawPolygon(pen, hull);
|
||||
|
||||
|
||||
//блоки
|
||||
|
||||
Brush blockBrush2 = new
|
||||
SolidBrush(Color.Gray);
|
||||
g.FillRectangle(blockBrush2, _startPosX + 100, _startPosY + 35, 20, 40);
|
||||
g.DrawRectangle(pen, _startPosX + 100, _startPosY+35, 20, 40);
|
||||
Brush blockBrush = new
|
||||
SolidBrush(Color.DimGray);
|
||||
g.FillRectangle(blockBrush, _startPosX + 70, _startPosY + 15, 20, 40);
|
||||
g.DrawRectangle(pen, _startPosX + 70, _startPosY + 15, 20, 40);
|
||||
|
||||
Brush blockBrush1 = new
|
||||
SolidBrush(EntityBattleship.BodyColor);
|
||||
g.FillRectangle(blockBrush1, _startPosX + 70, _startPosY + 45, 30, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 70, _startPosY + 45, 30, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 40, _startPosY + 25, 30, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 40, _startPosY + 25, 30, 20);
|
||||
|
||||
g.FillEllipse(blockBrush1, _startPosX + 130, _startPosY + 40, 30, 30);
|
||||
g.DrawEllipse(pen, _startPosX + 130, _startPosY + 40, 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);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 100, _startPosY + 20, 30, 30);
|
||||
g.DrawEllipse(pen, _startPosX + 100, _startPosY + 20, 30, 30);
|
||||
|
||||
//для ускорения
|
||||
Brush speedBrush = new
|
||||
SolidBrush(Color.Orange);
|
||||
g.FillRectangle(speedBrush, _startPosX + 35, _startPosY + 30, 5, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 35, _startPosY + 30, 5, 20);
|
||||
g.FillRectangle(speedBrush, _startPosX + 35, _startPosY + 60, 5, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 35, _startPosY + 60, 5, 20);
|
||||
SolidBrush(Color.Gold);
|
||||
g.FillRectangle(speedBrush, _startPosX + 5, _startPosY + 10, 5, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 10, 5, 20);
|
||||
g.FillRectangle(speedBrush, _startPosX + 5, _startPosY + 40, 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
|
||||
SolidBrush(Color.Gray);
|
||||
g.FillRectangle(sectionBrush, _startPosX + 50, _startPosY + 90, 40, 10);
|
||||
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 90, 40, 10);
|
||||
g.FillRectangle(sectionBrush, _startPosX + 100, _startPosY + 90, 40, 10);
|
||||
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 90, 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);
|
||||
// }
|
||||
if (EntityBattleship.Section)
|
||||
{
|
||||
Brush sectionBrush = new
|
||||
SolidBrush(Color.Gray);
|
||||
g.FillRectangle(sectionBrush, _startPosX + 20, _startPosY + 70, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,15 +27,15 @@ namespace Battleship
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
//public bool BodyKit { get; private set; }
|
||||
// /// <summary>
|
||||
// /// Признак (опция) наличия башни
|
||||
// /// </summary>
|
||||
public bool Tower { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// Признак (опция) наличия секции под ракеты
|
||||
/// </summary>
|
||||
public bool Wing { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool SportLine { get; private set; }
|
||||
public bool Section { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
@ -48,18 +48,17 @@ namespace Battleship
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
/// <param name="tower">Признак наличия антикрыла</param>
|
||||
/// <param name="section">Признак наличия гоночной полосы</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
additionalColor, bool tower, bool section)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Wing = wing;
|
||||
SportLine = sportLine;
|
||||
AdditionalColor = additionalColor;
|
||||
Tower = tower;
|
||||
Section = section;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user