This commit is contained in:
sofiaivv 2023-10-31 02:42:49 +04:00
parent 3f1b5d0305
commit 1675790901
8 changed files with 146 additions and 33 deletions

View File

@ -37,12 +37,12 @@ namespace MotorBoat
private int _startPosY = 0;
/// <summary>
/// Ширина прорисовки автомобиля
/// Ширина прорисовки катера
/// </summary>
private readonly int _boatWight = 120;
private readonly int _boatWight = 165;
/// <summary>
/// Высота прорисовки автомобиля
/// Высота прорисовки катера
/// </summary>
private readonly int _boatHeight = 80;
@ -53,17 +53,19 @@ namespace MotorBoat
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Цвет корпуса</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="wight">Ширина картинки</param>
/// <param name="engine">Признак наличия двигателя в корме</param>
/// <param name="glass">Признак наличия защитного стекла впереди</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Выслота картинки</param>
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
public bool Init(int speed, double weight, Color bodyColor, Color AdditionalColor, int width, int height)
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool engine, bool glass, int width, int height)
{
if (width <= _boatWight || height <= _boatHeight)
return false;
_pictureWight = width;
_pictureHeight = height;
EntityMotorBoat = new EntityMotorBoat();
EntityMotorBoat.Init(speed, weight, bodyColor, AdditionalColor);
EntityMotorBoat.Init(speed, weight, bodyColor, additionalColor, engine, glass);
return true;
}
@ -132,7 +134,7 @@ namespace MotorBoat
//вниз
case DirectionType.Down:
if (_startPosY + _pictureHeight + EntityMotorBoat.Step < _pictureHeight)
if (_startPosY + _boatHeight + EntityMotorBoat.Step < _pictureHeight)
{
_startPosY += (int)EntityMotorBoat.Step;
}
@ -150,17 +152,38 @@ namespace MotorBoat
{
return;
}
Pen pen = new(Color.Black);
Pen pen = new(Color.Black, 1);
Brush mainBrush = new SolidBrush(EntityMotorBoat.BodyColor);
Brush additionalBrush = new SolidBrush(EntityMotorBoat.AdditionalColor);
Point[] points = { new Point(_startPosX + _boatWight - 40, _startPosY + 10), new Point(_startPosX + _boatWight, _startPosY + 40), new Point(_startPosX + _boatWight - 40, _startPosY + 70) };
// корпус
Point[] hull = new Point[]
{
new Point(_startPosX + 5, _startPosY + 0),
new Point(_startPosX + 120, _startPosY + 0),
new Point(_startPosX + 160, _startPosY + 35),
new Point(_startPosX + 120, _startPosY + 70),
new Point(_startPosX + 5, _startPosY + 70),
};
g.FillPolygon(mainBrush, hull);
g.DrawPolygon(pen, hull);
g.DrawRectangle(pen, _startPosX, _startPosY, _boatWight - 20, 10);
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 10, _boatWight - 50, 60);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 25, 60, 30); // палуба
g.DrawPolygon(pen, points);
// стекло впереди
Brush glassBrush = new SolidBrush(Color.LightBlue);
g.FillEllipse(glassBrush, _startPosX + 20, _startPosY + 15, 100, 40);
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 15, 100, 40);
// осн часть
Brush blockBrush = new SolidBrush(Color.Olive);
g.FillRectangle(blockBrush, _startPosX + 20, _startPosY + 15, 80, 40);
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 15, 80, 40);
// двигатель
Brush engineBrush = new
SolidBrush(Color.Olive);
g.FillRectangle(engineBrush, _startPosX + 0, _startPosY + 10, 5, 50);
g.DrawRectangle(pen, _startPosX + 0, _startPosY + 10, 5, 50);
}
}
}

View File

@ -6,27 +6,37 @@ using System.Threading.Tasks;
namespace MotorBoat
{
internal class EntityMotorBoat
public class EntityMotorBoat
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; set; }
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; set; }
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; set; }
public Color BodyColor { get; private set; }
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color AdditionalColor { get; set; }
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия двигателя в корме
/// </summary>
public bool Engine { get; private set; }
/// <summary>
/// Признак (опция) наличия защитного стекла спереди
/// </summary>
public bool Glass { get; private set; }
/// <summary>
/// Шаг перемещения моторной лодки
@ -40,13 +50,17 @@ namespace MotorBoat
/// <param name="weight">Вес катера</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="engine">Признак наличия двигателя в корме</param>
/// <param name="glass">Признак наличия защитного стекла впереди</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor)
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool engine, bool glass)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Engine = engine;
Glass = glass;
}
}
}

View File

@ -28,24 +28,24 @@
/// </summary>
private void InitializeComponent()
{
pictureBox1 = new PictureBox();
pictureBoxMotorBoat = new PictureBox();
buttonCreate = new Button();
buttonLeft = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonDown = new Button();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).BeginInit();
SuspendLayout();
//
// pictureBox1
// pictureBoxMotorBoat
//
pictureBox1.Dock = DockStyle.Fill;
pictureBox1.Location = new Point(0, 0);
pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new Size(884, 461);
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBox1.TabIndex = 0;
pictureBox1.TabStop = false;
pictureBoxMotorBoat.Dock = DockStyle.Fill;
pictureBoxMotorBoat.Location = new Point(0, 0);
pictureBoxMotorBoat.Name = "pictureBoxMotorBoat";
pictureBoxMotorBoat.Size = new Size(884, 461);
pictureBoxMotorBoat.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxMotorBoat.TabIndex = 0;
pictureBoxMotorBoat.TabStop = false;
//
// buttonCreate
//
@ -56,6 +56,7 @@
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// buttonLeft
//
@ -67,6 +68,7 @@
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonRight
//
@ -78,6 +80,7 @@
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 3;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// buttonUp
//
@ -89,6 +92,7 @@
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonDown
//
@ -100,6 +104,7 @@
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// FormMotorBoat
//
@ -111,18 +116,18 @@
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonCreate);
Controls.Add(pictureBox1);
Controls.Add(pictureBoxMotorBoat);
Name = "FormMotorBoat";
StartPosition = FormStartPosition.CenterScreen;
Text = "FormMotorBoat";
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private PictureBox pictureBox1;
private PictureBox pictureBoxMotorBoat;
private Button buttonCreate;
private Button buttonLeft;
private Button buttonRight;

View File

@ -2,9 +2,80 @@ namespace MotorBoat
{
public partial class FormMotorBoat : Form
{
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawningMotorboat? _drawningMotorboat;
/// <summary>
/// Èíèöèàëèçàöèÿ ôîðìû
/// </summary>
public FormMotorBoat()
{
InitializeComponent();
}
/// <summary>
/// Ìåòîä ïðîðèñîâêè êàòåðà
/// </summary>
private void Draw()
{
if (_drawningMotorboat == null)
{
return;
}
Bitmap bmp = new(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningMotorboat.DrawTransport(gr);
pictureBoxMotorBoat.Image = bmp;
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningMotorboat = new DrawningMotorboat();
_drawningMotorboat.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)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
_drawningMotorboat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningMotorboat == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningMotorboat.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawningMotorboat.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawningMotorboat.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawningMotorboat.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
MotorBoat/MotorBoat/up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB