PIbd-23_Lisov_N.A._AirFight.../AirFighter/FormMap.cs

103 lines
3.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 AirFighter
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
private void SetData(DrawingAircraft plane)
{
toolStripStatusSpeed.Text = $"Speed: {plane.Plane.Speed}";
toolStripStatusWeight.Text = $"Weight: {plane.Plane.Weight}";
toolStripStatusBodyColor.Text = $"BodyColor: {plane.Plane.BodyColor.Name}";
pictureBoxAirFighter.Image = _abstractMap.CreateMap(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height, new DrawingObjectAircraft(plane) );
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
var plane = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetData(plane);
}
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;
}
pictureBoxAirFighter.Image = _abstractMap?.MoveObject(dir);
}
private void buttonCreateModification_Click(object sender, EventArgs e)
{
Random rnd = new Random();
var plane = new DrawingMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(plane);
}
private void comboBoxMapSelection_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxMapSelection.Text)
{
case "1. Simple map":
{
_abstractMap = new SimpleMap();
}
break;
case "2. NightSky map":
{
_abstractMap = new NightSkyMap();
}
break;
}
}
}
}