127 lines
4.2 KiB
C#
127 lines
4.2 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 Boats
|
||
{
|
||
public partial class FormMap : Form
|
||
{
|
||
private AbstractMap _abstractMap;
|
||
public FormMap()
|
||
{
|
||
InitializeComponent();
|
||
_abstractMap = new SimpleMap();
|
||
}
|
||
/// <summary>
|
||
/// Метод установки данных
|
||
/// </summary>
|
||
private void SetData(DrawingBoat boat)
|
||
{
|
||
toolStripStatusLabelSpeed.Text = $"Скорость: {boat.Boat.Speed}";
|
||
toolStripStatusLabelWeight.Text = $"Вес: {boat.Boat.Weight}";
|
||
toolStripStatusLabelBodyColor.Text = $"Цвет: {boat.Boat.BodyColor.Name}";
|
||
pictureBoxMap.Image = _abstractMap.CreateMap(pictureBoxMap.Width, pictureBoxMap.Height,
|
||
new DrawingObjectBoat(boat));
|
||
}
|
||
/// <summary>
|
||
/// Обработка нажатия кнопки "Создать"
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||
{
|
||
Random rnd = new();
|
||
var boat = new DrawingBoat(
|
||
rnd.Next(100, 300),
|
||
rnd.Next(1000, 2000),
|
||
Color.FromArgb(rnd.Next(0, 256),
|
||
rnd.Next(0, 256), rnd.Next(0, 256))
|
||
);
|
||
SetData(boat);
|
||
}
|
||
/// <summary>
|
||
/// Обработчик нажатий кнопок передвижения
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonMove_Click(object sender, EventArgs e)
|
||
{
|
||
//получаем имя кнопки
|
||
string btnName = ((Button)sender)?.Name ?? string.Empty;
|
||
Direction dir = Direction.None;
|
||
|
||
switch (btnName)
|
||
{
|
||
case "ButtonUp":
|
||
{
|
||
dir = Direction.Up;
|
||
}
|
||
break;
|
||
case "ButtonDown":
|
||
{
|
||
dir = Direction.Down;
|
||
}
|
||
break;
|
||
case "ButtonLeft":
|
||
{
|
||
dir = Direction.Left;
|
||
}
|
||
break;
|
||
case "ButtonRight":
|
||
{
|
||
dir = Direction.Right;
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
pictureBoxMap.Image = _abstractMap?.MoveObject(dir);
|
||
}
|
||
/// <summary>
|
||
/// Обработка нажатия кнопки "Модификация"
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonCreateModificate_Click(object sender, EventArgs e)
|
||
{
|
||
Random rnd = new Random();
|
||
|
||
var boat = new DrawingCatamaran(
|
||
rnd.Next(100, 300),
|
||
rnd.Next(1000, 2000),
|
||
Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)),
|
||
Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)),
|
||
Convert.ToBoolean(rnd.Next(0, 2)),
|
||
Convert.ToBoolean(rnd.Next(0, 2))
|
||
);
|
||
SetData(boat);
|
||
}
|
||
/// <summary>
|
||
/// Смена карты
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
switch (comboBoxSelectorMap.Text)
|
||
{
|
||
case "Простая карта":
|
||
_abstractMap = new SimpleMap();
|
||
break;
|
||
case "Океан карта":
|
||
_abstractMap = new OceanMap();
|
||
break;
|
||
case "Линии карта":
|
||
_abstractMap = new LineMap();
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|