lab#3 ready

This commit is contained in:
Danil Markov 2022-10-24 21:21:12 +04:00
parent 969d383e4a
commit 1af1d0c9b5
5 changed files with 42 additions and 16 deletions

View File

@ -14,10 +14,12 @@ namespace ContainerShip
{
private MapWithSetShipGeneric<DrawingObjectShip, AbstractMap> _mapShipCollectionGeneric;
public bool onMap;
public FormMapWithSetShip()
{
InitializeComponent();
onMap = false;
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
@ -98,21 +100,25 @@ namespace ContainerShip
return;
}
pictureBox.Image = _mapShipCollectionGeneric.ShowSet();
onMap = false;
}
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapShipCollectionGeneric == null)
{
onMap = false;
return;
}
pictureBox.Image = _mapShipCollectionGeneric.ShowOnMap();
onMap = true;
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapShipCollectionGeneric == null)
if (_mapShipCollectionGeneric == null || !onMap)
{
return;
}
//получаем имя кнопки

View File

@ -160,7 +160,7 @@
this.buttonSelectShip.TabIndex = 11;
this.buttonSelectShip.Text = "Выбрать";
this.buttonSelectShip.UseVisualStyleBackColor = true;
this.buttonSelectShip.Click += new System.EventHandler(this.buttonSelectShip_Click);
this.buttonSelectShip.Click += new System.EventHandler(this.ButtonSelectShip_Click);
//
// FormShip
//

View File

@ -86,10 +86,13 @@ namespace ContainerShip
Draw();
}
private void buttonSelectShip_Click(object sender, EventArgs e)
private void ButtonSelectShip_Click(object sender, EventArgs e)
{
SelectedShip = _ship;
DialogResult = DialogResult.OK;
if(_ship != null)
{
SelectedShip = _ship;
DialogResult = DialogResult.OK;
}
}
}
}

View File

@ -103,16 +103,33 @@ namespace ContainerShip
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
SolidBrush brWater = new SolidBrush(Color.LightSkyBlue);
g.FillRectangle(brWater, 0,0,_pictureWidth, _pictureHeight);
Pen pen = new(Color.Brown, 3);
Pen penBold = new(Color.Brown, 5);
Pen penThin = new(Color.Black, 1);
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, j * _placeSizeHeight + _placeSizeHeight/2, i *
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight + _placeSizeHeight / 2);
for(int k = 1; k < 3; ++k)
{
g.DrawLine(penThin, i * _placeSizeWidth, j * _placeSizeHeight + k * 21, i *
_placeSizeWidth + 3 * _placeSizeWidth / 10, j * _placeSizeHeight + k * 21);
}
for (int k = 0; k < 4; ++k)
{
g.DrawLine(penBold, i * _placeSizeWidth + k * _placeSizeWidth / 10, j * _placeSizeHeight + 20, i * _placeSizeWidth + k * _placeSizeWidth / 10,
(j + 1) * _placeSizeHeight - 20);
}
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
@ -122,7 +139,7 @@ namespace ContainerShip
int xNumOfPlaces = _pictureWidth / _placeSizeWidth;
int RowIndex = yNumOfPlaces - 1;
int ColumnIndex = 0;
int ColumnIndex = xNumOfPlaces - 1;
for (int i = 0; i < _setShip.Count; i++)
{
@ -134,14 +151,14 @@ namespace ContainerShip
_pictureWidth, _pictureHeight);
_setShip.Get(i).DrawingObject(g);
}
if (ColumnIndex == xNumOfPlaces - 1)
if (ColumnIndex == 0)
{
ColumnIndex = 0;
ColumnIndex = xNumOfPlaces - 1;
RowIndex--;
}
else
{
ColumnIndex++;
ColumnIndex--;
}
}
}

View File

@ -82,7 +82,7 @@ namespace ContainerShip
{
if (position >= Count || position < 0)
{
return default(T);
return null;
}
return _places[position];
}