Фикс 3 лабы
This commit is contained in:
parent
cb66cd7938
commit
98ce97ea6f
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace WarmlyShip
|
namespace WarmlyShip
|
||||||
{
|
{
|
||||||
internal enum Direction //Направление при перемещении
|
public enum Direction //Направление при перемещении
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
Left = 1, //Влево
|
Left = 1, //Влево
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace WarmlyShip
|
namespace WarmlyShip
|
||||||
{
|
{
|
||||||
internal class DrawingWarmlyShip
|
public class DrawingWarmlyShip
|
||||||
{
|
{
|
||||||
public EntityWarmlyShip warmlyShip { protected set; get; } //Класс-сущность
|
public EntityWarmlyShip warmlyShip { protected set; get; } //Класс-сущность
|
||||||
protected float _startPosX; //Координаты отрисовки по оси x
|
protected float _startPosX; //Координаты отрисовки по оси x
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace WarmlyShip
|
namespace WarmlyShip
|
||||||
{
|
{
|
||||||
internal class EntityWarmlyShip
|
public class EntityWarmlyShip
|
||||||
{
|
{
|
||||||
public int Speed { get; private set; } //Скорость
|
public int Speed { get; private set; } //Скорость
|
||||||
public float Weight { get; private set; } //Вес
|
public float Weight { get; private set; } //Вес
|
||||||
|
13
WarmlyShip/WarmlyShip/FormClass.Designer.cs
generated
13
WarmlyShip/WarmlyShip/FormClass.Designer.cs
generated
@ -39,6 +39,7 @@
|
|||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.ButtonCreate = new System.Windows.Forms.Button();
|
this.ButtonCreate = new System.Windows.Forms.Button();
|
||||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSelectShip = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
this.statusStrip.SuspendLayout();
|
this.statusStrip.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -154,11 +155,22 @@
|
|||||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||||
//
|
//
|
||||||
|
// buttonSelectShip
|
||||||
|
//
|
||||||
|
this.buttonSelectShip.Location = new System.Drawing.Point(522, 402);
|
||||||
|
this.buttonSelectShip.Name = "buttonSelectShip";
|
||||||
|
this.buttonSelectShip.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSelectShip.TabIndex = 9;
|
||||||
|
this.buttonSelectShip.Text = "Выбрать";
|
||||||
|
this.buttonSelectShip.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSelectShip.Click += new System.EventHandler(this.ButtonSelectShip_Click);
|
||||||
|
//
|
||||||
// FormClass
|
// FormClass
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonSelectShip);
|
||||||
this.Controls.Add(this.buttonCreateModif);
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
this.Controls.Add(this.ButtonCreate);
|
this.Controls.Add(this.ButtonCreate);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
@ -190,5 +202,6 @@
|
|||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button ButtonCreate;
|
private Button ButtonCreate;
|
||||||
private Button buttonCreateModif;
|
private Button buttonCreateModif;
|
||||||
|
private Button buttonSelectShip;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,8 @@ namespace WarmlyShip
|
|||||||
{
|
{
|
||||||
private DrawingWarmlyShip _warmlyShip;
|
private DrawingWarmlyShip _warmlyShip;
|
||||||
|
|
||||||
|
public DrawingWarmlyShip SelectedShip { get; private set; }
|
||||||
|
|
||||||
public FormClass()
|
public FormClass()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -71,5 +73,11 @@ namespace WarmlyShip
|
|||||||
SetData();
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSelectShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedShip = _warmlyShip;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
122
WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs
Normal file
122
WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WarmlyShip
|
||||||
|
{
|
||||||
|
internal class MapWithSetShipGeneric<T, U>
|
||||||
|
where T : class, IDrawningObject
|
||||||
|
where U : AbstractMap
|
||||||
|
{
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
private readonly int _placeSizeWidth = 210;
|
||||||
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
private readonly SetShipGeneric<T> _setShips;
|
||||||
|
private readonly U _map;
|
||||||
|
|
||||||
|
public MapWithSetShipGeneric(int picWidth, int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setShips = new SetShipGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator +(MapWithSetShipGeneric<T, U> map, T ship)
|
||||||
|
{
|
||||||
|
return map._setShips.Insert(ship);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator -(MapWithSetShipGeneric<T, U> map, int position)
|
||||||
|
{
|
||||||
|
return map._setShips.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap ShowSet()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawShips(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
for (int i = 0; i < _setShips.Count; i++)
|
||||||
|
{
|
||||||
|
var ship = _setShips.Get(i);
|
||||||
|
if (ship != null)
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, ship);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
return _map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setShips.Count - 1;
|
||||||
|
for (int i = 0; i < _setShips.Count; i++)
|
||||||
|
{
|
||||||
|
if (_setShips.Get(i) == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var ship = _setShips.Get(j);
|
||||||
|
if (ship != null)
|
||||||
|
{
|
||||||
|
_setShips.Insert(ship, i);
|
||||||
|
_setShips.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{//линия рамзетки места
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i *
|
||||||
|
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||||
|
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawShips(Graphics g)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _setShips.Count; i++)
|
||||||
|
{
|
||||||
|
// TODO установка позиции
|
||||||
|
_setShips.Get(i)?.DrawningObject(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
49
WarmlyShip/WarmlyShip/SetShipGeneric.cs
Normal file
49
WarmlyShip/WarmlyShip/SetShipGeneric.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WarmlyShip
|
||||||
|
{
|
||||||
|
internal class SetShipGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
private readonly T[] _places;
|
||||||
|
public int Count => _places.Length;
|
||||||
|
public SetShipGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T[count];
|
||||||
|
}
|
||||||
|
public bool Insert(T ship)
|
||||||
|
{
|
||||||
|
// TODO вставка в начало набора
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Insert(T ship, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||||
|
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||||
|
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||||
|
// TODO вставка по позиции
|
||||||
|
_places[position] = ship;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO удаление объекта из массива, присовив элементу массива значение null
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Get(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user