148 lines
4.4 KiB
C#
148 lines
4.4 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 FormMapWithSetAircrafts : Form
|
|
{
|
|
private MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap> _mapAircraftsCollectionGeneric;
|
|
|
|
public FormMapWithSetAircrafts()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void ShowMapButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (_mapAircraftsCollectionGeneric == null)
|
|
{
|
|
return;
|
|
}
|
|
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowOnMap();
|
|
}
|
|
|
|
private void comboBoxMapSelection_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
AbstractMap map = null;
|
|
switch (comboBoxMapSelection.Text)
|
|
{
|
|
case "1. Simple map":
|
|
{
|
|
map = new SimpleMap();
|
|
}
|
|
break;
|
|
case "2. NightSky map":
|
|
{
|
|
map = new NightSkyMap();
|
|
}
|
|
break;
|
|
|
|
|
|
}
|
|
if (map != null)
|
|
{
|
|
_mapAircraftsCollectionGeneric = new MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
|
}
|
|
else
|
|
{
|
|
_mapAircraftsCollectionGeneric = null;
|
|
}
|
|
}
|
|
|
|
private void AddAircraftButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (_mapAircraftsCollectionGeneric == null)
|
|
{
|
|
return;
|
|
}
|
|
AirFighterForm form = new();
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
DrawingObjectAircraft aircraft = new(form.SelectedAircraft);
|
|
if (_mapAircraftsCollectionGeneric + aircraft)
|
|
{
|
|
MessageBox.Show("Object is added");
|
|
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowSet();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Unable to add object");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DeleteAircraftButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(maskedTextBoxPostion.Text))
|
|
{
|
|
return;
|
|
}
|
|
if (MessageBox.Show("Delete object?", "Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
{
|
|
return;
|
|
}
|
|
int pos = Convert.ToInt32(maskedTextBoxPostion.Text);
|
|
if (_mapAircraftsCollectionGeneric - pos)
|
|
{
|
|
MessageBox.Show("Object is deleted");
|
|
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowSet();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Unable to delete object");
|
|
}
|
|
}
|
|
|
|
private void ShowHangarButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (_mapAircraftsCollectionGeneric == null)
|
|
{
|
|
return;
|
|
}
|
|
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowSet();
|
|
}
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_mapAircraftsCollectionGeneric == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
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;
|
|
}
|
|
pictureBox.Image = _mapAircraftsCollectionGeneric.MoveObject(dir);
|
|
}
|
|
}
|
|
}
|