Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca8833f4e1 | ||
|
|
9a5a57c959 |
@@ -8,31 +8,15 @@ namespace Cruiser
|
||||
{
|
||||
public class Cruiser
|
||||
{
|
||||
|
||||
public int Speed { get; private set; }
|
||||
|
||||
|
||||
|
||||
public double Weight { get; private set; }
|
||||
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
|
||||
public bool Headlights { get; private set; }
|
||||
public bool HelicopterPad { get; private set; }
|
||||
|
||||
public bool Coating { get; private set; }
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="headlights">Признак наличия передних фар</param>
|
||||
/// <param name="helicopterPad">Признак наличия площадки для вертолета</param>
|
||||
/// <param name="coating">Признак наличия покрытия</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool headlights, bool helicopterPad, bool coating)
|
||||
{
|
||||
|
||||
@@ -21,37 +21,23 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(386, 68);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(112, 34);
|
||||
this.button1.TabIndex = 0;
|
||||
this.button1.Text = "button1";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(667, 358);
|
||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBox1.TabIndex = 0;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
|
||||
this.pictureBoxCruiser.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxCruiser.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCruiser.Name = "pictureBoxCruiser";
|
||||
this.pictureBoxCruiser.Size = new System.Drawing.Size(667, 358);
|
||||
this.pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxCruiser.TabIndex = 0;
|
||||
this.pictureBoxCruiser.TabStop = false;
|
||||
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Cruiser.Properties.Resources.вниз;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
@@ -61,9 +47,7 @@
|
||||
this.buttonDown.TabIndex = 1;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::Cruiser.Properties.Resources.влево;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
@@ -73,9 +57,7 @@
|
||||
this.buttonLeft.TabIndex = 2;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::Cruiser.Properties.Resources.вправо;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
@@ -85,9 +67,7 @@
|
||||
this.buttonRight.TabIndex = 3;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Cruiser.Properties.Resources.вверх;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
@@ -97,9 +77,7 @@
|
||||
this.buttonUp.TabIndex = 4;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(36, 302);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
@@ -107,84 +85,25 @@
|
||||
this.buttonCreate.TabIndex = 5;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreateSportCar_Click);
|
||||
//
|
||||
// CruiserForm
|
||||
//
|
||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
|
||||
this.ClientSize = new System.Drawing.Size(667, 358);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Controls.Add(this.pictureBoxCruiser);
|
||||
this.Name = "CruiserForm";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateSportCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningCruiser = new DrawningCruiser();
|
||||
_drawningCruiser.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)), Convert.ToBoolean(random.Next(0, 2)), pictureBox1.Width, pictureBox1.Height);
|
||||
_drawningCruiser.SetPosition(random.Next(10, 100),
|
||||
random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningCruiser.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningCruiser.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningCruiser.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningCruiser.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBox1.Width,
|
||||
pictureBox1.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningCruiser.DrawTransport(gr);
|
||||
pictureBox1.Image = bmp;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button button1;
|
||||
private PictureBox pictureBox1;
|
||||
private PictureBox pictureBoxCruiser;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
66
Cruiser/Cruiser/CruiserForm.cs
Normal file
66
Cruiser/Cruiser/CruiserForm.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Cruiser
|
||||
{
|
||||
public partial class CruiserForm : Form
|
||||
{
|
||||
private DrawningCruiser? _drawningCruiser;
|
||||
public CruiserForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningCruiser = new DrawningCruiser();
|
||||
_drawningCruiser.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)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxCruiser.Width, pictureBoxCruiser.Height);
|
||||
_drawningCruiser.SetPosition(random.Next(10, 100),
|
||||
random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningCruiser.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningCruiser.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningCruiser.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningCruiser.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxCruiser.Width,
|
||||
pictureBoxCruiser.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningCruiser.DrawTransport(gr);
|
||||
pictureBoxCruiser.Image = bmp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,23 +8,9 @@ namespace Cruiser
|
||||
{
|
||||
public enum Direction
|
||||
{
|
||||
/// Вверх
|
||||
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -8,7 +8,6 @@ namespace Cruiser
|
||||
{
|
||||
public class DrawningCruiser
|
||||
{
|
||||
|
||||
public Cruiser? Cruiser { get; private set; }
|
||||
|
||||
private int _pictureWidth;
|
||||
@@ -21,66 +20,34 @@ namespace Cruiser
|
||||
|
||||
private readonly int _cruiserWidth = 150;
|
||||
|
||||
|
||||
private readonly int _cruiserHeight = 50;
|
||||
|
||||
|
||||
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="headlights">Признак наличия фар</param>
|
||||
/// <param name="helicopterPad">Признак наличия антикрыла</param>
|
||||
/// <param name="coating">Признак наличия гоночной полосы</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 headlights, bool helicopterPad, bool coating, int width, int height)
|
||||
{
|
||||
|
||||
if (_pictureHeight < _cruiserHeight || _pictureWidth < _cruiserWidth)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureHeight > _cruiserWidth && _pictureWidth > _cruiserHeight)
|
||||
{
|
||||
Cruiser = new Cruiser();
|
||||
Cruiser.Init(speed, weight, bodyColor, additionalColor,
|
||||
headlights, helicopterPad, coating);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
Cruiser = new Cruiser();
|
||||
Cruiser.Init(speed, weight, bodyColor, additionalColor,
|
||||
headlights, helicopterPad, coating);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (Cruiser == null) return;
|
||||
while (x + _cruiserWidth > _pictureWidth)
|
||||
if (x < 0 || x >= _pictureWidth || y < 0 || y >= _pictureHeight)
|
||||
{
|
||||
x -= (int)Cruiser.Step;
|
||||
_startPosX = 0;
|
||||
_startPosY = 0;
|
||||
}
|
||||
while (x < 0)
|
||||
{
|
||||
x += (int)Cruiser.Step;
|
||||
}
|
||||
while (y + _cruiserHeight > _pictureHeight)
|
||||
{
|
||||
y -= (int)Cruiser.Step;
|
||||
}
|
||||
while (y < 0)
|
||||
{
|
||||
y += (int)Cruiser.Step;
|
||||
}
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
}
|
||||
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (Cruiser == null)
|
||||
@@ -117,12 +84,8 @@ additionalColor, bool headlights, bool helicopterPad, bool coating, int width, i
|
||||
_startPosY += (int)Cruiser.Step;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Cruiser == null)
|
||||
@@ -133,10 +96,6 @@ additionalColor, bool headlights, bool helicopterPad, bool coating, int width, i
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(Cruiser.AdditionalColor);
|
||||
|
||||
|
||||
//границы автомобиля
|
||||
|
||||
|
||||
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 35, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
|
||||
@@ -144,28 +103,26 @@ additionalColor, bool headlights, bool helicopterPad, bool coating, int width, i
|
||||
30);
|
||||
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
|
||||
|
||||
//если есть доп.фонари
|
||||
if (Cruiser.Headlights)
|
||||
{
|
||||
|
||||
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(Cruiser.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);
|
||||
Point[] points = new Point[3];// нос лодки
|
||||
Point[] points = new Point[3];
|
||||
points[0] = new Point(_startPosX + 100, _startPosY + 5);
|
||||
points[1] = new Point(_startPosX + 100, _startPosY + 55);
|
||||
points[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
|
||||
g.FillPolygon(Brushes.Pink, points);
|
||||
//границы носа лодки
|
||||
Point[] points1 = new Point[3];// нос лодки
|
||||
|
||||
Point[] points1 = new Point[3];
|
||||
points1[0] = new Point(_startPosX + 100, _startPosY + 5);
|
||||
points1[1] = new Point(_startPosX + 100, _startPosY + 55);
|
||||
points1[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
|
||||
@@ -173,7 +130,6 @@ additionalColor, bool headlights, bool helicopterPad, bool coating, int width, i
|
||||
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 15, 10, 10);
|
||||
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 35, 10, 10);
|
||||
|
||||
//если есть ракетные шахты, добавить условие
|
||||
g.DrawRectangle(Pens.Black, _startPosX + 35,
|
||||
_startPosY + 23, 15, 15);
|
||||
g.DrawRectangle(Pens.Black, _startPosX + 50,
|
||||
@@ -181,20 +137,13 @@ additionalColor, bool headlights, bool helicopterPad, bool coating, int width, i
|
||||
|
||||
if (Cruiser.HelicopterPad)
|
||||
{
|
||||
//если есть площадка под вертолет
|
||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 20, 20);
|
||||
}
|
||||
if (Cruiser.Coating)
|
||||
{
|
||||
//если есть спец покрытие для площадки под вертолет
|
||||
g.FillEllipse(Brushes.Red, _startPosX + 90, _startPosY + 20, 20, 20);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Cruiser
|
||||
{
|
||||
|
||||
public partial class CruiserForm : Form
|
||||
{
|
||||
private DrawningCruiser? _drawningCruiser;
|
||||
public CruiserForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@ namespace Cruiser
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user