changes forms

This commit is contained in:
Nap 2022-10-26 18:47:48 +04:00
parent 544a3d3006
commit bed8d7d922
13 changed files with 480 additions and 341 deletions

View File

@ -9,7 +9,7 @@ namespace Battleship
/// <summary>
/// Направление перемещения
/// </summary>
internal enum Direction
public enum Direction
{
None = 0,
Up = 1,

View File

@ -9,7 +9,7 @@ namespace Battleship
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
internal class DrawningBattleship
public class DrawningBattleship
{
/// <summary>
/// Класс-сущность

View File

@ -9,7 +9,7 @@ namespace Battleship
/// <summary>
/// Класс-сущность "Боевой корабль"
/// </summary>
internal class EntityBattleship
public class EntityBattleship
{
/// <summary>
/// Скорость

View File

@ -39,6 +39,7 @@
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabeBodylColor = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStripBattleship = new System.Windows.Forms.StatusStrip();
this.buttonSelectBatlleship = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBattleship)).BeginInit();
this.statusStripBattleship.SuspendLayout();
this.SuspendLayout();
@ -149,12 +150,23 @@
this.statusStripBattleship.TabIndex = 1;
this.statusStripBattleship.Text = "statusStrip1";
//
// buttonSelectBatlleship
//
this.buttonSelectBatlleship.Location = new System.Drawing.Point(614, 397);
this.buttonSelectBatlleship.Name = "buttonSelectBatlleship";
this.buttonSelectBatlleship.Size = new System.Drawing.Size(75, 23);
this.buttonSelectBatlleship.TabIndex = 8;
this.buttonSelectBatlleship.Text = "Выбрать";
this.buttonSelectBatlleship.UseVisualStyleBackColor = true;
this.buttonSelectBatlleship.Click += new System.EventHandler(this.ButtonSelectBatlleship_Click);
//
// FormBattleship
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonSelectBatlleship);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight);
@ -186,5 +198,6 @@
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabeBodylColor;
private StatusStrip statusStripBattleship;
private Button buttonSelectBatlleship;
}
}

View File

@ -3,6 +3,10 @@ namespace Battleship
public partial class FormBattleship : Form
{
private DrawningBattleship _battleship;
/// <summary>
/// Âűáđŕííűé îáúĺęň
/// </summary>
public DrawningBattleship SelectedBattleship { get; private set; }
public FormBattleship()
{
@ -38,7 +42,13 @@ namespace Battleship
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_battleship = new DrawningBattleship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
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;
}
_battleship = new DrawningBattleship(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
@ -86,12 +96,29 @@ namespace Battleship
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_battleship = new DrawningGunBattleship(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)),
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;
}
_battleship = new DrawningGunBattleship(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
private void ButtonSelectBatlleship_Click(object sender, EventArgs e)
{
SelectedBattleship = _battleship;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -1,205 +0,0 @@
namespace Battleship
{
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.pictureBoxBattleship = new System.Windows.Forms.PictureBox();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabeBodylColor = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStripBattleship = new System.Windows.Forms.StatusStrip();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBattleship)).BeginInit();
this.statusStripBattleship.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxBattleship
//
this.pictureBoxBattleship.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxBattleship.Location = new System.Drawing.Point(0, 0);
this.pictureBoxBattleship.Name = "pictureBoxBattleship";
this.pictureBoxBattleship.Size = new System.Drawing.Size(800, 450);
this.pictureBoxBattleship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxBattleship.TabIndex = 0;
this.pictureBoxBattleship.TabStop = false;
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(12, 397);
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);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Battleship.Properties.Resources.BatteleshipDown;
this.buttonDown.Location = new System.Drawing.Point(731, 390);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 3;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.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::Battleship.Properties.Resources.BattleshipUp;
this.buttonUp.Location = new System.Drawing.Point(732, 361);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 4;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.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::Battleship.Properties.Resources.BattleshipRight;
this.buttonRight.Location = new System.Drawing.Point(758, 390);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5;
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::Battleship.Properties.Resources.BattleshipLeft;
this.buttonLeft.Location = new System.Drawing.Point(706, 390);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 6;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonCreateModif
//
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateModif.Location = new System.Drawing.Point(93, 397);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(110, 23);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17);
this.toolStripStatusLabelSpeed.Text = "Скорость: ";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17);
this.toolStripStatusLabelWeight.Text = "Вес: ";
//
// toolStripStatusLabeBodylColor
//
this.toolStripStatusLabeBodylColor.Name = "toolStripStatusLabeBodylColor";
this.toolStripStatusLabeBodylColor.Size = new System.Drawing.Size(36, 17);
this.toolStripStatusLabeBodylColor.Text = "Цвет:";
//
// statusStripBattleship
//
this.statusStripBattleship.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabeBodylColor});
this.statusStripBattleship.Location = new System.Drawing.Point(0, 428);
this.statusStripBattleship.Name = "statusStripBattleship";
this.statusStripBattleship.Size = new System.Drawing.Size(800, 22);
this.statusStripBattleship.TabIndex = 1;
this.statusStripBattleship.Text = "statusStrip1";
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
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(209, 397);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
this.comboBoxSelectorMap.TabIndex = 8;
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.AutoSize = true;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.comboBoxSelectorMap);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.statusStripBattleship);
this.Controls.Add(this.pictureBoxBattleship);
this.Name = "FormMap";
this.Text = "Военный корабль ";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBattleship)).EndInit();
this.statusStripBattleship.ResumeLayout(false);
this.statusStripBattleship.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxBattleship;
private Button buttonCreate;
private Button buttonDown;
private Button buttonUp;
private Button buttonRight;
private Button buttonLeft;
private Button buttonCreateModif;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabeBodylColor;
private StatusStrip statusStripBattleship;
private ComboBox comboBoxSelectorMap;
}
}

View File

@ -1,104 +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 Battleship
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
/// <summary>
/// Заполнение информации по объекту
/// </summary>
/// <param name="car"></param>
private void SetData(DrawningBattleship battleship)
{
toolStripStatusLabelSpeed.Text = $"Скорость: {battleship.Battleship.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {battleship.Battleship.Weight}";
toolStripStatusLabeBodylColor.Text = $"Цвет: {battleship.Battleship.BodyColor.Name}";
pictureBoxBattleship.Image = _abstractMap.CreateMap(pictureBoxBattleship.Width, pictureBoxBattleship.Height,
new DrawningObjectBattleship(battleship));
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
var car = new DrawningBattleship(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;
}
pictureBoxBattleship.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 car = new DrawningGunBattleship(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)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(car);
}
/// <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 "Водная карта":
_abstractMap = new WaterMap();
break;
}
}
}
}

View File

@ -0,0 +1,217 @@
namespace Battleship
{
partial class FormMapWithSetBattleship
{
/// <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.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveBattleship = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddBattleship = 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.buttonDown);
this.groupBoxTools.Controls.Add(this.buttonLeft);
this.groupBoxTools.Controls.Add(this.buttonUp);
this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.groupBoxTools.Controls.Add(this.buttonRemoveBattleship);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonAddBattleship);
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(632, 0);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(200, 493);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты";
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Battleship.Properties.Resources.BatteleshipDown;
this.buttonDown.Location = new System.Drawing.Point(77, 449);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 9;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.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::Battleship.Properties.Resources.BattleshipLeft;
this.buttonLeft.Location = new System.Drawing.Point(41, 449);
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::Battleship.Properties.Resources.BattleshipUp;
this.buttonUp.Location = new System.Drawing.Point(77, 413);
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);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Battleship.Properties.Resources.BattleshipRight;
this.buttonRight.Location = new System.Drawing.Point(113, 449);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 6;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonShowOnMap.Location = new System.Drawing.Point(6, 367);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(188, 30);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonShowStorage.Location = new System.Drawing.Point(6, 290);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(188, 30);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonRemoveBattleship
//
this.buttonRemoveBattleship.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRemoveBattleship.Location = new System.Drawing.Point(6, 195);
this.buttonRemoveBattleship.Name = "buttonRemoveBattleship";
this.buttonRemoveBattleship.Size = new System.Drawing.Size(188, 29);
this.buttonRemoveBattleship.TabIndex = 3;
this.buttonRemoveBattleship.Text = "Удалить корабль";
this.buttonRemoveBattleship.UseVisualStyleBackColor = true;
this.buttonRemoveBattleship.Click += new System.EventHandler(this.ButtonRemoveBattleship_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 166);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23);
this.maskedTextBoxPosition.TabIndex = 2;
//
// buttonAddBattleship
//
this.buttonAddBattleship.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAddBattleship.Location = new System.Drawing.Point(6, 112);
this.buttonAddBattleship.Name = "buttonAddBattleship";
this.buttonAddBattleship.Size = new System.Drawing.Size(188, 29);
this.buttonAddBattleship.TabIndex = 1;
this.buttonAddBattleship.Text = "Добавить корабль";
this.buttonAddBattleship.UseVisualStyleBackColor = true;
this.buttonAddBattleship.Click += new System.EventHandler(this.ButtonAddBattleship_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Водная карта"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 32);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 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(632, 493);
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
//
// FormMapWithSetBattleship
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(832, 493);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetBattleship";
this.Text = "FormMapWithSetBattleship";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private Button buttonDown;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonShowOnMap;
private Button buttonShowStorage;
private Button buttonRemoveBattleship;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddBattleship;
private ComboBox comboBoxSelectorMap;
private PictureBox pictureBox;
}
}

View File

@ -0,0 +1,168 @@
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;
using static System.Windows.Forms.DataFormats;
namespace Battleship
{
public partial class FormMapWithSetBattleship : Form
{
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetBattleshipGeneric<DrawningObjectBattleship, AbstractMap> _mapBattleshipCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetBattleship()
{
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;
}
switch (comboBoxSelectorMap.Text)
{
case "Водная карта":
map = new WaterMap();
break;
}
if (map != null)
{
_mapBattleshipCollectionGeneric = new MapWithSetBattleshipGeneric<DrawningObjectBattleship, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapBattleshipCollectionGeneric = null;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddBattleship_Click(object sender, EventArgs e)
{
if (_mapBattleshipCollectionGeneric == null)
{
return;
}
FormBattleship form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectBattleship battleship = new(form.SelectedBattleship);
if (_mapBattleshipCollectionGeneric + battleship)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapBattleshipCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveBattleship_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 (_mapBattleshipCollectionGeneric - pos)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapBattleshipCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapBattleshipCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapBattleshipCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapBattleshipCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapBattleshipCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapBattleshipCollectionGeneric == 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 = _mapBattleshipCollectionGeneric.MoveObject(dir);
}
}
}

View File

@ -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="statusStripBattleship.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -17,8 +17,8 @@ namespace Battleship
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 130;
private readonly int _placeSizeHeight = 40;
private readonly int _placeSizeWidth = 150;
private readonly int _placeSizeHeight = 45;
private readonly SetBattleshipGeneric<T> _setBattleship;
private readonly U _map;
@ -32,9 +32,9 @@ namespace Battleship
_map = map;
}
public static bool operator +(MapWithSetBattleshipGeneric<T, U> map, T battleship)
public static bool operator +(MapWithSetBattleshipGeneric<T, U> map, T warship)
{
return map._setBattleship.Insert(battleship);
return map._setBattleship.Insert(warship);
}
public static bool operator -(MapWithSetBattleshipGeneric<T, U> map, int position)
@ -47,7 +47,7 @@ namespace Battleship
Bitmap bmp = new(_pictureWidth, _pictureWidth);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawBattleship(gr, _placeSizeWidth, _placeSizeHeight, _pictureWidth, _pictureHeight);
DrawWarship(gr);
return bmp;
}
@ -98,26 +98,33 @@ namespace Battleship
}
}
}
private void DrawBackground(Graphics gr)
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
Pen pen = new(Color.LightSlateGray, 3);
Brush brush = new SolidBrush(Color.SkyBlue);
g.FillRectangle(brush, 0, 0, _pictureWidth, _pictureHeight);
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);
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight + 2, i * _placeSizeWidth + _placeSizeWidth / 2 + 40, j * _placeSizeHeight + 2);
}
gr.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth + 7, 2, i * _placeSizeWidth + 7, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth + 3, 2, i * _placeSizeWidth + 3, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
private void DrawBattleship(Graphics gr, int x, int y, int width, int height)
private void DrawWarship(Graphics gr)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _setBattleship.Count; i++)
{
_setBattleship.Get(i)?.SetObject(x, y, width, height);
_setBattleship.Get(i)?.DrawningObject(gr);
if (_setBattleship.Get(i) != null)
{
_setBattleship.Get(i).SetObject(i % width * _placeSizeWidth + 15, (height - 1 - i / width) * _placeSizeHeight + 8, _pictureWidth, _pictureHeight);
_setBattleship.Get(i)?.DrawningObject(gr);
}
}
}
}

View File

@ -11,7 +11,7 @@ namespace Battleship
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormMap());
Application.Run(new FormMapWithSetBattleship());
}
}
}

View File

@ -24,37 +24,56 @@ namespace Battleship
public bool Insert(T battleship)
{
_places[0] = battleship;
return true;
return Insert(battleship, 0);
}
public bool Insert(T battleship, 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] = battleship;
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] = battleship;
return true;
}
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];
}
}