80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
|
using System;
|
|||
|
|
|||
|
namespace Cruiser
|
|||
|
{
|
|||
|
public partial class FormCruiser : Form
|
|||
|
{
|
|||
|
Bitmap bmp;
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
private DrawingCruiser? _drawningCruiser;
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public FormCruiser()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
bmp = new(pictureBoxCruiser.Width, pictureBoxCruiser.Width);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
private void Draw()
|
|||
|
{
|
|||
|
if (_drawningCruiser == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Graphics gr = Graphics.FromImage(bmp);
|
|||
|
gr.Clear(Color.White);
|
|||
|
_drawningCruiser.DrawTransport(gr);
|
|||
|
pictureBoxCruiser.Image = bmp;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_drawningCruiser == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|||
|
switch (name)
|
|||
|
{
|
|||
|
case "buttonUp":
|
|||
|
_drawningCruiser.MoveTransport(Direction.Up);
|
|||
|
break;
|
|||
|
case "buttonDown":
|
|||
|
_drawningCruiser.MoveTransport(Direction.Down);
|
|||
|
break;
|
|||
|
case "buttonLeft":
|
|||
|
_drawningCruiser.MoveTransport(Direction.Left);
|
|||
|
break;
|
|||
|
case "buttonRight":
|
|||
|
_drawningCruiser.MoveTransport(Direction.Right);
|
|||
|
break;
|
|||
|
}
|
|||
|
Draw();
|
|||
|
}
|
|||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Random random = new();
|
|||
|
_drawningCruiser = new DrawingCruiser();
|
|||
|
_drawningCruiser.Init(random.Next(100, 300),
|
|||
|
random.Next(1000, 3000),
|
|||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|||
|
Convert.ToBoolean(random.Next(0, 2)),
|
|||
|
Convert.ToBoolean(random.Next(0, 2)),
|
|||
|
pictureBoxCruiser.Width,
|
|||
|
pictureBoxCruiser.Height);
|
|||
|
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|||
|
Draw();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|