bool broblem
This commit is contained in:
parent
5ae5e17d51
commit
efa7099a7a
@ -55,7 +55,6 @@ namespace Stormtrooper
|
|||||||
}
|
}
|
||||||
public Bitmap MoveObject(Direction direction)
|
public Bitmap MoveObject(Direction direction)
|
||||||
{
|
{
|
||||||
// TODO проверка, что объект может переместится в требуемом направлении
|
|
||||||
bool place = false;
|
bool place = false;
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
@ -87,7 +86,6 @@ namespace Stormtrooper
|
|||||||
int x = _random.Next(0, 10);
|
int x = _random.Next(0, 10);
|
||||||
int y = _random.Next(0, 10);
|
int y = _random.Next(0, 10);
|
||||||
_drawningObject.SetObject(x, y, _width, _height);
|
_drawningObject.SetObject(x, y, _width, _height);
|
||||||
// TODO првоерка, что объект не "накладывается" на закрытые участки
|
|
||||||
while (!CheckEnoughPlace(0, 0))
|
while (!CheckEnoughPlace(0, 0))
|
||||||
{
|
{
|
||||||
x += 10;
|
x += 10;
|
||||||
|
@ -28,12 +28,124 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.components = new System.ComponentModel.Container();
|
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||||
|
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRemoveStormtrooper = new System.Windows.Forms.Button();
|
||||||
|
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.buttonAddStormtrooper = new System.Windows.Forms.Button();
|
||||||
|
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||||
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.buttonShowOnMap);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonShowStorage);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonRemoveStormtrooper);
|
||||||
|
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonAddStormtrooper);
|
||||||
|
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
|
||||||
|
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
|
this.groupBox1.Location = new System.Drawing.Point(550, 0);
|
||||||
|
this.groupBox1.Name = "groupBox1";
|
||||||
|
this.groupBox1.Size = new System.Drawing.Size(250, 450);
|
||||||
|
this.groupBox1.TabIndex = 0;
|
||||||
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "groupBox1";
|
||||||
|
//
|
||||||
|
// buttonShowOnMap
|
||||||
|
//
|
||||||
|
this.buttonShowOnMap.Location = new System.Drawing.Point(41, 344);
|
||||||
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
|
this.buttonShowOnMap.Size = new System.Drawing.Size(142, 29);
|
||||||
|
this.buttonShowOnMap.TabIndex = 5;
|
||||||
|
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||||
|
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||||
|
//
|
||||||
|
// buttonShowStorage
|
||||||
|
//
|
||||||
|
this.buttonShowStorage.Location = new System.Drawing.Point(41, 250);
|
||||||
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
|
this.buttonShowStorage.Size = new System.Drawing.Size(185, 29);
|
||||||
|
this.buttonShowStorage.TabIndex = 4;
|
||||||
|
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||||
|
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||||
|
//
|
||||||
|
// buttonRemoveStormtrooper
|
||||||
|
//
|
||||||
|
this.buttonRemoveStormtrooper.Location = new System.Drawing.Point(41, 194);
|
||||||
|
this.buttonRemoveStormtrooper.Name = "buttonRemoveStormtrooper";
|
||||||
|
this.buttonRemoveStormtrooper.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonRemoveStormtrooper.TabIndex = 3;
|
||||||
|
this.buttonRemoveStormtrooper.Text = "Удалить";
|
||||||
|
this.buttonRemoveStormtrooper.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRemoveStormtrooper.Click += new System.EventHandler(this.ButtonRemoveStormtrooper_Click);
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(41, 146);
|
||||||
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
this.maskedTextBoxPosition.Size = new System.Drawing.Size(125, 27);
|
||||||
|
this.maskedTextBoxPosition.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// buttonAddStormtrooper
|
||||||
|
//
|
||||||
|
this.buttonAddStormtrooper.Location = new System.Drawing.Point(41, 91);
|
||||||
|
this.buttonAddStormtrooper.Name = "buttonAddStormtrooper";
|
||||||
|
this.buttonAddStormtrooper.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonAddStormtrooper.TabIndex = 1;
|
||||||
|
this.buttonAddStormtrooper.Text = "Добавить";
|
||||||
|
this.buttonAddStormtrooper.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddStormtrooper.Click += new System.EventHandler(this.ButtonAddStormtrooper_Click);
|
||||||
|
//
|
||||||
|
// comboBoxSelectorMap
|
||||||
|
//
|
||||||
|
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(41, 35);
|
||||||
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28);
|
||||||
|
this.comboBoxSelectorMap.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// 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(550, 450);
|
||||||
|
this.pictureBox.TabIndex = 1;
|
||||||
|
this.pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormMapWithSetStormtroopers
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.pictureBox);
|
||||||
|
this.Controls.Add(this.groupBox1);
|
||||||
|
this.Name = "FormMapWithSetStormtroopers";
|
||||||
this.Text = "FormMapWithSetStormtroopers";
|
this.Text = "FormMapWithSetStormtroopers";
|
||||||
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
this.groupBox1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private Button buttonShowOnMap;
|
||||||
|
private Button buttonShowStorage;
|
||||||
|
private Button buttonRemoveStormtrooper;
|
||||||
|
private MaskedTextBox maskedTextBoxPosition;
|
||||||
|
private Button buttonAddStormtrooper;
|
||||||
|
private ComboBox comboBoxSelectorMap;
|
||||||
|
private PictureBox pictureBox;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,14 +7,159 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using static System.Windows.Forms.DataFormats;
|
||||||
|
|
||||||
namespace Stormtrooper
|
namespace Stormtrooper
|
||||||
{
|
{
|
||||||
public partial class FormMapWithSetStormtroopers : Form
|
public partial class FormMapWithSetStormtroopers : Form
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Объект от класса карты с набором объектов
|
||||||
|
/// </summary>
|
||||||
|
private MapWithSetStormtroopersGeneric<DrawningObjectStormtrooper, AbstractMap> _mapCarsCollectionGeneric;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
public FormMapWithSetStormtroopers()
|
public FormMapWithSetStormtroopers()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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;
|
||||||
|
}
|
||||||
|
if (map != null)
|
||||||
|
{
|
||||||
|
_mapCarsCollectionGeneric = new
|
||||||
|
MapWithSetStormtroopersGeneric<DrawningObjectStormtrooper, AbstractMap>(
|
||||||
|
pictureBox.Width, pictureBox.Height, map);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_mapCarsCollectionGeneric = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddStormtrooper_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapCarsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormStormtrooper form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
DrawningObjectStormtrooper car = new(form.SelectedStormtrooper);
|
||||||
|
if (_mapCarsCollectionGeneric + car)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRemoveStormtrooper_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 (_mapCarsCollectionGeneric - pos)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapCarsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapCarsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapCarsCollectionGeneric.ShowOnMap();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapCarsCollectionGeneric == 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 = _mapCarsCollectionGeneric.MoveObject(dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,64 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<root>
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
@ -29,7 +29,7 @@ namespace Stormtrooper
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Набор объектов
|
/// Набор объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly SetStormtroopersGeneric<T> _setCars;
|
private readonly SetStormtroopersGeneric<T> _setStormtroopers;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Карта
|
/// Карта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -44,7 +44,7 @@ namespace Stormtrooper
|
|||||||
{
|
{
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
int height = picHeight / _placeSizeHeight;
|
int height = picHeight / _placeSizeHeight;
|
||||||
_setCars = new SetStormtroopersGeneric<T>(width * height);
|
_setStormtroopers = new SetStormtroopersGeneric<T>(width * height);
|
||||||
_pictureWidth = picWidth;
|
_pictureWidth = picWidth;
|
||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_map = map;
|
_map = map;
|
||||||
@ -57,7 +57,7 @@ namespace Stormtrooper
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool operator + (MapWithSetStormtroopersGeneric<T, U> map, T car)
|
public static bool operator + (MapWithSetStormtroopersGeneric<T, U> map, T car)
|
||||||
{
|
{
|
||||||
return map._setCars.Insert(car);
|
return map._setStormtroopers.Insert(car);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перегрузка оператора вычитания
|
/// Перегрузка оператора вычитания
|
||||||
@ -68,7 +68,7 @@ namespace Stormtrooper
|
|||||||
public static bool operator - (MapWithSetStormtroopersGeneric<T, U> map, int
|
public static bool operator - (MapWithSetStormtroopersGeneric<T, U> map, int
|
||||||
position)
|
position)
|
||||||
{
|
{
|
||||||
return map._setCars.Remove(position);
|
return map._setStormtroopers.Remove(position);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вывод всего набора объектов
|
/// Вывод всего набора объектов
|
||||||
@ -89,9 +89,9 @@ namespace Stormtrooper
|
|||||||
public Bitmap ShowOnMap()
|
public Bitmap ShowOnMap()
|
||||||
{
|
{
|
||||||
Shaking();
|
Shaking();
|
||||||
for (int i = 0; i < _setCars.Count; i++)
|
for (int i = 0; i < _setStormtroopers.Count; i++)
|
||||||
{
|
{
|
||||||
var car = _setCars.Get(i);
|
var car = _setStormtroopers.Get(i);
|
||||||
if (car != null)
|
if (car != null)
|
||||||
{
|
{
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
||||||
@ -117,18 +117,18 @@ namespace Stormtrooper
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Shaking()
|
private void Shaking()
|
||||||
{
|
{
|
||||||
int j = _setCars.Count - 1;
|
int j = _setStormtroopers.Count - 1;
|
||||||
for (int i = 0; i < _setCars.Count; i++)
|
for (int i = 0; i < _setStormtroopers.Count; i++)
|
||||||
{
|
{
|
||||||
if (_setCars.Get(i) == null)
|
if (_setStormtroopers.Get(i) == null)
|
||||||
{
|
{
|
||||||
for (; j > i; j--)
|
for (; j > i; j--)
|
||||||
{
|
{
|
||||||
var car = _setCars.Get(j);
|
var car = _setStormtroopers.Get(j);
|
||||||
if (car != null)
|
if (car != null)
|
||||||
{
|
{
|
||||||
_setCars.Insert(car, i);
|
_setStormtroopers.Insert(car, i);
|
||||||
_setCars.Remove(j);
|
_setStormtroopers.Remove(j);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,10 +163,18 @@ namespace Stormtrooper
|
|||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
private void DrawCars(Graphics g)
|
private void DrawCars(Graphics g)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _setCars.Count; i++)
|
int x = 5;
|
||||||
|
int y = 5;
|
||||||
|
for (int i = 0; i < _setStormtroopers.Count; i++)
|
||||||
{
|
{
|
||||||
// TODO установка позиции
|
_setStormtroopers.Get(i)?.SetObject(x, y, _pictureWidth, _pictureHeight);
|
||||||
_setCars.Get(i)?.DrawningObject(g);
|
_setStormtroopers.Get(i)?.DrawningObject(g);
|
||||||
|
x += _placeSizeWidth;
|
||||||
|
if (x + _placeSizeWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
y += _placeSizeHeight;
|
||||||
|
x = 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ namespace Stormtrooper
|
|||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="count"></param>
|
/// <param name="count"></param>
|
||||||
public SetCarsGeneric(int count)
|
public SetStormtroopersGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T[count];
|
_places = new T[count];
|
||||||
}
|
}
|
||||||
@ -30,10 +30,17 @@ namespace Stormtrooper
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="car">Добавляемый автомобиль</param>
|
/// <param name="car">Добавляемый автомобиль</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Insert(T car)
|
public int Insert(T stormtrooper)
|
||||||
{
|
{
|
||||||
// TODO вставка в начало набора
|
for (int i = 0; i < _places.Length; i++)
|
||||||
return true;
|
{
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
_places[i] = stormtrooper;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
@ -48,6 +55,9 @@ namespace Stormtrooper
|
|||||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||||
// TODO вставка по позиции
|
// TODO вставка по позиции
|
||||||
|
|
||||||
|
// hz kak sdelat s bool
|
||||||
|
|
||||||
_places[position] = car;
|
_places[position] = car;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -60,6 +70,7 @@ namespace Stormtrooper
|
|||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
// TODO удаление объекта из массива, присовив элементу массива значение null
|
// TODO удаление объекта из массива, присовив элементу массива значение null
|
||||||
|
// hz kak sdelat s bool
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -69,7 +80,10 @@ namespace Stormtrooper
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T Get(int position)
|
public T Get(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (position < 0 || position > _places.Length)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user