LabWork01
This commit is contained in:
parent
eb93d49c6b
commit
d36c8c65c2
14
ProjectBattleship/ProjectBattleship/BlockEnum.cs
Normal file
14
ProjectBattleship/ProjectBattleship/BlockEnum.cs
Normal 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
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
59
ProjectBattleship/ProjectBattleship/DrawingBlock.cs
Normal file
59
ProjectBattleship/ProjectBattleship/DrawingBlock.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user