91 lines
3.1 KiB
C#
91 lines
3.1 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 WinFormsApp1
|
|||
|
{
|
|||
|
public partial class FormMap : Form
|
|||
|
{
|
|||
|
private AbstractMap _abstractMap;
|
|||
|
|
|||
|
public FormMap()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_abstractMap = new SimpleMap();
|
|||
|
}
|
|||
|
|
|||
|
//Заполнение информации по объекту
|
|||
|
private void SetData(TractorDraw tractor)
|
|||
|
{
|
|||
|
toolStripStatusLabelSpeed.Text = $"Скорость: {tractor.Tractor.Speed}";
|
|||
|
toolStripStatusLabelWeight.Text = $"Вес: {tractor.Tractor.Weight}";
|
|||
|
toolStripStatusLabelBodyColor.Text = $"Цвет: {tractor.Tractor.BodyColor.Name}";
|
|||
|
pictureBoxTractor.Image = _abstractMap.CreateMap(pictureBoxTractor.Width, pictureBoxTractor.Height,
|
|||
|
new DrawningObjectTractor(tractor));
|
|||
|
}
|
|||
|
|
|||
|
//Логика кнопки Создать
|
|||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Random random = new();
|
|||
|
var tractor = new TractorDraw(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
|||
|
SetData(tractor);
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
//получаем имя кнопки
|
|||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|||
|
Direction dir = Direction.None;
|
|||
|
switch (name)
|
|||
|
{
|
|||
|
case "buttonUp":
|
|||
|
dir = Direction.Up;
|
|||
|
break;
|
|||
|
case "buttonDown":
|
|||
|
dir = Direction.Down;
|
|||
|
break;
|
|||
|
case "buttonLeft":
|
|||
|
dir = Direction.Left;
|
|||
|
break;
|
|||
|
case "buttonRight":
|
|||
|
dir = Direction.Right;
|
|||
|
break;
|
|||
|
}
|
|||
|
pictureBoxTractor.Image = _abstractMap?.MoveObject(dir);
|
|||
|
}
|
|||
|
|
|||
|
// Обработка нажатия кнопки "Модификация"
|
|||
|
private void buttonCreateModif_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Random random = new Random();
|
|||
|
var _Tractor = new MultiTraktorDraw(random.Next(100, 200), random.Next(2500, 5000),
|
|||
|
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)));
|
|||
|
SetData(_Tractor);
|
|||
|
}
|
|||
|
|
|||
|
private void comboBoxSelectionMap_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
switch (comboBoxSelectionMap.Text)
|
|||
|
{
|
|||
|
case "Простая карта":
|
|||
|
_abstractMap = new SimpleMap();
|
|||
|
break;
|
|||
|
case "Поле":
|
|||
|
_abstractMap = new FieldMap();
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|