Merge pull request 'Borschevskaya A.A. Lab Work 3' (#3) from lab3 into lab2
Reviewed-on: http://student.git.athene.tech/pgirl1/PIbd-23_Borschevskaya_A.A._ArmoredCar_Base/pulls/3
This commit is contained in:
commit
9a75ae1a2a
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
internal class DrawningArmoredCar
|
||||
public class DrawningArmoredCar
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
|
@ -5,7 +5,7 @@ using System.Text;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
internal class EntityArmoredCar
|
||||
public class EntityArmoredCar
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
|
28
ArmoredCar/ArmoredCar/FormCar.Designer.cs
generated
28
ArmoredCar/ArmoredCar/FormCar.Designer.cs
generated
@ -39,6 +39,8 @@ namespace ArmoredCar
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonSelectArmoredCar = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -144,11 +146,35 @@ namespace ArmoredCar
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonSelectArmoredCar
|
||||
//
|
||||
this.buttonSelectArmoredCar.Location = new System.Drawing.Point(545, 382);
|
||||
this.buttonSelectArmoredCar.Name = "buttonSelectArmoredCar";
|
||||
this.buttonSelectArmoredCar.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonSelectArmoredCar.TabIndex = 12;
|
||||
this.buttonSelectArmoredCar.Text = "Выбрать";
|
||||
this.buttonSelectArmoredCar.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectArmoredCar.Click += new System.EventHandler(this.buttonSelectArmoredCar_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateModif.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(148, 382);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(109, 23);
|
||||
this.buttonCreateModif.TabIndex = 13;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||
//
|
||||
// FormCar
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonSelectArmoredCar);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
@ -178,6 +204,8 @@ namespace ArmoredCar
|
||||
private System.Windows.Forms.Button buttonLeft;
|
||||
private System.Windows.Forms.Button buttonDown;
|
||||
private System.Windows.Forms.Button buttonRight;
|
||||
private System.Windows.Forms.Button buttonSelectArmoredCar;
|
||||
private System.Windows.Forms.Button buttonCreateModif;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,8 @@ namespace ArmoredCar
|
||||
{
|
||||
private DrawningArmoredCar _car;
|
||||
|
||||
public DrawningArmoredCar SelectedCar { get; private set; }
|
||||
|
||||
public FormCar()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -28,6 +30,16 @@ namespace ArmoredCar
|
||||
_car?.DrawTransport(gr);
|
||||
pictureBoxCar.Image = bmp;
|
||||
}
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_car.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_car.ArmoredCar.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_car.ArmoredCar.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_car.ArmoredCar.BodyColor.Name}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
@ -36,13 +48,14 @@ namespace ArmoredCar
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_car = new DrawningArmoredCar(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_car.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
|
||||
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_car.ArmoredCar.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_car.ArmoredCar.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет: { _car.ArmoredCar.BodyColor.Name}";
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_car = new DrawningArmoredCar(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -81,5 +94,37 @@ namespace ArmoredCar
|
||||
_car?.ChangeBorders(pictureBoxCar.Width, pictureBoxCar.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonSelectArmoredCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_car != null) {
|
||||
SelectedCar = _car;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialogDop = new();
|
||||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialogDop.Color;
|
||||
}
|
||||
_car = new DrawningTank(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
212
ArmoredCar/ArmoredCar/FormMap.Designer.cs
generated
212
ArmoredCar/ArmoredCar/FormMap.Designer.cs
generated
@ -1,212 +0,0 @@
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
partial class FormMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.pictureBoxCar = new System.Windows.Forms.PictureBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// statusStrip1
|
||||
//
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelBodyColor});
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 428);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Size = new System.Drawing.Size(800, 22);
|
||||
this.statusStrip1.TabIndex = 0;
|
||||
this.statusStrip1.Text = "statusStrip1";
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17);
|
||||
this.toolStripStatusLabelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17);
|
||||
this.toolStripStatusLabelWeight.Text = "Вес: ";
|
||||
//
|
||||
// toolStripStatusLabelBodyColor
|
||||
//
|
||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
|
||||
//
|
||||
// pictureBoxCar
|
||||
//
|
||||
this.pictureBoxCar.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxCar.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCar.Name = "pictureBoxCar";
|
||||
this.pictureBoxCar.Size = new System.Drawing.Size(800, 428);
|
||||
this.pictureBoxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxCar.TabIndex = 6;
|
||||
this.pictureBoxCar.TabStop = false;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.button1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.button1.Location = new System.Drawing.Point(42, 382);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(75, 23);
|
||||
this.button1.TabIndex = 7;
|
||||
this.button1.Text = "Создать";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::ArmoredCar.Properties.Resources.Up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(692, 324);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 8;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.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::ArmoredCar.Properties.Resources.Left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(656, 360);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 9;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::ArmoredCar.Properties.Resources.Down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(692, 360);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 10;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.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::ArmoredCar.Properties.Resources.Right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(728, 360);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 11;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(154, 382);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(95, 23);
|
||||
this.button2.TabIndex = 12;
|
||||
this.button2.Text = "Модификация";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Карта 1",
|
||||
"Карта 2"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(42, 26);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(107, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 13;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// FormMap
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.Controls.Add(this.button2);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.pictureBoxCar);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Name = "FormMap";
|
||||
this.Text = "Карта";
|
||||
this.statusStrip1.ResumeLayout(false);
|
||||
this.statusStrip1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.StatusStrip statusStrip1;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private System.Windows.Forms.PictureBox pictureBoxCar;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Button buttonUp;
|
||||
private System.Windows.Forms.Button buttonLeft;
|
||||
private System.Windows.Forms.Button buttonDown;
|
||||
private System.Windows.Forms.Button buttonRight;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.ComboBox comboBoxSelectorMap;
|
||||
}
|
||||
}
|
||||
|
@ -1,112 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
public partial class FormMap : Form
|
||||
{
|
||||
|
||||
private AbstractMap _abstractMap;
|
||||
public FormMap()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
private void SetData(DrawningArmoredCar car)
|
||||
{
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {car.ArmoredCar.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {car.ArmoredCar.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет:{ car.ArmoredCar.BodyColor.Name}";
|
||||
pictureBoxCar.Image = _abstractMap.CreateMap(pictureBoxCar.Width,
|
||||
pictureBoxCar.Height, new DrawningObjectArmCar(car));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var car = new DrawningArmoredCar(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
SetData(car);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение размеров формы
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBoxCar.Image = _abstractMap?.MoveObject(dir);
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Модификация"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var tank = new DrawningTank(rnd.Next(100, 300), rnd.Next(1000,
|
||||
2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0,
|
||||
256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0,
|
||||
256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData(tank);
|
||||
}
|
||||
/// <summary>
|
||||
/// Смена карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender,
|
||||
EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
{
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
|
||||
case "Карта 1":
|
||||
_abstractMap = new MyMapWooden();
|
||||
break;
|
||||
case "Карта 2":
|
||||
_abstractMap = new MyMapLabirinth();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
219
ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.Designer.cs
generated
Normal file
219
ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.Designer.cs
generated
Normal file
@ -0,0 +1,219 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
partial class FormMapWithSetArmoredCars
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRemoveCar = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonAddCar = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRemoveCar);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddCar);
|
||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(204, 554);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
||||
this.maskedTextBoxPosition.TabIndex = 2;
|
||||
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRemoveCar
|
||||
//
|
||||
this.buttonRemoveCar.Location = new System.Drawing.Point(17, 195);
|
||||
this.buttonRemoveCar.Name = "buttonRemoveCar";
|
||||
this.buttonRemoveCar.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonRemoveCar.TabIndex = 3;
|
||||
this.buttonRemoveCar.Text = "Удалить бронемашину";
|
||||
this.buttonRemoveCar.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveArmoredCar_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(17, 287);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::ArmoredCar.Properties.Resources.Down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(91, 504);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 10;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.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::ArmoredCar.Properties.Resources.Right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(127, 504);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 9;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.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::ArmoredCar.Properties.Resources.Left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(55, 504);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 8;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.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::ArmoredCar.Properties.Resources.Up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(91, 468);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 7;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// buttonAddCar
|
||||
//
|
||||
this.buttonAddCar.Location = new System.Drawing.Point(17, 106);
|
||||
this.buttonAddCar.Name = "buttonAddCar";
|
||||
this.buttonAddCar.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonAddCar.TabIndex = 1;
|
||||
this.buttonAddCar.Text = "Добавить бронемашину";
|
||||
this.buttonAddCar.UseVisualStyleBackColor = true;
|
||||
this.buttonAddCar.Click += new System.EventHandler(this.ButtonAddarmoredCar_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Карта 1"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(811, 554);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetArmoredCars
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1015, 554);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Name = "FormMapWithSetArmoredCars";
|
||||
this.Text = "Карта с набором объектов";
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
this.groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private PictureBox pictureBox;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private Button buttonShowOnMap;
|
||||
private Button buttonAddCar;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonRemoveCar;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
}
|
||||
}
|
158
ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs
Normal file
158
ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs
Normal file
@ -0,0 +1,158 @@
|
||||
using ArmoredCar;
|
||||
using System.Windows.Forms;
|
||||
using System;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
public partial class FormMapWithSetArmoredCars : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// </summary>
|
||||
private MapWithSetArmoredCarsGeneric<DrawningObjectArmCar, AbstractMap> _mapArmoredCarsCollectionGeneric;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMapWithSetArmoredCars()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Карта 1":
|
||||
map = new MyMapLabirinth();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapArmoredCarsCollectionGeneric = new MapWithSetArmoredCarsGeneric<DrawningObjectArmCar, AbstractMap>(
|
||||
pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapArmoredCarsCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddarmoredCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapArmoredCarsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormCar form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawningObjectArmCar armoredCar = new(form.SelectedCar);
|
||||
if (_mapArmoredCarsCollectionGeneric + armoredCar > -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapArmoredCarsCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveArmoredCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapArmoredCarsCollectionGeneric - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapArmoredCarsCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapArmoredCarsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapArmoredCarsCollectionGeneric.ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapArmoredCarsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapArmoredCarsCollectionGeneric.ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapArmoredCarsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapArmoredCarsCollectionGeneric.MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
@ -57,7 +57,4 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
190
ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs
Normal file
190
ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs
Normal file
@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
internal class MapWithSetArmoredCarsGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetArmoredCarsGeneric<T> _setCars;
|
||||
/// <summary>
|
||||
/// Карта
|
||||
/// </summary>
|
||||
private readonly U _map;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="map"></param>
|
||||
public MapWithSetArmoredCarsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setCars = new SetArmoredCarsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="car"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(MapWithSetArmoredCarsGeneric<T, U> map, T car)
|
||||
{
|
||||
return map._setCars.Insert(car);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public static T operator -(MapWithSetArmoredCarsGeneric<T, U> map, int
|
||||
position)
|
||||
{
|
||||
return map._setCars.Remove(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawArmoredCars(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Просмотр объекта на карте
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setCars.Count; i++)
|
||||
{
|
||||
var car = _setCars.Get(i);
|
||||
if (car != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
||||
}
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение объекта по крате
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||
/// </summary>
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setCars.Count - 1;
|
||||
for (int i = 0; i < _setCars.Count; i++)
|
||||
{
|
||||
if (_setCars.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setCars.Get(j);
|
||||
if (car != null)
|
||||
{
|
||||
_setCars.Insert(car, i);
|
||||
_setCars.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
Brush brushRoad = new SolidBrush(Color.Gray);
|
||||
Brush brushBox = new SolidBrush(Color.SandyBrown);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
g.FillRectangle(brushRoad, i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth, _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
|
||||
int boxSize = _placeSizeWidth / 7;
|
||||
g.FillRectangle(brushBox, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight + _placeSizeHeight / 5, boxSize, boxSize);
|
||||
g.DrawRectangle(pen, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight + _placeSizeHeight / 5, boxSize, boxSize);
|
||||
g.FillRectangle(brushBox, i * _placeSizeWidth + _placeSizeWidth / 2 - boxSize / 2, j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
g.DrawRectangle(pen, i * _placeSizeWidth + _placeSizeWidth / 2 - boxSize / 2, j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
g.FillRectangle(brushBox, i * _placeSizeWidth + _placeSizeWidth / 2 + boxSize / 2, j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
g.DrawRectangle(pen, i * _placeSizeWidth + _placeSizeWidth / 2 + boxSize / 2, j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawArmoredCars(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
|
||||
for (int i = 0; i < _setCars.Count; i++)
|
||||
{
|
||||
if (_setCars.Get(i) != null) {
|
||||
_setCars.Get(i)?.SetObject(i % width * _placeSizeWidth + 5, i / width * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
_setCars.Get(i)?.DrawningObject(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,8 +16,8 @@ namespace ArmoredCar
|
||||
{
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormMap());
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormMapWithSetArmoredCars());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
97
ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs
Normal file
97
ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
internal class SetArmoredCarsGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetArmoredCarsGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="armoredCar">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T armoredCar)
|
||||
{
|
||||
return Insert(armoredCar, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="armoredCar">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T armoredCar, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
return -1;
|
||||
|
||||
if (!(_places[position] == null))
|
||||
{
|
||||
int index_empty = -1;
|
||||
// поиск первого пустого элемента
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
index_empty = i;
|
||||
}
|
||||
}
|
||||
if (index_empty == -1)
|
||||
return -1;
|
||||
else
|
||||
{
|
||||
for (int i = index_empty; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
_places[position] = armoredCar;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
return null;
|
||||
T armoredCar = _places[position];
|
||||
_places[position] = null;
|
||||
return armoredCar;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user