113 lines
3.6 KiB
C#
113 lines
3.6 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace ContainerShip
|
||
{
|
||
public partial class FormShip : Form
|
||
{
|
||
private DrawingShip _ship;
|
||
|
||
public DrawingShip SelectedShip { get; private set; }
|
||
|
||
public FormShip()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void Draw()
|
||
{
|
||
Bitmap bmp = new(pictureBoxShip.Width, pictureBoxShip.Height);
|
||
Graphics gr = Graphics.FromImage(bmp);
|
||
_ship?.DrawTransport(gr);
|
||
pictureBoxShip.Image = bmp;
|
||
}
|
||
|
||
private void ButtonMove_Click(object sender, EventArgs e)
|
||
{
|
||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||
switch (name)
|
||
{
|
||
case "buttonUp":
|
||
_ship?.MoveShip(Direction.Up);
|
||
break;
|
||
case "buttonDown":
|
||
_ship?.MoveShip(Direction.Down);
|
||
break;
|
||
case "buttonLeft":
|
||
_ship?.MoveShip(Direction.Left);
|
||
break;
|
||
case "buttonRight":
|
||
_ship?.MoveShip(Direction.Right);
|
||
break;
|
||
}
|
||
Draw();
|
||
}
|
||
|
||
private void SetData()
|
||
{
|
||
Random rnd = new();
|
||
toolStripStatusSpeed.Text = $"Скорость: {_ship.Ship.Speed}";
|
||
toolStripStatusWeight.Text = $"Вес: {_ship.Ship.Weight}";
|
||
toolStripStatusBodyColor.Text = $"Цвет: {_ship.Ship.BodyColor.Name}";
|
||
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(60, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
||
}
|
||
|
||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||
{
|
||
Random rnd = new();
|
||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||
ColorDialog dialog = new();
|
||
if(dialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
color = dialog.Color;
|
||
}
|
||
_ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||
SetData();
|
||
Draw();
|
||
}
|
||
|
||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
Random rnd = new();
|
||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||
ColorDialog dialog = new();
|
||
if (dialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
color = dialog.Color;
|
||
}
|
||
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||
ColorDialog dialogDop = new();
|
||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||
{
|
||
dopColor = dialogDop.Color;
|
||
}
|
||
_ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||
SetData();
|
||
Draw();
|
||
}
|
||
|
||
private void PictureBoxShip_Resize(object sender, EventArgs e)
|
||
{
|
||
_ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height);
|
||
Draw();
|
||
}
|
||
|
||
private void ButtonSelectShip_Click(object sender, EventArgs e)
|
||
{
|
||
if(_ship != null)
|
||
{
|
||
SelectedShip = _ship;
|
||
DialogResult = DialogResult.OK;
|
||
}
|
||
}
|
||
}
|
||
}
|