76 lines
2.7 KiB
C#
76 lines
2.7 KiB
C#
namespace Battleship
|
|
{
|
|
public partial class FormBattleship : Form
|
|
{
|
|
private DrawningBattleship _battleship;
|
|
|
|
public FormBattleship()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
|
/// </summary>
|
|
private void Draw()
|
|
{
|
|
Bitmap bmp = new(pictureBoxBattleship.Width, pictureBoxBattleship.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_battleship?.DrawTransport(gr);
|
|
pictureBoxBattleship.Image = bmp;
|
|
}
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random rnd = new();
|
|
_battleship = new DrawningBattleship();
|
|
_battleship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
_battleship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBattleship.Width, pictureBoxBattleship.Height);
|
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_battleship.Battleship.Speed}";
|
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_battleship.Battleship.Weight}";
|
|
toolStripStatusLabeBodylColor.Text = $"Öâåò: {_battleship.Battleship.BodyColor.Name}";
|
|
Draw();
|
|
}
|
|
/// <summary>
|
|
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
//ïîëó÷àåì èìÿ êíîïêè
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_battleship?.MoveTransport(Direction.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_battleship?.MoveTransport(Direction.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_battleship?.MoveTransport(Direction.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_battleship?.MoveTransport(Direction.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
/// <summary>
|
|
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void PictureBoxBattleship_Resize(object sender, EventArgs e)
|
|
{
|
|
_battleship?.ChangeBorders(pictureBoxBattleship.Width, pictureBoxBattleship.Height);
|
|
Draw();
|
|
}
|
|
}
|
|
} |