LabWork01

This commit is contained in:
Сафия Мухамадиева 2024-06-02 17:21:54 +03:00
parent eb93d49c6b
commit d36c8c65c2
4 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBattleship;
public enum BlockEnum
{
Two,
Four,
Six
}

View File

@ -4,6 +4,7 @@
/// </summary>
public class DrawingBattleship
{
public DrawingBlock Block { get; set; }
/// <summary>
/// Класс-сущность
/// </summary>
@ -51,6 +52,7 @@ public class DrawingBattleship
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
Block = new DrawingBlock();
}
/// <summary>
/// Установка границ поля
@ -225,5 +227,7 @@ public class DrawingBattleship
g.DrawRectangle(pen, _startPosX.Value + 119,
_startPosY.Value + 24, 12, 2);
}
Block.DrawBlocks(g, _startPosX, _startPosY);
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBattleship;
public class DrawingBlock
{
public BlockEnum BlockNum;
public int NumOfBlocks
{
set
{
switch (value)
{
case 0:
BlockNum = BlockEnum.Two;
break;
case 1:
BlockNum = BlockEnum.Four;
break;
case 2:
BlockNum = BlockEnum.Six;
break;
default:
BlockNum = BlockEnum.Two;
break;
}
}
}
public void DrawBlocks(Graphics g, int? _startPosX, int? _startPosY)
{
Brush blocksColor = new SolidBrush(Color.Orange);
g.FillRectangle(blocksColor, _startPosX.Value + 10,
_startPosY.Value , 10, 10);
g.FillRectangle(blocksColor, _startPosX.Value + 10,
_startPosY.Value+40, 10, 10);
if (BlockNum == BlockEnum.Four || BlockNum == BlockEnum.Six)
{
g.FillRectangle(blocksColor, _startPosX.Value + 30,
_startPosY.Value, 10, 10);
g.FillRectangle(blocksColor, _startPosX.Value + 30,
_startPosY.Value + 40, 10, 10);
}
if (BlockNum == BlockEnum.Six)
{
g.FillRectangle(blocksColor, _startPosX.Value + 50,
_startPosY.Value, 10, 10);
g.FillRectangle(blocksColor, _startPosX.Value + 50,
_startPosY.Value + 40, 10, 10);
}
}
}

View File

@ -48,6 +48,7 @@ public partial class FormBattleship : Form
pictureBoxBattleship.Height);
_drawingBattleship.SetPosition(random.Next(10, 100),
random.Next(10, 100));
_drawingBattleship.Block.NumOfBlocks = random.Next(0, 3);
Draw();
}
/// <summary>