рабочие TODO

This commit is contained in:
AnnZhimol 2022-10-04 14:49:13 +04:00
parent c9d1b9f133
commit 7fb61aaaf1
4 changed files with 70 additions and 44 deletions

View File

@ -43,9 +43,9 @@
this.groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
//
// groupBoxTools
//
//
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonRemoveWarship);
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
@ -63,18 +63,18 @@
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);
//
//
// buttonRemoveWarship
//
//
this.buttonRemoveWarship.Location = new System.Drawing.Point(17, 195);
this.buttonRemoveWarship.Name = "buttonRemoveWarship";
this.buttonRemoveWarship.Size = new System.Drawing.Size(175, 35);
@ -82,9 +82,9 @@
this.buttonRemoveWarship.Text = "Удалить корабль";
this.buttonRemoveWarship.UseVisualStyleBackColor = true;
this.buttonRemoveWarship.Click += new System.EventHandler(this.ButtonRemoveWarship_Click);
//
//
// buttonShowStorage
//
//
this.buttonShowStorage.Location = new System.Drawing.Point(17, 287);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
@ -92,9 +92,9 @@
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::Warship.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
@ -103,9 +103,9 @@
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 10;
this.buttonDown.UseVisualStyleBackColor = true;
//
//
// buttonRight
//
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Warship.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
@ -114,9 +114,9 @@
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 9;
this.buttonRight.UseVisualStyleBackColor = true;
//
//
// buttonLeft
//
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Warship.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
@ -125,9 +125,9 @@
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 8;
this.buttonLeft.UseVisualStyleBackColor = true;
//
//
// buttonUp
//
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Warship.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
@ -136,9 +136,9 @@
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 7;
this.buttonUp.UseVisualStyleBackColor = true;
//
//
// buttonShowOnMap
//
//
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
@ -146,9 +146,9 @@
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
//
// buttonAddWarship
//
//
this.buttonAddWarship.Location = new System.Drawing.Point(17, 106);
this.buttonAddWarship.Name = "buttonAddWarship";
this.buttonAddWarship.Size = new System.Drawing.Size(175, 35);
@ -156,29 +156,31 @@
this.buttonAddWarship.Text = "Добавить корабль";
this.buttonAddWarship.UseVisualStyleBackColor = true;
this.buttonAddWarship.Click += new System.EventHandler(this.ButtonAddWarship_Click);
//
//
// comboBoxSelectorMap
//
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {"Простая карта"});
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Первая карта",
"Вторая карта"});
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;
//
//
// FormMapWithSetWarships
//
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1015, 554);
@ -190,6 +192,7 @@
this.groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion

View File

@ -22,11 +22,15 @@ namespace Warship
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case ростая карта":
case ервая карта":
map = new SimpleMap();
break;
case "Вторая карта":
map = new SecondMap();
break;
}
if (map != null)
{

View File

@ -96,29 +96,30 @@ namespace Warship
private void DrawBackground(Graphics gr)
{
Pen pen = new(Color.Black, 3);
Pen pen = new(Color.Black, 5);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{
gr.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
gr.DrawLine(pen, i * _placeSizeWidth+10, j * _placeSizeHeight+2, i * _placeSizeWidth + (int)(_placeSizeWidth*0.8), j * _placeSizeHeight+2);
gr.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9)+10, j * _placeSizeHeight + 2+20);
gr.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20);
}
gr.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight/_placeSizeHeight) * _placeSizeHeight);
}
}
private void DrawWarship(Graphics gr)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _setWarship.Count; i++)
{
for (int i1 = 0; i1 < _pictureWidth / _placeSizeWidth; i1++)
if (_setWarship.Get(i) != null)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{
_setWarship.Get(i)?.SetObject(i1 * _placeSizeWidth, j * _placeSizeHeight, _pictureWidth, _pictureHeight);
}
_setWarship.Get(i).SetObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
_setWarship.Get(i)?.DrawingObject(gr);
}
_setWarship.Get(i)?.DrawingObject(gr);
}
}
}

View File

@ -20,24 +20,36 @@ namespace Warship
public bool Insert(T warship)
{
_places[0] = warship;
return true;
return Insert(warship,0);
}
public bool Insert(T warship, int position)
{
int EmptyEl=position;
int EmptyEl=-1;
if (_places[position]!=null)
if (position>=Count || position < 0)
return false;
if (_places[position] == null)
{
for (int i = position; i < Count; i++)
_places[position] = warship;
return true;
}
else if (_places[position] != null)
{
for (int i = position + 1; i < Count; i++)
if (_places[i] == null)
{
EmptyEl = i;
break;
}
for (int j = EmptyEl; j > position; j--)
_places[j] = _places[j - 1];
if (EmptyEl == -1)
return false;
for (int i = EmptyEl; i > position; i--)
_places[i] = _places[i - 1];
}
_places[position] = warship;
@ -46,12 +58,18 @@ namespace Warship
public bool Remove(int position)
{
if (position >= Count || position < 0 || _places[position]==null)
return false;
_places[position] = null;
return true;
}
public T Get(int position)
{
if (position >= Count || position < 0)
return null;
return _places[position];
}
}