This commit is contained in:
Александр Разживин 2022-12-05 01:16:33 +04:00
parent ca8768f67f
commit bd60416bcb
8 changed files with 56 additions and 49 deletions

View File

@ -8,8 +8,8 @@ namespace Stormtrooper
{ {
internal class DrawningObjectStormtrooper : IDrawningObject internal class DrawningObjectStormtrooper : IDrawningObject
{ {
private DrowningStormtrooper _stormtrooper = null; private DrawningStormtrooper _stormtrooper = null;
public DrawningObjectStormtrooper(DrowningStormtrooper stormtrooper) public DrawningObjectStormtrooper(DrawningStormtrooper stormtrooper)
{ {
_stormtrooper = stormtrooper; _stormtrooper = stormtrooper;
} }

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Stormtrooper namespace Stormtrooper
{ {
public class DrowningStormtrooper public class DrawningStormtrooper
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность
@ -42,11 +42,11 @@ namespace Stormtrooper
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param> /// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param> /// <param name="bodyColor">Цвет кузова</param>
public DrowningStormtrooper(int speed, float weight, Color bodyColor) public DrawningStormtrooper(int speed, float weight, Color bodyColor)
{ {
Stormtrooper = new EntityStormtrooper(speed, weight, bodyColor); Stormtrooper = new EntityStormtrooper(speed, weight, bodyColor);
} }
protected DrowningStormtrooper(int speed, float weight, Color bodyColor, int StormtrooperWidth, int StormtrooperHeight) : protected DrawningStormtrooper(int speed, float weight, Color bodyColor, int StormtrooperWidth, int StormtrooperHeight) :
this(speed, weight, bodyColor) this(speed, weight, bodyColor)
{ {
_stormtrooperWidth = StormtrooperWidth; _stormtrooperWidth = StormtrooperWidth;

View File

@ -6,9 +6,9 @@ using System.Threading.Tasks;
namespace Stormtrooper namespace Stormtrooper
{ {
internal class DrowningSuperStormtrooper : DrowningStormtrooper internal class DrawningSuperStormtrooper : DrawningStormtrooper
{ {
public DrowningSuperStormtrooper(int speed, float weight, Color bodyColor, Color dopColor, bool bombs, bool rockets, bool sportLine) : base(speed, weight, bodyColor, 90, 120) public DrawningSuperStormtrooper(int speed, float weight, Color bodyColor, Color dopColor, bool bombs, bool rockets, bool sportLine) : base(speed, weight, bodyColor, 90, 120)
{ {
Stormtrooper = new EntitySuperStormtrooper(speed, weight, bodyColor, dopColor, bombs, rockets, sportLine); Stormtrooper = new EntitySuperStormtrooper(speed, weight, bodyColor, dopColor, bombs, rockets, sportLine);
} }
@ -19,7 +19,7 @@ namespace Stormtrooper
return; return;
} }
Brush redBrush = new SolidBrush(Color.Red); Brush redBrush = new SolidBrush(superStormtrooper.BodyColor);
Brush dopBrush = new SolidBrush(superStormtrooper.DopColor); Brush dopBrush = new SolidBrush(superStormtrooper.DopColor);
if (superStormtrooper.Bombs) if (superStormtrooper.Bombs)

View File

@ -35,13 +35,12 @@
this.buttonDeleteMap = new System.Windows.Forms.Button(); this.buttonDeleteMap = new System.Windows.Forms.Button();
this.buttonAddMap = new System.Windows.Forms.Button(); this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMap = new System.Windows.Forms.TextBox(); this.textBoxNewMap = new System.Windows.Forms.TextBox();
this.comboBoxSelector = new System.Windows.Forms.ComboBox(); this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonShowOnMap = new System.Windows.Forms.Button(); this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button(); this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveStormtrooper = new System.Windows.Forms.Button(); this.buttonRemoveStormtrooper = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddStormtrooper = new System.Windows.Forms.Button(); this.buttonAddStormtrooper = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
@ -60,7 +59,6 @@
this.groupBox1.Controls.Add(this.buttonRemoveStormtrooper); this.groupBox1.Controls.Add(this.buttonRemoveStormtrooper);
this.groupBox1.Controls.Add(this.maskedTextBoxPosition); this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonAddStormtrooper); this.groupBox1.Controls.Add(this.buttonAddStormtrooper);
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(637, 0); this.groupBox1.Location = new System.Drawing.Point(637, 0);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
@ -75,7 +73,7 @@
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.groupBoxMaps.Controls.Add(this.buttonAddMap); this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMap); this.groupBoxMaps.Controls.Add(this.textBoxNewMap);
this.groupBoxMaps.Controls.Add(this.comboBoxSelector); this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Location = new System.Drawing.Point(23, 26); this.groupBoxMaps.Location = new System.Drawing.Point(23, 26);
this.groupBoxMaps.Name = "groupBoxMaps"; this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Size = new System.Drawing.Size(203, 290); this.groupBoxMaps.Size = new System.Drawing.Size(203, 290);
@ -120,18 +118,15 @@
this.textBoxNewMap.Size = new System.Drawing.Size(179, 27); this.textBoxNewMap.Size = new System.Drawing.Size(179, 27);
this.textBoxNewMap.TabIndex = 1; this.textBoxNewMap.TabIndex = 1;
// //
// comboBoxSelector // comboBoxSelectorMap
// //
this.comboBoxSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelector.FormattingEnabled = true; this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] { this.comboBoxSelectorMap.Location = new System.Drawing.Point(18, 59);
"Простая карта", this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
"Собственная карта"}); this.comboBoxSelectorMap.Size = new System.Drawing.Size(179, 28);
this.comboBoxSelector.Location = new System.Drawing.Point(18, 59); this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelector.Name = "comboBoxSelector"; this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelector_SelectedIndexChanged);
this.comboBoxSelector.Size = new System.Drawing.Size(179, 28);
this.comboBoxSelector.TabIndex = 0;
this.comboBoxSelector.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelector_SelectedIndexChanged);
// //
// buttonShowOnMap // buttonShowOnMap
// //
@ -181,8 +176,6 @@
this.buttonAddStormtrooper.Text = "Добавить"; this.buttonAddStormtrooper.Text = "Добавить";
this.buttonAddStormtrooper.UseVisualStyleBackColor = true; this.buttonAddStormtrooper.UseVisualStyleBackColor = true;
this.buttonAddStormtrooper.Click += new System.EventHandler(this.ButtonAddStormtrooper_Click); this.buttonAddStormtrooper.Click += new System.EventHandler(this.ButtonAddStormtrooper_Click);
//
// //
// buttonDown // buttonDown
// //
@ -271,7 +264,6 @@
private Button buttonRemoveStormtrooper; private Button buttonRemoveStormtrooper;
private MaskedTextBox maskedTextBoxPosition; private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddStormtrooper; private Button buttonAddStormtrooper;
private ComboBox comboBoxSelectorMap;
private PictureBox pictureBox; private PictureBox pictureBox;
private Button buttonRight; private Button buttonRight;
private Button buttonLeft; private Button buttonLeft;
@ -282,6 +274,6 @@
private Button buttonDeleteMap; private Button buttonDeleteMap;
private Button buttonAddMap; private Button buttonAddMap;
private TextBox textBoxNewMap; private TextBox textBoxNewMap;
private ComboBox comboBoxSelector; private ComboBox comboBoxSelectorMap;
} }
} }

View File

@ -68,18 +68,18 @@ namespace Stormtrooper
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonAddStormtrooper_Click(object sender, EventArgs e) private void ButtonAddStormtrooper_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
FormStormtrooper form = new(); FormStormtrooper form = new();
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
DrawningObjectStormtrooper stormtrooper = new(form.SelectedStormtrooper); DrawningObjectStormtrooper car = new(form.SelectedStormtrooper);
if (_mapCarsCollectionGeneric + stormtrooper != -1) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + car != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -124,11 +124,11 @@ namespace Stormtrooper
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e) private void ButtonShowStorage_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
/// <summary> /// <summary>
/// Вывод карты /// Вывод карты
@ -137,11 +137,11 @@ namespace Stormtrooper
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapCarsCollectionGeneric.ShowOnMap(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
} }
/// <summary> /// <summary>
/// Перемещение /// Перемещение
@ -150,7 +150,8 @@ namespace Stormtrooper
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -172,7 +173,8 @@ namespace Stormtrooper
dir = Direction.Right; dir = Direction.Right;
break; break;
} }
pictureBox.Image = _mapCarsCollectionGeneric.MoveObject(dir); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ??
string.Empty].MoveObject(dir);
} }
private void buttonAddMap_Click(object sender, EventArgs e) private void buttonAddMap_Click(object sender, EventArgs e)
@ -213,5 +215,7 @@ namespace Stormtrooper
{ {
} }
} }
} }

View File

@ -13,9 +13,9 @@ namespace Stormtrooper
public partial class FormStormtrooper : Form public partial class FormStormtrooper : Form
{ {
private DrowningStormtrooper _stormtrooper; private DrawningStormtrooper _stormtrooper;
public DrowningStormtrooper SelectedStormtrooper { get; private set; } public DrawningStormtrooper SelectedStormtrooper { get; private set; }
public FormStormtrooper() public FormStormtrooper()
{ {
@ -46,8 +46,15 @@ namespace Stormtrooper
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_stormtrooper = new DrowningStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000), Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_stormtrooper = new DrawningStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000),
color);
_stormtrooper.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), _stormtrooper.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
SetData(); SetData();
@ -70,7 +77,7 @@ namespace Stormtrooper
{ {
dopColor = dialogDop.Color; dopColor = dialogDop.Color;
} }
_stormtrooper = new DrowningSuperStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000), _stormtrooper = new DrawningSuperStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000),
color, dopColor, color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,
2)), Convert.ToBoolean(rnd.Next(0, 2))); 2)), Convert.ToBoolean(rnd.Next(0, 2)));

View File

@ -161,17 +161,17 @@ namespace Stormtrooper
/// <param name="g"></param> /// <param name="g"></param>
private void DrawCars(Graphics g) private void DrawCars(Graphics g)
{ {
int x = 5; int x = (_pictureWidth / _placeSizeWidth) * _placeSizeWidth - _placeSizeWidth;
int y = 5; int y = 5;
foreach (var boat in _setStormtroopers.GetStormtroopers()) foreach (var boat in _setStormtroopers.GetStormtroopers())
{ {
boat?.SetObject(x, y, _pictureWidth, _pictureHeight); boat?.SetObject(x, y, _pictureWidth, _pictureHeight);
boat?.DrawningObject(g); boat?.DrawningObject(g);
x += _placeSizeWidth; x -= _placeSizeWidth;
if (x + _placeSizeWidth > _pictureWidth) if (x < 0)
{ {
y += _placeSizeHeight; y += _placeSizeHeight;
x = 5; x = (_pictureWidth / _placeSizeWidth) * _placeSizeWidth - _placeSizeWidth;
} }
} }
} }

View File

@ -11,7 +11,7 @@ namespace Stormtrooper
/// <summary> /// <summary>
/// Цвет участка закрытого /// Цвет участка закрытого
/// </summary> /// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Red); private readonly Brush barrierColor = new SolidBrush(Color.Blue);
/// <summary> /// <summary>
/// Цвет участка открытого /// Цвет участка открытого
/// </summary> /// </summary>
@ -41,11 +41,15 @@ namespace Stormtrooper
} }
while (counter < 10) while (counter < 10)
{ {
int x = _random.Next(0, _map.GetLength(0)); int x = _random.Next(2, _map.GetLength(0));
int y = _random.Next(0, _map.GetLength(1)); int y = _random.Next(2, _map.GetLength(1));
if (_map[x, y] == _freeRoad) if (_map[x, y] == _freeRoad)
{ {
_map[x, y] = _barrier; _map[x, y] = _barrier;
_map[x - 1, y] = _barrier;
_map[x, y - 1] = _barrier;
_map[x - 1, y - 1] = _barrier;
counter++; counter++;
} }
} }