Changes forms
This commit is contained in:
parent
64d37b837f
commit
e2969fef09
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Warship
|
namespace Warship
|
||||||
{
|
{
|
||||||
internal enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
Up = 1,
|
Up = 1,
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Warship
|
namespace Warship
|
||||||
{
|
{
|
||||||
internal class DrawingWarship
|
public class DrawingWarship
|
||||||
{
|
{
|
||||||
public EntityWarship Warship { get; protected set; }
|
public EntityWarship Warship { get; protected set; }
|
||||||
protected int _startPosX;
|
protected int _startPosX;
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Warship
|
namespace Warship
|
||||||
{
|
{
|
||||||
internal class EntityWarship
|
public class EntityWarship
|
||||||
{
|
{
|
||||||
public int Speed { get; private set; }
|
public int Speed { get; private set; }
|
||||||
public float Weight { get; private set; }
|
public float Weight { get; private set; }
|
||||||
|
200
Warship/Warship/FormMap.Designer.cs
generated
200
Warship/Warship/FormMap.Designer.cs
generated
@ -1,200 +0,0 @@
|
|||||||
namespace Warship
|
|
||||||
{
|
|
||||||
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.pictureBoxWarship = new System.Windows.Forms.PictureBox();
|
|
||||||
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.buttonCreate = 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.buttonDown = new System.Windows.Forms.Button();
|
|
||||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
|
||||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit();
|
|
||||||
this.statusStrip1.SuspendLayout();
|
|
||||||
this.SuspendLayout();
|
|
||||||
//
|
|
||||||
// pictureBoxWarship
|
|
||||||
//
|
|
||||||
this.pictureBoxWarship.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
||||||
this.pictureBoxWarship.Location = new System.Drawing.Point(0, 0);
|
|
||||||
this.pictureBoxWarship.Name = "pictureBoxWarship";
|
|
||||||
this.pictureBoxWarship.Size = new System.Drawing.Size(800, 450);
|
|
||||||
this.pictureBoxWarship.TabIndex = 0;
|
|
||||||
this.pictureBoxWarship.TabStop = false;
|
|
||||||
//
|
|
||||||
// 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 = 1;
|
|
||||||
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(29, 17);
|
|
||||||
this.toolStripStatusLabelWeight.Text = "Вес:";
|
|
||||||
//
|
|
||||||
// toolStripStatusLabelBodyColor
|
|
||||||
//
|
|
||||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
|
||||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
|
|
||||||
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
|
|
||||||
//
|
|
||||||
// buttonCreate
|
|
||||||
//
|
|
||||||
this.buttonCreate.Location = new System.Drawing.Point(28, 381);
|
|
||||||
this.buttonCreate.Name = "buttonCreate";
|
|
||||||
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
|
|
||||||
this.buttonCreate.TabIndex = 2;
|
|
||||||
this.buttonCreate.Text = "Создать";
|
|
||||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
|
||||||
//
|
|
||||||
// buttonRight
|
|
||||||
//
|
|
||||||
this.buttonRight.BackgroundImage = global::Warship.Properties.Resources.arrowRight;
|
|
||||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
|
||||||
this.buttonRight.Location = new System.Drawing.Point(700, 351);
|
|
||||||
this.buttonRight.Name = "buttonRight";
|
|
||||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
|
||||||
this.buttonRight.TabIndex = 3;
|
|
||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
|
||||||
//
|
|
||||||
// buttonLeft
|
|
||||||
//
|
|
||||||
this.buttonLeft.BackgroundImage = global::Warship.Properties.Resources.arrowLeft;
|
|
||||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
|
||||||
this.buttonLeft.Location = new System.Drawing.Point(628, 351);
|
|
||||||
this.buttonLeft.Name = "buttonLeft";
|
|
||||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
|
||||||
this.buttonLeft.TabIndex = 4;
|
|
||||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
|
||||||
//
|
|
||||||
// buttonUp
|
|
||||||
//
|
|
||||||
this.buttonUp.BackgroundImage = global::Warship.Properties.Resources.arrowUp;
|
|
||||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
|
||||||
this.buttonUp.Location = new System.Drawing.Point(664, 334);
|
|
||||||
this.buttonUp.Name = "buttonUp";
|
|
||||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
|
||||||
this.buttonUp.TabIndex = 5;
|
|
||||||
this.buttonUp.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
|
||||||
//
|
|
||||||
// buttonDown
|
|
||||||
//
|
|
||||||
this.buttonDown.BackgroundImage = global::Warship.Properties.Resources.arrowDown;
|
|
||||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
|
||||||
this.buttonDown.Location = new System.Drawing.Point(664, 381);
|
|
||||||
this.buttonDown.Name = "buttonDown";
|
|
||||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
|
||||||
this.buttonDown.TabIndex = 6;
|
|
||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
|
||||||
//
|
|
||||||
// buttonCreateModif
|
|
||||||
//
|
|
||||||
this.buttonCreateModif.Location = new System.Drawing.Point(120, 381);
|
|
||||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
|
||||||
this.buttonCreateModif.Size = new System.Drawing.Size(100, 23);
|
|
||||||
this.buttonCreateModif.TabIndex = 7;
|
|
||||||
this.buttonCreateModif.Text = "Модификация";
|
|
||||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonCreateModif.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[] {
|
|
||||||
"Первая карта",
|
|
||||||
"Вторая карта"});
|
|
||||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
|
|
||||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
|
||||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
|
|
||||||
this.comboBoxSelectorMap.TabIndex = 8;
|
|
||||||
//
|
|
||||||
// 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.buttonCreateModif);
|
|
||||||
this.Controls.Add(this.buttonDown);
|
|
||||||
this.Controls.Add(this.buttonUp);
|
|
||||||
this.Controls.Add(this.buttonLeft);
|
|
||||||
this.Controls.Add(this.buttonRight);
|
|
||||||
this.Controls.Add(this.buttonCreate);
|
|
||||||
this.Controls.Add(this.statusStrip1);
|
|
||||||
this.Controls.Add(this.pictureBoxWarship);
|
|
||||||
this.Name = "FormMap";
|
|
||||||
this.Text = "Form1";
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).EndInit();
|
|
||||||
this.statusStrip1.ResumeLayout(false);
|
|
||||||
this.statusStrip1.PerformLayout();
|
|
||||||
this.ResumeLayout(false);
|
|
||||||
this.PerformLayout();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
private PictureBox pictureBoxWarship;
|
|
||||||
private StatusStrip statusStrip1;
|
|
||||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
|
||||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
|
||||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
|
||||||
private Button buttonCreate;
|
|
||||||
private Button buttonRight;
|
|
||||||
private Button buttonLeft;
|
|
||||||
private Button buttonUp;
|
|
||||||
private Button buttonDown;
|
|
||||||
private Button buttonCreateModif;
|
|
||||||
private ComboBox comboBoxSelectorMap;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +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 Warship
|
|
||||||
{
|
|
||||||
public partial class FormMap : Form
|
|
||||||
{
|
|
||||||
private AbstractMap _abstractMap;
|
|
||||||
public FormMap()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_abstractMap = new SimpleMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetData(DrawingWarship warship)
|
|
||||||
{
|
|
||||||
toolStripStatusLabelSpeed.Text = $"Cкорость: {warship.Warship.Speed}";
|
|
||||||
toolStripStatusLabelWeight.Text = $"Вес: {warship.Warship.Weight}";
|
|
||||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {warship.Warship.BodyColor.Name}";
|
|
||||||
pictureBoxWarship.Image = _abstractMap.CreateMap(pictureBoxWarship.Width, pictureBoxWarship.Height, new DrawingObjectWarship(warship));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Random rnd = new();
|
|
||||||
var warship = new DrawingWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
||||||
SetData(warship);
|
|
||||||
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
pictureBoxWarship.Image = _abstractMap?.MoveObject(dir);
|
|
||||||
}
|
|
||||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Random rnd = new();
|
|
||||||
var warship = new DrawingAdvancedWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), 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)), Convert.ToBoolean(rnd.Next(0, 2)));
|
|
||||||
SetData(warship);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
switch (comboBoxSelectorMap.Text)
|
|
||||||
{
|
|
||||||
case "Простая карта":
|
|
||||||
_abstractMap = new SimpleMap();
|
|
||||||
break;
|
|
||||||
case "Вторая карта":
|
|
||||||
_abstractMap = new SecondMap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
168
Warship/Warship/FormMapWithSetWarships.Designer.cs
generated
Normal file
168
Warship/Warship/FormMapWithSetWarships.Designer.cs
generated
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
namespace Warship
|
||||||
|
{
|
||||||
|
partial class FormMapWithSetWarships
|
||||||
|
{
|
||||||
|
/// <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.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||||
|
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRemoveWarship = new System.Windows.Forms.Button();
|
||||||
|
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.buttonAddWarship = new System.Windows.Forms.Button();
|
||||||
|
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||||
|
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||||
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.groupBoxTools.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonRemoveWarship);
|
||||||
|
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonAddWarship);
|
||||||
|
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||||
|
this.groupBoxTools.Controls.Add(this.pictureBox1);
|
||||||
|
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
|
this.groupBoxTools.Location = new System.Drawing.Point(600, 0);
|
||||||
|
this.groupBoxTools.Name = "groupBoxTools";
|
||||||
|
this.groupBoxTools.Size = new System.Drawing.Size(200, 450);
|
||||||
|
this.groupBoxTools.TabIndex = 0;
|
||||||
|
this.groupBoxTools.TabStop = false;
|
||||||
|
this.groupBoxTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// buttonShowOnMap
|
||||||
|
//
|
||||||
|
this.buttonShowOnMap.Location = new System.Drawing.Point(25, 317);
|
||||||
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
|
this.buttonShowOnMap.Size = new System.Drawing.Size(163, 23);
|
||||||
|
this.buttonShowOnMap.TabIndex = 7;
|
||||||
|
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||||
|
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||||
|
//
|
||||||
|
// buttonShowStorage
|
||||||
|
//
|
||||||
|
this.buttonShowStorage.Location = new System.Drawing.Point(25, 253);
|
||||||
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
|
this.buttonShowStorage.Size = new System.Drawing.Size(163, 23);
|
||||||
|
this.buttonShowStorage.TabIndex = 6;
|
||||||
|
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||||
|
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||||
|
//
|
||||||
|
// buttonRemoveWarship
|
||||||
|
//
|
||||||
|
this.buttonRemoveWarship.Location = new System.Drawing.Point(25, 188);
|
||||||
|
this.buttonRemoveWarship.Name = "buttonRemoveWarship";
|
||||||
|
this.buttonRemoveWarship.Size = new System.Drawing.Size(163, 23);
|
||||||
|
this.buttonRemoveWarship.TabIndex = 5;
|
||||||
|
this.buttonRemoveWarship.Text = "Удалить корабль";
|
||||||
|
this.buttonRemoveWarship.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRemoveWarship.Click += new System.EventHandler(this.ButtonRemoveWarship_Click);
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(25, 123);
|
||||||
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
this.maskedTextBoxPosition.Size = new System.Drawing.Size(163, 23);
|
||||||
|
this.maskedTextBoxPosition.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// buttonAddWarship
|
||||||
|
//
|
||||||
|
this.buttonAddWarship.Location = new System.Drawing.Point(25, 62);
|
||||||
|
this.buttonAddWarship.Name = "buttonAddWarship";
|
||||||
|
this.buttonAddWarship.Size = new System.Drawing.Size(163, 23);
|
||||||
|
this.buttonAddWarship.TabIndex = 3;
|
||||||
|
this.buttonAddWarship.Text = "Добавить корабль";
|
||||||
|
this.buttonAddWarship.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddWarship.Click += new System.EventHandler(this.ButtonAddWarship_Click);
|
||||||
|
//
|
||||||
|
// comboBoxSelectorMap
|
||||||
|
//
|
||||||
|
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
|
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||||
|
"Первая карта",
|
||||||
|
"Вторая карта"});
|
||||||
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(25, 22);
|
||||||
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(163, 23);
|
||||||
|
this.comboBoxSelectorMap.TabIndex = 2;
|
||||||
|
this.comboBoxSelectorMap.Click += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// pictureBox1
|
||||||
|
//
|
||||||
|
this.pictureBox1.Location = new System.Drawing.Point(3, 12);
|
||||||
|
this.pictureBox1.Name = "pictureBox1";
|
||||||
|
this.pictureBox1.Size = new System.Drawing.Size(197, 438);
|
||||||
|
this.pictureBox1.TabIndex = 0;
|
||||||
|
this.pictureBox1.TabStop = false;
|
||||||
|
//
|
||||||
|
// 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(600, 450);
|
||||||
|
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(800, 450);
|
||||||
|
this.Controls.Add(this.pictureBox);
|
||||||
|
this.Controls.Add(this.groupBoxTools);
|
||||||
|
this.Name = "FormMapWithSetWarships";
|
||||||
|
this.Text = "FormMapWithSetWarships";
|
||||||
|
this.groupBoxTools.ResumeLayout(false);
|
||||||
|
this.groupBoxTools.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private PictureBox pictureBox1;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button buttonAddWarship;
|
||||||
|
private ComboBox comboBoxSelectorMap;
|
||||||
|
private Button buttonShowOnMap;
|
||||||
|
private Button buttonShowStorage;
|
||||||
|
private Button buttonRemoveWarship;
|
||||||
|
private MaskedTextBox maskedTextBoxPosition;
|
||||||
|
}
|
||||||
|
}
|
134
Warship/Warship/FormMapWithSetWarships.cs
Normal file
134
Warship/Warship/FormMapWithSetWarships.cs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
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 Warship
|
||||||
|
{
|
||||||
|
public partial class FormMapWithSetWarships : Form
|
||||||
|
{
|
||||||
|
private MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap> _mapWarshipsCollectionGeneric;
|
||||||
|
|
||||||
|
public FormMapWithSetWarships()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
AbstractMap map = null;
|
||||||
|
|
||||||
|
switch (comboBoxSelectorMap.Text)
|
||||||
|
{
|
||||||
|
case "Первая карта":
|
||||||
|
map = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "Вторая карта":
|
||||||
|
map = new SecondMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (map != null)
|
||||||
|
{
|
||||||
|
_mapWarshipsCollectionGeneric = new MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap>(
|
||||||
|
pictureBox.Width, pictureBox.Height, map);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_mapWarshipsCollectionGeneric = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAddWarship_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapWarshipsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormWarship form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
DrawingObjectWarship warship = new(form.SelectedWarship);
|
||||||
|
if (_mapWarshipsCollectionGeneric + warship >= 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRemoveWarship_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 (_mapWarshipsCollectionGeneric - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapWarshipsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapWarshipsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowOnMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapWarshipsCollectionGeneric == 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 = _mapWarshipsCollectionGeneric.MoveObject(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -57,7 +57,4 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</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>
|
</root>
|
13
Warship/Warship/FormWarship.Designer.cs
generated
13
Warship/Warship/FormWarship.Designer.cs
generated
@ -39,6 +39,7 @@
|
|||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSelectedWarship = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -146,11 +147,22 @@
|
|||||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||||
//
|
//
|
||||||
|
// buttonSelectedWarship
|
||||||
|
//
|
||||||
|
this.buttonSelectedWarship.Location = new System.Drawing.Point(512, 381);
|
||||||
|
this.buttonSelectedWarship.Name = "buttonSelectedWarship";
|
||||||
|
this.buttonSelectedWarship.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSelectedWarship.TabIndex = 8;
|
||||||
|
this.buttonSelectedWarship.Text = "Выбрать";
|
||||||
|
this.buttonSelectedWarship.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSelectedWarship.Click += new System.EventHandler(this.ButtonSelect_Click);
|
||||||
|
//
|
||||||
// FormWarship
|
// FormWarship
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
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.buttonSelectedWarship);
|
||||||
this.Controls.Add(this.buttonCreateModif);
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
@ -182,5 +194,6 @@
|
|||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonCreateModif;
|
private Button buttonCreateModif;
|
||||||
|
private Button buttonSelectedWarship;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,8 @@ namespace Warship
|
|||||||
{
|
{
|
||||||
private DrawingWarship _warship;
|
private DrawingWarship _warship;
|
||||||
|
|
||||||
|
public DrawingWarship SelectedWarship { get; private set; }
|
||||||
|
|
||||||
public FormWarship()
|
public FormWarship()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -74,5 +76,10 @@ namespace Warship
|
|||||||
SetData();
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
private void ButtonSelect_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedWarship = _warship;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ using System.Threading.Tasks;
|
|||||||
namespace Warship
|
namespace Warship
|
||||||
{
|
{
|
||||||
internal class MapWithSetWarshipsGeneric<T, U>
|
internal class MapWithSetWarshipsGeneric<T, U>
|
||||||
where T : class, IDrawingObject
|
where T : class, IDrawingObject
|
||||||
where U : AbstractMap
|
where U : AbstractMap
|
||||||
{
|
{
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
@ -49,9 +49,13 @@ namespace Warship
|
|||||||
public Bitmap ShowOnMap()
|
public Bitmap ShowOnMap()
|
||||||
{
|
{
|
||||||
Shaking();
|
Shaking();
|
||||||
foreach (var warship in _setWarship.GetWarships())
|
for (int i = 0; i < _setWarship.Count; i++)
|
||||||
{
|
{
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, warship);
|
var warship = _setWarship.Get(i);
|
||||||
|
if (warship != null)
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, warship);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new(_pictureWidth, _pictureHeight);
|
return new(_pictureWidth, _pictureHeight);
|
||||||
}
|
}
|
||||||
@ -70,11 +74,11 @@ namespace Warship
|
|||||||
int j = _setWarship.Count - 1;
|
int j = _setWarship.Count - 1;
|
||||||
for (int i = 0; i < _setWarship.Count; i++)
|
for (int i = 0; i < _setWarship.Count; i++)
|
||||||
{
|
{
|
||||||
if (_setWarship[i] == null)
|
if (_setWarship.Get(i) == null)
|
||||||
{
|
{
|
||||||
for (; j > i; j--)
|
for (; j > i; j--)
|
||||||
{
|
{
|
||||||
var warship = _setWarship[j];
|
var warship = _setWarship.Get(j);
|
||||||
if (warship != null)
|
if (warship != null)
|
||||||
{
|
{
|
||||||
_setWarship.Insert(warship, i);
|
_setWarship.Insert(warship, i);
|
||||||
@ -109,13 +113,14 @@ namespace Warship
|
|||||||
{
|
{
|
||||||
int width = _pictureWidth / _placeSizeWidth;
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
int height = _pictureHeight / _placeSizeHeight;
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
foreach (var warship in _setWarship.GetWarships())
|
for (int i = 0; i < _setWarship.Count; i++)
|
||||||
{
|
{
|
||||||
warship.SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
if (_setWarship.Get(i) != null)
|
||||||
warship.DrawingObject(gr);
|
{
|
||||||
i++;
|
_setWarship.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||||
|
_setWarship.Get(i)?.DrawingObject(gr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace Warship
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormMap());
|
Application.Run(new FormMapWithSetWarships());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,73 +9,69 @@ namespace Warship
|
|||||||
internal class SetWarshipsGeneric<T>
|
internal class SetWarshipsGeneric<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
private readonly List<T> _places;
|
private readonly T[] _places;
|
||||||
|
|
||||||
public int Count => _places.Count;
|
public int Count => _places.Length;
|
||||||
|
|
||||||
private readonly int _maxCount;
|
|
||||||
|
|
||||||
public SetWarshipsGeneric(int count)
|
public SetWarshipsGeneric(int count)
|
||||||
{
|
{
|
||||||
_maxCount = count;
|
_places = new T[count];
|
||||||
_places = new List<T>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T warship)
|
public int Insert(T warship)
|
||||||
{
|
{
|
||||||
if (_places.Count + 1 >= _maxCount)
|
return Insert(warship, 0);
|
||||||
return -1;
|
|
||||||
_places.Insert(0, warship);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T warship, int position)
|
public int Insert(T warship, int position)
|
||||||
{
|
{
|
||||||
if (position >= _maxCount || position < 0)
|
int EmptyEl = -1;
|
||||||
|
|
||||||
|
if (position >= Count || position < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (_places.Count + 1 >= _maxCount)
|
|
||||||
return -1;
|
if (_places[position] == null)
|
||||||
_places.Insert(position, warship);
|
{
|
||||||
return position;
|
_places[position] = warship;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (_places[position] != null)
|
||||||
|
{
|
||||||
|
for (int i = position + 1; i < Count; i++)
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
EmptyEl = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EmptyEl == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (int i = EmptyEl; i > position; i--)
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
_places[position] = warship;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (position >= _maxCount || position < 0)
|
if (position >= Count || position < 0 || _places[position] == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
T deleted = _places[position];
|
T deleted = _places[position];
|
||||||
_places.RemoveAt(position);
|
_places[position] = null;
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T this[int position]
|
public T Get(int position)
|
||||||
{
|
{
|
||||||
get
|
if (position >= Count || position < 0)
|
||||||
{
|
return null;
|
||||||
if (position < 0 || position >= _maxCount)
|
|
||||||
return null;
|
return _places[position];
|
||||||
return _places[position];
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (position < 0 || position >= _maxCount)
|
|
||||||
Insert(value, position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public IEnumerable<T> GetWarships()
|
|
||||||
{
|
|
||||||
foreach (var warship in _places)
|
|
||||||
{
|
|
||||||
if (warship != null)
|
|
||||||
{
|
|
||||||
yield return warship;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user