Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
944a015cbc | |||
55a92737a2 | |||
1e245ddeea | |||
6ca9449eb0 | |||
332cf2b91e | |||
44408586b5 | |||
1bf55f260e | |||
187957395e | |||
f8520664cc | |||
26b48afac4 | |||
7fb61aaaf1 | |||
c9d1b9f133 | |||
296f2fdacd | |||
ab43211760 | |||
9b08e32244 | |||
6789fca1cb | |||
96d2bfbb8f | |||
cd528db9c6 |
152
Warship/Warship/AbstractMap.cs
Normal file
152
Warship/Warship/AbstractMap.cs
Normal file
@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
{
|
||||
private IDrawingObject _drawingObject = null;
|
||||
protected int[,] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected readonly Random _random = new();
|
||||
protected readonly int _freeWaterArea = 0;
|
||||
protected readonly int _land = 1;
|
||||
|
||||
public Bitmap CreateMap(int width,int height,IDrawingObject drawingObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawingObject = drawingObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
(float Left, float Right, float Top, float Bottom) = _drawingObject.GetCurrentPosition();
|
||||
|
||||
if (CheckLand(Left, Right, Top, Bottom) != 0)
|
||||
{
|
||||
_drawingObject.MoveObject(SetOppositDirection(direction));
|
||||
}
|
||||
|
||||
if (true)
|
||||
{
|
||||
_drawingObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawingObject==null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.Next(0, 10);
|
||||
int y = _random.Next(0, 10);
|
||||
_drawingObject.SetObject(x, y, _width, _height);
|
||||
|
||||
(float Left, float Right, float Top, float Bottom) = _drawingObject.GetCurrentPosition();
|
||||
|
||||
while (CheckLand(Left, Right, Top, Bottom) != 2)
|
||||
{
|
||||
int res;
|
||||
do
|
||||
{
|
||||
res = CheckLand(Left, Right, Top, Bottom);
|
||||
if (res == 0)
|
||||
{
|
||||
_drawingObject.SetObject((int)Left, (int)Right, _width, _height);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Left += _size_x;
|
||||
}
|
||||
} while (res != 2);
|
||||
Left = x;
|
||||
Right += _size_y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Bitmap DrawMapWithObject()
|
||||
{
|
||||
Bitmap bmp = new(_width, _height);
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i,j] == _freeWaterArea)
|
||||
{
|
||||
DrawWaterPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i, j] == _land)
|
||||
{
|
||||
DrawLandPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawingObject.DrawingObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
private int CheckLand(float Left, float Right, float Top, float Bottom)
|
||||
{
|
||||
int RUi = (int)(Left / _size_x);
|
||||
int RUj = (int)(Right / _size_y);
|
||||
int LDi = (int)(Top / _size_x);
|
||||
int LDj = (int)(Bottom / _size_y);
|
||||
|
||||
if (RUi < 0 || RUj < 0 || LDi >= _map.GetLength(1) || LDj >= _map.GetLength(0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int x = RUi; x <= LDi; x++)
|
||||
{
|
||||
for (int y = RUj; y <= LDj; y++)
|
||||
{
|
||||
if (_map[x, y] == _land)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private Direction SetOppositDirection(Direction dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case Direction.Up:
|
||||
return Direction.Down;
|
||||
case Direction.Down:
|
||||
return Direction.Up;
|
||||
case Direction.Left:
|
||||
return Direction.Right;
|
||||
case Direction.Right:
|
||||
return Direction.Left;
|
||||
}
|
||||
return Direction.None;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawWaterPart(Graphics gr, int i, int j);
|
||||
protected abstract void DrawLandPart(Graphics gr, int i, int j);
|
||||
}
|
||||
}
|
@ -6,11 +6,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None=0,
|
||||
Up=1,
|
||||
Down=2,
|
||||
Left=3,
|
||||
Right=4
|
||||
Right=4,
|
||||
}
|
||||
}
|
||||
|
76
Warship/Warship/DrawingAdvancedWarship.cs
Normal file
76
Warship/Warship/DrawingAdvancedWarship.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal class DrawingAdvancedWarship : DrawingWarship
|
||||
{
|
||||
public DrawingAdvancedWarship(int speed,float weight, Color bodyColor, Color dopColor, bool Helipad, bool Antenna, bool Missile) : base(speed, weight, bodyColor, 120, 50)
|
||||
{
|
||||
Warship = new EntityAdvancedWarship(speed, weight, bodyColor, dopColor, Helipad, Antenna, Missile);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Warship is not EntityAdvancedWarship advancedWarship)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(advancedWarship.DopColor);
|
||||
|
||||
if (advancedWarship.Missile)
|
||||
{
|
||||
g.FillPolygon(dopBrush, new Point[]
|
||||
{
|
||||
new Point(_startPosX+25,_startPosY+5-5),new Point(_startPosX+65,_startPosY+5-5),
|
||||
new Point(_startPosX+75,_startPosY+10-5),new Point(_startPosX+25,_startPosY+10-5),
|
||||
new Point(_startPosX+25,_startPosY+5-5)
|
||||
}
|
||||
);
|
||||
g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 5 - 5), new Point(_startPosX + 65, _startPosY + 5 - 5));
|
||||
g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 5 - 5), new Point(_startPosX + 75, _startPosY + 10 - 5));
|
||||
g.DrawLine(pen, new Point(_startPosX + 75, _startPosY + 10 - 5), new Point(_startPosX + 25, _startPosY + 10 - 5));
|
||||
g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 10 - 5), new Point(_startPosX + 25, _startPosY + 5 - 5));
|
||||
|
||||
g.FillPolygon(dopBrush, new Point[]
|
||||
{
|
||||
new Point(_startPosX+25,_startPosY+50-5),new Point(_startPosX+75,_startPosY+50-5),
|
||||
new Point(_startPosX+65,_startPosY+55-5),new Point(_startPosX+25,_startPosY+55-5),
|
||||
new Point(_startPosX+25,_startPosY+50-5)
|
||||
}
|
||||
);
|
||||
g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 50 - 5), new Point(_startPosX + 75, _startPosY + 50 - 5));
|
||||
g.DrawLine(pen, new Point(_startPosX + 75, _startPosY + 50 - 5), new Point(_startPosX + 65, _startPosY + 55 - 5));
|
||||
g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 55 - 5), new Point(_startPosX + 25, _startPosY + 55 - 5));
|
||||
g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 55 - 5), new Point(_startPosX + 25, _startPosY + 50 - 5));
|
||||
}
|
||||
_startPosY += 5;
|
||||
base.DrawTransport(g);
|
||||
_startPosY -= 5;
|
||||
|
||||
if (advancedWarship.Helipad)
|
||||
{
|
||||
g.FillEllipse(dopBrush, _startPosX + 85, _startPosY + 20-5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 85, _startPosY + 20-5, 20, 20);
|
||||
g.DrawLine(pen, _startPosX + 90, _startPosY + 25 - 5, _startPosX + 90, _startPosY + 35 - 5);
|
||||
g.DrawLine(pen, _startPosX + 90+10, _startPosY + 25 - 5, _startPosX + 90+10, _startPosY + 35 - 5);
|
||||
g.DrawLine(pen, _startPosX + 90, _startPosY + 30 - 5, _startPosX + 100, _startPosY + 30 - 5);
|
||||
}
|
||||
if (advancedWarship.Antenna)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX + 15, _startPosY + 20 - 5, _startPosX + 15, _startPosY + 40 - 5);
|
||||
g.DrawLine(pen, _startPosX +10, _startPosY + 30 - 5, _startPosX + 20, _startPosY + 30 - 5);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetModifColor(Color modifColor)
|
||||
{
|
||||
((EntityAdvancedWarship)Warship).DopColor = modifColor;
|
||||
}
|
||||
}
|
||||
}
|
39
Warship/Warship/DrawingObjectWarship.cs
Normal file
39
Warship/Warship/DrawingObjectWarship.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal class DrawingObjectWarship : IDrawingObject
|
||||
{
|
||||
private DrawingWarship _warship=null;
|
||||
|
||||
public DrawingObjectWarship(DrawingWarship warship)
|
||||
{
|
||||
_warship= warship;
|
||||
}
|
||||
public float Step => _warship?.Warship?.Step ?? 0;
|
||||
|
||||
void IDrawingObject.DrawingObject(Graphics g)
|
||||
{
|
||||
_warship.DrawTransport(g);
|
||||
}
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _warship?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_warship?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_warship.SetPosition(x,y,width,height);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,22 +6,33 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal class DrawingWarship
|
||||
public class DrawingWarship
|
||||
{
|
||||
public EntityWarship Warship { get; private set; }
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
public EntityWarship Warship { get; protected set; }
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
private int? _pictureWidth = null;
|
||||
private int? _pictureHeight = null;
|
||||
private readonly int _warshipWidth = 120;
|
||||
private readonly int _warshipHeight = 40;
|
||||
|
||||
public void Init(int speed, float weight,Color bodyColor)
|
||||
public DrawingWarship(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Warship = new EntityWarship();
|
||||
Warship.Init(speed, weight, bodyColor);
|
||||
Warship=new EntityWarship(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
protected DrawingWarship(int speed, float weight,Color bodyColor, int warshipWidth, int warshipHeight) : this(speed,weight,bodyColor)
|
||||
{
|
||||
_warshipWidth = warshipWidth;
|
||||
_warshipHeight = warshipHeight;
|
||||
}
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
Warship.BodyColor = color;
|
||||
}
|
||||
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x >= 0 && x+_warshipWidth <= width && y >= 0 && y+_warshipHeight <= height)
|
||||
@ -72,7 +83,7 @@ namespace Warship
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
@ -134,5 +145,9 @@ namespace Warship
|
||||
_startPosY = _pictureHeight.Value - _warshipHeight;
|
||||
}
|
||||
}
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _warshipWidth, _startPosY + _warshipHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
Warship/Warship/EntityAdvancedWarship.cs
Normal file
23
Warship/Warship/EntityAdvancedWarship.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal class EntityAdvancedWarship : EntityWarship
|
||||
{
|
||||
public Color DopColor { get; set; }
|
||||
public bool Helipad { get;private set; }
|
||||
public bool Antenna { get; private set; }
|
||||
public bool Missile { get; private set; }
|
||||
public EntityAdvancedWarship(int speed, float weight, Color bodyColor, Color dopColor, bool helipad, bool antenna, bool missile) : base(speed,weight,bodyColor) {
|
||||
DopColor = dopColor;
|
||||
Helipad = helipad;
|
||||
Antenna = antenna;
|
||||
Missile = missile;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -6,14 +6,14 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal class EntityWarship
|
||||
public class EntityWarship
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public float Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public Color BodyColor { get; set; }
|
||||
public int Step => (int)(Speed * 2000 / Weight);
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityWarship(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(10, 60) : speed;
|
||||
|
280
Warship/Warship/FormMapWithSetWarships.Designer.cs
generated
Normal file
280
Warship/Warship/FormMapWithSetWarships.Designer.cs
generated
Normal file
@ -0,0 +1,280 @@
|
||||
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.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
this.ButtonAddMap = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRemoveWarship = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonDown = 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.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonAddWarship = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.textBoxMap = new System.Windows.Forms.TextBox();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
this.groupBoxMaps.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRemoveWarship);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddWarship);
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(859, 0);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(204, 652);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// groupBoxMaps
|
||||
//
|
||||
this.groupBoxMaps.Controls.Add(this.textBoxMap);
|
||||
this.groupBoxMaps.Controls.Add(this.ButtonDeleteMap);
|
||||
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
||||
this.groupBoxMaps.Controls.Add(this.ButtonAddMap);
|
||||
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxMaps.Location = new System.Drawing.Point(10, 22);
|
||||
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||
this.groupBoxMaps.Size = new System.Drawing.Size(188, 266);
|
||||
this.groupBoxMaps.TabIndex = 11;
|
||||
this.groupBoxMaps.TabStop = false;
|
||||
this.groupBoxMaps.Text = "Карты";
|
||||
//
|
||||
// ButtonDeleteMap
|
||||
//
|
||||
this.ButtonDeleteMap.Location = new System.Drawing.Point(12, 223);
|
||||
this.ButtonDeleteMap.Name = "ButtonDeleteMap";
|
||||
this.ButtonDeleteMap.Size = new System.Drawing.Size(168, 33);
|
||||
this.ButtonDeleteMap.TabIndex = 4;
|
||||
this.ButtonDeleteMap.Text = "Удалить карту";
|
||||
this.ButtonDeleteMap.UseVisualStyleBackColor = true;
|
||||
this.ButtonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.ItemHeight = 15;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(10, 118);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(170, 94);
|
||||
this.listBoxMaps.TabIndex = 3;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// ButtonAddMap
|
||||
//
|
||||
this.ButtonAddMap.Location = new System.Drawing.Point(8, 79);
|
||||
this.ButtonAddMap.Name = "ButtonAddMap";
|
||||
this.ButtonAddMap.Size = new System.Drawing.Size(174, 35);
|
||||
this.ButtonAddMap.TabIndex = 2;
|
||||
this.ButtonAddMap.Text = "Добавить карту";
|
||||
this.ButtonAddMap.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddMap.Click += new System.EventHandler(this.ButtonAddMap_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(7, 50);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(15, 358);
|
||||
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(15, 387);
|
||||
this.buttonRemoveWarship.Name = "buttonRemoveWarship";
|
||||
this.buttonRemoveWarship.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonRemoveWarship.TabIndex = 3;
|
||||
this.buttonRemoveWarship.Text = "Удалить корабль";
|
||||
this.buttonRemoveWarship.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveWarship.Click += new System.EventHandler(this.ButtonRemoveWarship_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(15, 452);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
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;
|
||||
this.buttonDown.Location = new System.Drawing.Point(91, 602);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 10;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.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::Warship.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(127, 602);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 9;
|
||||
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::Warship.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(55, 602);
|
||||
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::Warship.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(91, 566);
|
||||
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);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(15, 493);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// buttonAddWarship
|
||||
//
|
||||
this.buttonAddWarship.Location = new System.Drawing.Point(15, 317);
|
||||
this.buttonAddWarship.Name = "buttonAddWarship";
|
||||
this.buttonAddWarship.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonAddWarship.TabIndex = 1;
|
||||
this.buttonAddWarship.Text = "Добавить корабль";
|
||||
this.buttonAddWarship.UseVisualStyleBackColor = true;
|
||||
this.buttonAddWarship.Click += new System.EventHandler(this.ButtonAddWarship_Click);
|
||||
//
|
||||
// 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(859, 652);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// textBoxMap
|
||||
//
|
||||
this.textBoxMap.Location = new System.Drawing.Point(5, 21);
|
||||
this.textBoxMap.Name = "textBoxMap";
|
||||
this.textBoxMap.Size = new System.Drawing.Size(175, 23);
|
||||
this.textBoxMap.TabIndex = 12;
|
||||
//
|
||||
// FormMapWithSetWarships
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1063, 652);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Name = "FormMapWithSetWarships";
|
||||
this.Text = "Карта с набором объектов";
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
this.groupBoxTools.PerformLayout();
|
||||
this.groupBoxMaps.ResumeLayout(false);
|
||||
this.groupBoxMaps.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private PictureBox pictureBox;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private Button buttonShowOnMap;
|
||||
private Button buttonAddWarship;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonRemoveWarship;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private GroupBox groupBoxMaps;
|
||||
private Button ButtonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private Button ButtonAddMap;
|
||||
private TextBox textBoxMap;
|
||||
}
|
||||
}
|
182
Warship/Warship/FormMapWithSetWarships.cs
Normal file
182
Warship/Warship/FormMapWithSetWarships.cs
Normal file
@ -0,0 +1,182 @@
|
||||
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 readonly Dictionary<string, AbstractMap> _mapDict = new()
|
||||
{
|
||||
{"Первая карта",new SimpleMap() },
|
||||
{"Вторая карта",new SecondMap() }
|
||||
};
|
||||
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
|
||||
public FormMapWithSetWarships()
|
||||
{
|
||||
InitializeComponent();
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
foreach(var elem in _mapDict)
|
||||
{
|
||||
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReloadMaps()
|
||||
{
|
||||
int index = listBoxMaps.SelectedIndex;
|
||||
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||
{
|
||||
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||
}
|
||||
if (listBoxMaps.Items.Count>0&& (index == -1 || index >= listBoxMaps.Items.Count))
|
||||
{
|
||||
listBoxMaps.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxMaps.Items.Count>0&&index>-1 && index < listBoxMaps.Items.Count)
|
||||
{
|
||||
listBoxMaps.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAddWarship_Click(object sender, EventArgs e)
|
||||
{
|
||||
var formWarshipConfig = new FormWarshipConfig();
|
||||
formWarshipConfig.AddEvent(AddWarshipOnMap);
|
||||
formWarshipConfig.Show();
|
||||
}
|
||||
private void AddWarshipOnMap(DrawingWarship drawingWarship)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawingObjectWarship warship = new(drawingWarship);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + warship != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemoveWarship_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos !=null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
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 = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
|
||||
private void ButtonAddMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxMap.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (!_mapDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||
{
|
||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
listBoxMaps.Items.Clear();
|
||||
_mapsCollection.AddMap(textBoxMap.Text, _mapDict[comboBoxSelectorMap.Text]);
|
||||
ReloadMaps();
|
||||
}
|
||||
|
||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void ButtonDeleteMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
listBoxMaps.Items.Clear();
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
Warship/Warship/FormMapWithSetWarships.resx
Normal file
60
Warship/Warship/FormMapWithSetWarships.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<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:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
38
Warship/Warship/FormWarship.Designer.cs
generated
38
Warship/Warship/FormWarship.Designer.cs
generated
@ -38,6 +38,8 @@
|
||||
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.buttonSelect = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -51,7 +53,7 @@
|
||||
this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxWarship.TabIndex = 0;
|
||||
this.pictureBoxWarship.TabStop = false;
|
||||
this.pictureBoxWarship.Resize += new System.EventHandler(this.pictureBoxWarship_Resize);
|
||||
this.pictureBoxWarship.Resize += new System.EventHandler(this.PictureBoxWarship_Resize);
|
||||
//
|
||||
// statusStrip
|
||||
//
|
||||
@ -91,7 +93,7 @@
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
@ -104,7 +106,7 @@
|
||||
this.buttonDown.TabIndex = 3;
|
||||
this.buttonDown.Text = " ";
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
@ -117,7 +119,7 @@
|
||||
this.buttonUp.TabIndex = 4;
|
||||
this.buttonUp.Text = " ";
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
@ -130,7 +132,7 @@
|
||||
this.buttonRight.TabIndex = 5;
|
||||
this.buttonRight.Text = " ";
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
@ -143,13 +145,35 @@
|
||||
this.buttonLeft.TabIndex = 6;
|
||||
this.buttonLeft.Text = " ";
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(93, 393);
|
||||
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);
|
||||
//
|
||||
// buttonSelect
|
||||
//
|
||||
this.buttonSelect.Location = new System.Drawing.Point(551, 390);
|
||||
this.buttonSelect.Name = "buttonSelect";
|
||||
this.buttonSelect.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonSelect.TabIndex = 8;
|
||||
this.buttonSelect.Text = "Выбрать";
|
||||
this.buttonSelect.UseVisualStyleBackColor = true;
|
||||
this.buttonSelect.Click += new System.EventHandler(this.ButtonSelect_Click);
|
||||
//
|
||||
// FormWarship
|
||||
//
|
||||
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.buttonSelect);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
@ -179,5 +203,7 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonCreateModif;
|
||||
private Button buttonSelect;
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ namespace Warship
|
||||
public partial class FormWarship : Form
|
||||
{
|
||||
private DrawingWarship _warship;
|
||||
|
||||
public DrawingWarship SelectedWarship { get; private set; }
|
||||
public FormWarship()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -15,18 +17,29 @@ namespace Warship
|
||||
pictureBoxWarship.Image = bmp;
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_warship = new DrawingWarship();
|
||||
_warship.Init(rnd.Next(10, 60), rnd.Next(20000, 25000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Cêîðîñòü: {_warship.Warship.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_warship.Warship.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_warship.Warship.BodyColor.Name}";
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
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;
|
||||
}
|
||||
_warship = new DrawingWarship(rnd.Next(10, 60), rnd.Next(20000, 25000),color);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
@ -47,10 +60,36 @@ namespace Warship
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void pictureBoxWarship_Resize(object sender, EventArgs e)
|
||||
private void PictureBoxWarship_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_warship?.ChangeBorders(pictureBoxWarship.Width, pictureBoxWarship.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
Color color1 = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog1 = new();
|
||||
if (dialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color1 = dialog1.Color;
|
||||
}
|
||||
Color color2 = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog2 = new();
|
||||
if (dialog2.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color2 = dialog2.Color;
|
||||
}
|
||||
_warship = new DrawingAdvancedWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), color1,color2, Convert.ToBoolean(rnd.Next(0,2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonSelect_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedWarship = _warship;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
374
Warship/Warship/FormWarshipConfig.Designer.cs
generated
Normal file
374
Warship/Warship/FormWarshipConfig.Designer.cs
generated
Normal file
@ -0,0 +1,374 @@
|
||||
namespace Warship
|
||||
{
|
||||
partial class FormWarshipConfig
|
||||
{
|
||||
/// <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.GroupBoxConfig = new System.Windows.Forms.GroupBox();
|
||||
this.LabelAdvancedWarship = new System.Windows.Forms.Label();
|
||||
this.LabelBasicWarship = new System.Windows.Forms.Label();
|
||||
this.GroupBoxColors = new System.Windows.Forms.GroupBox();
|
||||
this.PanelSilver = new System.Windows.Forms.Panel();
|
||||
this.PanelRed = new System.Windows.Forms.Panel();
|
||||
this.PanelBlue = new System.Windows.Forms.Panel();
|
||||
this.PanelCyan = new System.Windows.Forms.Panel();
|
||||
this.PanelLime = new System.Windows.Forms.Panel();
|
||||
this.PanelFuchsia = new System.Windows.Forms.Panel();
|
||||
this.PanelYellow = new System.Windows.Forms.Panel();
|
||||
this.PanelOrange = new System.Windows.Forms.Panel();
|
||||
this.CheckBoxMissile = new System.Windows.Forms.CheckBox();
|
||||
this.CheckBoxAntenna = new System.Windows.Forms.CheckBox();
|
||||
this.CheckBoxHelipad = new System.Windows.Forms.CheckBox();
|
||||
this.NumericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.NumericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.LabelWeight = new System.Windows.Forms.Label();
|
||||
this.LabelSpeed = new System.Windows.Forms.Label();
|
||||
this.PictureBoxWarship = new System.Windows.Forms.PictureBox();
|
||||
this.PanelWarship = new System.Windows.Forms.Panel();
|
||||
this.LabelModifColor = new System.Windows.Forms.Label();
|
||||
this.LabelBodyColor = new System.Windows.Forms.Label();
|
||||
this.ButtomAdd = new System.Windows.Forms.Button();
|
||||
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||
this.GroupBoxConfig.SuspendLayout();
|
||||
this.GroupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.NumericUpDownWeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.NumericUpDownSpeed)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.PictureBoxWarship)).BeginInit();
|
||||
this.PanelWarship.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// GroupBoxConfig
|
||||
//
|
||||
this.GroupBoxConfig.Controls.Add(this.LabelAdvancedWarship);
|
||||
this.GroupBoxConfig.Controls.Add(this.LabelBasicWarship);
|
||||
this.GroupBoxConfig.Controls.Add(this.GroupBoxColors);
|
||||
this.GroupBoxConfig.Controls.Add(this.CheckBoxMissile);
|
||||
this.GroupBoxConfig.Controls.Add(this.CheckBoxAntenna);
|
||||
this.GroupBoxConfig.Controls.Add(this.CheckBoxHelipad);
|
||||
this.GroupBoxConfig.Controls.Add(this.NumericUpDownWeight);
|
||||
this.GroupBoxConfig.Controls.Add(this.NumericUpDownSpeed);
|
||||
this.GroupBoxConfig.Controls.Add(this.LabelWeight);
|
||||
this.GroupBoxConfig.Controls.Add(this.LabelSpeed);
|
||||
this.GroupBoxConfig.Location = new System.Drawing.Point(12, 12);
|
||||
this.GroupBoxConfig.Name = "GroupBoxConfig";
|
||||
this.GroupBoxConfig.Size = new System.Drawing.Size(596, 241);
|
||||
this.GroupBoxConfig.TabIndex = 0;
|
||||
this.GroupBoxConfig.TabStop = false;
|
||||
this.GroupBoxConfig.Text = "Параметры: ";
|
||||
//
|
||||
// LabelAdvancedWarship
|
||||
//
|
||||
this.LabelAdvancedWarship.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.LabelAdvancedWarship.Location = new System.Drawing.Point(452, 183);
|
||||
this.LabelAdvancedWarship.Name = "LabelAdvancedWarship";
|
||||
this.LabelAdvancedWarship.Size = new System.Drawing.Size(123, 41);
|
||||
this.LabelAdvancedWarship.TabIndex = 9;
|
||||
this.LabelAdvancedWarship.Text = "Продвинутый корабль";
|
||||
this.LabelAdvancedWarship.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.LabelAdvancedWarship.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelWarship_MouseDown);
|
||||
//
|
||||
// LabelBasicWarship
|
||||
//
|
||||
this.LabelBasicWarship.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.LabelBasicWarship.Location = new System.Drawing.Point(321, 183);
|
||||
this.LabelBasicWarship.Name = "LabelBasicWarship";
|
||||
this.LabelBasicWarship.Size = new System.Drawing.Size(125, 41);
|
||||
this.LabelBasicWarship.TabIndex = 8;
|
||||
this.LabelBasicWarship.Text = "Обычный корабль";
|
||||
this.LabelBasicWarship.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.LabelBasicWarship.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelWarship_MouseDown);
|
||||
//
|
||||
// GroupBoxColors
|
||||
//
|
||||
this.GroupBoxColors.Controls.Add(this.PanelSilver);
|
||||
this.GroupBoxColors.Controls.Add(this.PanelRed);
|
||||
this.GroupBoxColors.Controls.Add(this.PanelBlue);
|
||||
this.GroupBoxColors.Controls.Add(this.PanelCyan);
|
||||
this.GroupBoxColors.Controls.Add(this.PanelLime);
|
||||
this.GroupBoxColors.Controls.Add(this.PanelFuchsia);
|
||||
this.GroupBoxColors.Controls.Add(this.PanelYellow);
|
||||
this.GroupBoxColors.Controls.Add(this.PanelOrange);
|
||||
this.GroupBoxColors.Location = new System.Drawing.Point(321, 24);
|
||||
this.GroupBoxColors.Name = "GroupBoxColors";
|
||||
this.GroupBoxColors.Size = new System.Drawing.Size(254, 144);
|
||||
this.GroupBoxColors.TabIndex = 7;
|
||||
this.GroupBoxColors.TabStop = false;
|
||||
this.GroupBoxColors.Text = "Цвета: ";
|
||||
//
|
||||
// PanelSilver
|
||||
//
|
||||
this.PanelSilver.BackColor = System.Drawing.Color.Silver;
|
||||
this.PanelSilver.Location = new System.Drawing.Point(191, 78);
|
||||
this.PanelSilver.Name = "PanelSilver";
|
||||
this.PanelSilver.Size = new System.Drawing.Size(44, 45);
|
||||
this.PanelSilver.TabIndex = 1;
|
||||
//
|
||||
// PanelRed
|
||||
//
|
||||
this.PanelRed.BackColor = System.Drawing.Color.Red;
|
||||
this.PanelRed.Location = new System.Drawing.Point(136, 78);
|
||||
this.PanelRed.Name = "PanelRed";
|
||||
this.PanelRed.Size = new System.Drawing.Size(46, 45);
|
||||
this.PanelRed.TabIndex = 1;
|
||||
//
|
||||
// PanelBlue
|
||||
//
|
||||
this.PanelBlue.BackColor = System.Drawing.Color.Blue;
|
||||
this.PanelBlue.Location = new System.Drawing.Point(79, 78);
|
||||
this.PanelBlue.Name = "PanelBlue";
|
||||
this.PanelBlue.Size = new System.Drawing.Size(46, 45);
|
||||
this.PanelBlue.TabIndex = 1;
|
||||
//
|
||||
// PanelCyan
|
||||
//
|
||||
this.PanelCyan.BackColor = System.Drawing.Color.Cyan;
|
||||
this.PanelCyan.Location = new System.Drawing.Point(20, 78);
|
||||
this.PanelCyan.Name = "PanelCyan";
|
||||
this.PanelCyan.Size = new System.Drawing.Size(48, 45);
|
||||
this.PanelCyan.TabIndex = 1;
|
||||
//
|
||||
// PanelLime
|
||||
//
|
||||
this.PanelLime.BackColor = System.Drawing.Color.Lime;
|
||||
this.PanelLime.Location = new System.Drawing.Point(191, 24);
|
||||
this.PanelLime.Name = "PanelLime";
|
||||
this.PanelLime.Size = new System.Drawing.Size(44, 45);
|
||||
this.PanelLime.TabIndex = 1;
|
||||
//
|
||||
// PanelFuchsia
|
||||
//
|
||||
this.PanelFuchsia.BackColor = System.Drawing.Color.Fuchsia;
|
||||
this.PanelFuchsia.Location = new System.Drawing.Point(136, 24);
|
||||
this.PanelFuchsia.Name = "PanelFuchsia";
|
||||
this.PanelFuchsia.Size = new System.Drawing.Size(46, 45);
|
||||
this.PanelFuchsia.TabIndex = 1;
|
||||
//
|
||||
// PanelYellow
|
||||
//
|
||||
this.PanelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||
this.PanelYellow.Location = new System.Drawing.Point(79, 24);
|
||||
this.PanelYellow.Name = "PanelYellow";
|
||||
this.PanelYellow.Size = new System.Drawing.Size(46, 45);
|
||||
this.PanelYellow.TabIndex = 1;
|
||||
//
|
||||
// PanelOrange
|
||||
//
|
||||
this.PanelOrange.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
|
||||
this.PanelOrange.Location = new System.Drawing.Point(20, 24);
|
||||
this.PanelOrange.Name = "PanelOrange";
|
||||
this.PanelOrange.Size = new System.Drawing.Size(48, 45);
|
||||
this.PanelOrange.TabIndex = 0;
|
||||
//
|
||||
// CheckBoxMissile
|
||||
//
|
||||
this.CheckBoxMissile.AutoSize = true;
|
||||
this.CheckBoxMissile.Location = new System.Drawing.Point(42, 205);
|
||||
this.CheckBoxMissile.Name = "CheckBoxMissile";
|
||||
this.CheckBoxMissile.Size = new System.Drawing.Size(200, 19);
|
||||
this.CheckBoxMissile.TabIndex = 6;
|
||||
this.CheckBoxMissile.Text = "Признак наличия боевых ракет";
|
||||
this.CheckBoxMissile.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// CheckBoxAntenna
|
||||
//
|
||||
this.CheckBoxAntenna.AutoSize = true;
|
||||
this.CheckBoxAntenna.Location = new System.Drawing.Point(42, 168);
|
||||
this.CheckBoxAntenna.Name = "CheckBoxAntenna";
|
||||
this.CheckBoxAntenna.Size = new System.Drawing.Size(173, 19);
|
||||
this.CheckBoxAntenna.TabIndex = 5;
|
||||
this.CheckBoxAntenna.Text = "Признак наличия антенны";
|
||||
this.CheckBoxAntenna.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// CheckBoxHelipad
|
||||
//
|
||||
this.CheckBoxHelipad.AutoSize = true;
|
||||
this.CheckBoxHelipad.Location = new System.Drawing.Point(42, 129);
|
||||
this.CheckBoxHelipad.Name = "CheckBoxHelipad";
|
||||
this.CheckBoxHelipad.Size = new System.Drawing.Size(256, 19);
|
||||
this.CheckBoxHelipad.TabIndex = 4;
|
||||
this.CheckBoxHelipad.Text = "Признак наличия вертолетной площадки";
|
||||
this.CheckBoxHelipad.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// NumericUpDownWeight
|
||||
//
|
||||
this.NumericUpDownWeight.Location = new System.Drawing.Point(113, 78);
|
||||
this.NumericUpDownWeight.Name = "NumericUpDownWeight";
|
||||
this.NumericUpDownWeight.Size = new System.Drawing.Size(120, 23);
|
||||
this.NumericUpDownWeight.TabIndex = 3;
|
||||
this.NumericUpDownWeight.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// NumericUpDownSpeed
|
||||
//
|
||||
this.NumericUpDownSpeed.Location = new System.Drawing.Point(113, 41);
|
||||
this.NumericUpDownSpeed.Name = "NumericUpDownSpeed";
|
||||
this.NumericUpDownSpeed.Size = new System.Drawing.Size(120, 23);
|
||||
this.NumericUpDownSpeed.TabIndex = 2;
|
||||
this.NumericUpDownSpeed.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// LabelWeight
|
||||
//
|
||||
this.LabelWeight.AutoSize = true;
|
||||
this.LabelWeight.Location = new System.Drawing.Point(42, 80);
|
||||
this.LabelWeight.Name = "LabelWeight";
|
||||
this.LabelWeight.Size = new System.Drawing.Size(32, 15);
|
||||
this.LabelWeight.TabIndex = 1;
|
||||
this.LabelWeight.Text = "Вес: ";
|
||||
//
|
||||
// LabelSpeed
|
||||
//
|
||||
this.LabelSpeed.AutoSize = true;
|
||||
this.LabelSpeed.Location = new System.Drawing.Point(42, 43);
|
||||
this.LabelSpeed.Name = "LabelSpeed";
|
||||
this.LabelSpeed.Size = new System.Drawing.Size(65, 15);
|
||||
this.LabelSpeed.TabIndex = 0;
|
||||
this.LabelSpeed.Text = "Скорость: ";
|
||||
//
|
||||
// PictureBoxWarship
|
||||
//
|
||||
this.PictureBoxWarship.Location = new System.Drawing.Point(29, 53);
|
||||
this.PictureBoxWarship.Name = "PictureBoxWarship";
|
||||
this.PictureBoxWarship.Size = new System.Drawing.Size(240, 136);
|
||||
this.PictureBoxWarship.TabIndex = 1;
|
||||
this.PictureBoxWarship.TabStop = false;
|
||||
//
|
||||
// PanelWarship
|
||||
//
|
||||
this.PanelWarship.AllowDrop = true;
|
||||
this.PanelWarship.Controls.Add(this.LabelModifColor);
|
||||
this.PanelWarship.Controls.Add(this.LabelBodyColor);
|
||||
this.PanelWarship.Controls.Add(this.PictureBoxWarship);
|
||||
this.PanelWarship.Location = new System.Drawing.Point(621, 20);
|
||||
this.PanelWarship.Name = "PanelWarship";
|
||||
this.PanelWarship.Size = new System.Drawing.Size(298, 197);
|
||||
this.PanelWarship.TabIndex = 2;
|
||||
this.PanelWarship.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelWarship_DragDrop);
|
||||
this.PanelWarship.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelWarship_DragEnter);
|
||||
//
|
||||
// LabelModifColor
|
||||
//
|
||||
this.LabelModifColor.AllowDrop = true;
|
||||
this.LabelModifColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.LabelModifColor.Location = new System.Drawing.Point(153, 8);
|
||||
this.LabelModifColor.Name = "LabelModifColor";
|
||||
this.LabelModifColor.Size = new System.Drawing.Size(116, 38);
|
||||
this.LabelModifColor.TabIndex = 3;
|
||||
this.LabelModifColor.Text = "Цвет модификаций корабля";
|
||||
this.LabelModifColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.LabelModifColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelModifColor_DragDrop);
|
||||
this.LabelModifColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelModifColor_DragEnter);
|
||||
//
|
||||
// LabelBodyColor
|
||||
//
|
||||
this.LabelBodyColor.AllowDrop = true;
|
||||
this.LabelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.LabelBodyColor.Location = new System.Drawing.Point(29, 8);
|
||||
this.LabelBodyColor.Name = "LabelBodyColor";
|
||||
this.LabelBodyColor.Size = new System.Drawing.Size(118, 38);
|
||||
this.LabelBodyColor.TabIndex = 2;
|
||||
this.LabelBodyColor.Text = "Цвет корпуса корабля";
|
||||
this.LabelBodyColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.LabelBodyColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBodyColor_DragDrop);
|
||||
this.LabelBodyColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBodyColor_DragEnter);
|
||||
//
|
||||
// ButtomAdd
|
||||
//
|
||||
this.ButtomAdd.Location = new System.Drawing.Point(685, 227);
|
||||
this.ButtomAdd.Name = "ButtomAdd";
|
||||
this.ButtomAdd.Size = new System.Drawing.Size(83, 27);
|
||||
this.ButtomAdd.TabIndex = 3;
|
||||
this.ButtomAdd.Text = "Добавить";
|
||||
this.ButtomAdd.UseVisualStyleBackColor = true;
|
||||
this.ButtomAdd.Click += new System.EventHandler(this.ButtomAdd_Click);
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
this.ButtonCancel.Location = new System.Drawing.Point(783, 227);
|
||||
this.ButtonCancel.Name = "ButtonCancel";
|
||||
this.ButtonCancel.Size = new System.Drawing.Size(79, 27);
|
||||
this.ButtonCancel.TabIndex = 4;
|
||||
this.ButtonCancel.Text = "Отмена";
|
||||
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormWarshipConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(935, 266);
|
||||
this.Controls.Add(this.ButtonCancel);
|
||||
this.Controls.Add(this.ButtomAdd);
|
||||
this.Controls.Add(this.PanelWarship);
|
||||
this.Controls.Add(this.GroupBoxConfig);
|
||||
this.Name = "FormWarshipConfig";
|
||||
this.Text = "Создание корабля";
|
||||
this.GroupBoxConfig.ResumeLayout(false);
|
||||
this.GroupBoxConfig.PerformLayout();
|
||||
this.GroupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.NumericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.NumericUpDownSpeed)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.PictureBoxWarship)).EndInit();
|
||||
this.PanelWarship.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox GroupBoxConfig;
|
||||
private Label LabelAdvancedWarship;
|
||||
private Label LabelBasicWarship;
|
||||
private GroupBox GroupBoxColors;
|
||||
private Panel PanelSilver;
|
||||
private Panel PanelRed;
|
||||
private Panel PanelBlue;
|
||||
private Panel PanelCyan;
|
||||
private Panel PanelLime;
|
||||
private Panel PanelFuchsia;
|
||||
private Panel PanelYellow;
|
||||
private Panel PanelOrange;
|
||||
private CheckBox CheckBoxMissile;
|
||||
private CheckBox CheckBoxAntenna;
|
||||
private CheckBox CheckBoxHelipad;
|
||||
private NumericUpDown NumericUpDownWeight;
|
||||
private NumericUpDown NumericUpDownSpeed;
|
||||
private Label LabelWeight;
|
||||
private Label LabelSpeed;
|
||||
private PictureBox PictureBoxWarship;
|
||||
private Panel PanelWarship;
|
||||
private Label LabelModifColor;
|
||||
private Label LabelBodyColor;
|
||||
private Button ButtomAdd;
|
||||
private Button ButtonCancel;
|
||||
}
|
||||
}
|
138
Warship/Warship/FormWarshipConfig.cs
Normal file
138
Warship/Warship/FormWarshipConfig.cs
Normal file
@ -0,0 +1,138 @@
|
||||
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 FormWarshipConfig : Form
|
||||
{
|
||||
|
||||
DrawingWarship _warship = null;
|
||||
private event Action<DrawingWarship> EventAddWarship;
|
||||
public FormWarshipConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
PanelBlue.MouseDown += PanelColor_MouseDown;
|
||||
PanelCyan.MouseDown += PanelColor_MouseDown;
|
||||
PanelFuchsia.MouseDown += PanelColor_MouseDown;
|
||||
PanelLime.MouseDown += PanelColor_MouseDown;
|
||||
PanelOrange.MouseDown += PanelColor_MouseDown;
|
||||
PanelRed.MouseDown += PanelColor_MouseDown;
|
||||
PanelSilver.MouseDown += PanelColor_MouseDown;
|
||||
PanelYellow.MouseDown += PanelColor_MouseDown;
|
||||
ButtonCancel.Click += (sender, e) => Close();
|
||||
}
|
||||
|
||||
private void DrawWarship()
|
||||
{
|
||||
Bitmap bmp = new(PictureBoxWarship.Width,PictureBoxWarship.Height);
|
||||
Graphics gr =Graphics.FromImage(bmp);
|
||||
_warship?.SetPosition(5, 5, PictureBoxWarship.Width, PictureBoxWarship.Height);
|
||||
_warship?.DrawTransport(gr);
|
||||
PictureBoxWarship.Image = bmp;
|
||||
}
|
||||
|
||||
public void AddEvent(Action<DrawingWarship> ev)
|
||||
{
|
||||
if (EventAddWarship == null)
|
||||
{
|
||||
EventAddWarship = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddWarship += ev;
|
||||
}
|
||||
}
|
||||
|
||||
private void LabelWarship_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void PanelWarship_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
e.Effect=DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void PanelWarship_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "LabelBasicWarship":
|
||||
_warship = new DrawingWarship((int)NumericUpDownSpeed.Value, (int)NumericUpDownWeight.Value, Color.White);
|
||||
break;
|
||||
case "LabelAdvancedWarship":
|
||||
_warship = new DrawingAdvancedWarship((int)NumericUpDownSpeed.Value, (int)NumericUpDownWeight.Value, Color.White, Color.Black, CheckBoxHelipad.Checked, CheckBoxAntenna.Checked, CheckBoxMissile.Checked);
|
||||
break;
|
||||
}
|
||||
DrawWarship();
|
||||
}
|
||||
|
||||
private void PanelColor_MouseDown(object sender,MouseEventArgs e)
|
||||
{
|
||||
(sender as Control).DoDragDrop((sender as Control).BackColor,DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void LabelBodyColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect=DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
private void LabelModifColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_warship is DrawingAdvancedWarship)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LabelBodyColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
Color BodyColor = (Color)e.Data.GetData(typeof(Color));
|
||||
_warship.SetColor(BodyColor);
|
||||
DrawWarship();
|
||||
}
|
||||
|
||||
private void LabelModifColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
Color ModifColor = (Color)e.Data.GetData(typeof(Color));
|
||||
if(_warship is DrawingAdvancedWarship AdvancedWarship)
|
||||
{
|
||||
AdvancedWarship.SetModifColor(ModifColor);
|
||||
DrawWarship();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtomAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddWarship?.Invoke(_warship);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
Warship/Warship/FormWarshipConfig.resx
Normal file
60
Warship/Warship/FormWarshipConfig.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<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:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
17
Warship/Warship/IDrawingObject.cs
Normal file
17
Warship/Warship/IDrawingObject.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal interface IDrawingObject
|
||||
{
|
||||
public float Step { get; }
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
void MoveObject(Direction direction);
|
||||
void DrawingObject(Graphics g);
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
}
|
||||
}
|
122
Warship/Warship/MapWithSetWarshipsGeneric.cs
Normal file
122
Warship/Warship/MapWithSetWarshipsGeneric.cs
Normal file
@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal class MapWithSetWarshipsGeneric<T,U>
|
||||
where T : class, IDrawingObject
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 120;
|
||||
private readonly int _placeSizeHeight = 50;
|
||||
private readonly SetWarshipsGeneric<T> _setWarship;
|
||||
private readonly U _map;
|
||||
|
||||
public MapWithSetWarshipsGeneric(int picWidth,int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight/_placeSizeHeight;
|
||||
_setWarship = new SetWarshipsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public static int operator +(MapWithSetWarshipsGeneric<T,U> map, T warship)
|
||||
{
|
||||
return map._setWarship.Insert(warship);
|
||||
}
|
||||
|
||||
public static T operator -(MapWithSetWarshipsGeneric<T,U> map, int position)
|
||||
{
|
||||
return map._setWarship.Remove(position);
|
||||
}
|
||||
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawWarship(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
foreach(var warship in _setWarship.GetWarships())
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, warship);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
public void Shaking()
|
||||
{
|
||||
int j = _setWarship.Count - 1;
|
||||
for (int i = 0; i < _setWarship.Count; i++)
|
||||
{
|
||||
if (_setWarship[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var warship = _setWarship[j];
|
||||
if (warship != null)
|
||||
{
|
||||
_setWarship.Insert(warship, i);
|
||||
_setWarship.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics gr)
|
||||
{
|
||||
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 + 20, j * _placeSizeHeight+2, i * _placeSizeWidth + (int)(_placeSizeWidth*0.8), j * _placeSizeHeight+2);
|
||||
gr.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + _placeSizeHeight/2+2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight/2+2);
|
||||
gr.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight/2);
|
||||
gr.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2, i * _placeSizeWidth+ (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawWarship(Graphics gr)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
int i= 0;
|
||||
|
||||
foreach(var warship in _setWarship.GetWarships())
|
||||
{
|
||||
warship.SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
warship.DrawingObject(gr);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
Warship/Warship/MapsCollection.cs
Normal file
56
Warship/Warship/MapsCollection.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
readonly Dictionary<string, MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap>> _mapStorages;
|
||||
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (_mapStorages.ContainsKey(name))
|
||||
{
|
||||
MessageBox.Show("Карта уже существует");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapStorages.Add(name, new MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
}
|
||||
|
||||
public void DelMap(string name)
|
||||
{
|
||||
|
||||
_mapStorages.Remove(name);
|
||||
|
||||
}
|
||||
|
||||
public MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mapStorages.ContainsKey(ind))
|
||||
return _mapStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace Warship
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormWarship());
|
||||
Application.Run(new FormMapWithSetWarships());
|
||||
}
|
||||
}
|
||||
}
|
48
Warship/Warship/SecondMap.cs
Normal file
48
Warship/Warship/SecondMap.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal class SecondMap : AbstractMap
|
||||
{
|
||||
private readonly Brush waterColor = new SolidBrush(Color.White);
|
||||
private readonly Brush landColor = new SolidBrush(Color.Black);
|
||||
protected override void DrawLandPart(Graphics gr, int i, int j)
|
||||
{
|
||||
gr.FillRectangle(landColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
|
||||
protected override void DrawWaterPart(Graphics gr, int i, int j)
|
||||
{
|
||||
gr.FillRectangle(waterColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeWaterArea;
|
||||
}
|
||||
}
|
||||
while (counter < 20)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeWaterArea)
|
||||
{
|
||||
_map[x, y] = _land;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
81
Warship/Warship/SetWarshipsGeneric.cs
Normal file
81
Warship/Warship/SetWarshipsGeneric.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal class SetWarshipsGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly List<T> _places;
|
||||
|
||||
public int Count => _places.Count;
|
||||
|
||||
private readonly int _maxCount;
|
||||
|
||||
public SetWarshipsGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
|
||||
public int Insert(T warship)
|
||||
{
|
||||
if (_places.Count + 1 >= _maxCount)
|
||||
return -1;
|
||||
_places.Insert(0, warship);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int Insert(T warship, int position)
|
||||
{
|
||||
if (position >= _maxCount || position < 0)
|
||||
return -1;
|
||||
if (_places.Count + 1 >= _maxCount)
|
||||
return -1;
|
||||
_places.Insert(position, warship);
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= _maxCount || position < 0)
|
||||
return null;
|
||||
|
||||
T deleted =_places[position];
|
||||
_places.RemoveAt(position);
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public T this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
return null;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
Warship/Warship/SimpleMap.cs
Normal file
48
Warship/Warship/SimpleMap.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal class SimpleMap : AbstractMap
|
||||
{
|
||||
private readonly Brush waterColor = new SolidBrush(Color.Blue);
|
||||
private readonly Brush landColor = new SolidBrush(Color.Brown);
|
||||
protected override void DrawLandPart(Graphics gr, int i, int j)
|
||||
{
|
||||
gr.FillRectangle(landColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
|
||||
protected override void DrawWaterPart(Graphics gr, int i, int j)
|
||||
{
|
||||
gr.FillRectangle(waterColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y=(float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i=0;i<_map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeWaterArea;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeWaterArea)
|
||||
{
|
||||
_map[x, y] = _land;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user