1 Commits

5 changed files with 169 additions and 345 deletions

View File

@@ -29,30 +29,23 @@
private void InitializeComponent()
{
this.PanelGroupBox = new System.Windows.Forms.GroupBox();
this.MapsGroupBox = new System.Windows.Forms.GroupBox();
this.DeleteMapButton = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.AddMapButton = new System.Windows.Forms.Button();
this.newMapTextBox = new System.Windows.Forms.TextBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.comboBoxMapSelection = new System.Windows.Forms.ComboBox();
this.AddAircraftButton = new System.Windows.Forms.Button();
this.maskedTextBoxPostion = new System.Windows.Forms.MaskedTextBox();
this.DeleteAircraftButton = new System.Windows.Forms.Button();
this.ShowHangarButton = new System.Windows.Forms.Button();
this.ShowMapButton = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.ShowMapButton = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.ShowHangarButton = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.DeleteAircraftButton = new System.Windows.Forms.Button();
this.maskedTextBoxPostion = new System.Windows.Forms.MaskedTextBox();
this.AddAircraftButton = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.PanelGroupBox.SuspendLayout();
this.MapsGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// PanelGroupBox
//
this.PanelGroupBox.Controls.Add(this.MapsGroupBox);
this.PanelGroupBox.Controls.Add(this.buttonDown);
this.PanelGroupBox.Controls.Add(this.buttonRight);
this.PanelGroupBox.Controls.Add(this.ShowMapButton);
@@ -62,64 +55,23 @@
this.PanelGroupBox.Controls.Add(this.DeleteAircraftButton);
this.PanelGroupBox.Controls.Add(this.maskedTextBoxPostion);
this.PanelGroupBox.Controls.Add(this.AddAircraftButton);
this.PanelGroupBox.Controls.Add(this.comboBoxMapSelection);
this.PanelGroupBox.Dock = System.Windows.Forms.DockStyle.Right;
this.PanelGroupBox.Location = new System.Drawing.Point(672, 0);
this.PanelGroupBox.Location = new System.Drawing.Point(600, 0);
this.PanelGroupBox.Name = "PanelGroupBox";
this.PanelGroupBox.Size = new System.Drawing.Size(218, 623);
this.PanelGroupBox.Size = new System.Drawing.Size(200, 450);
this.PanelGroupBox.TabIndex = 0;
this.PanelGroupBox.TabStop = false;
this.PanelGroupBox.Text = "Function panel";
//
// MapsGroupBox
// pictureBox
//
this.MapsGroupBox.Controls.Add(this.DeleteMapButton);
this.MapsGroupBox.Controls.Add(this.listBoxMaps);
this.MapsGroupBox.Controls.Add(this.AddMapButton);
this.MapsGroupBox.Controls.Add(this.newMapTextBox);
this.MapsGroupBox.Controls.Add(this.comboBoxMapSelection);
this.MapsGroupBox.Location = new System.Drawing.Point(6, 22);
this.MapsGroupBox.Name = "MapsGroupBox";
this.MapsGroupBox.Size = new System.Drawing.Size(188, 260);
this.MapsGroupBox.TabIndex = 15;
this.MapsGroupBox.TabStop = false;
this.MapsGroupBox.Text = "Maps";
//
// DeleteMapButton
//
this.DeleteMapButton.Location = new System.Drawing.Point(6, 222);
this.DeleteMapButton.Name = "DeleteMapButton";
this.DeleteMapButton.Size = new System.Drawing.Size(176, 32);
this.DeleteMapButton.TabIndex = 13;
this.DeleteMapButton.Text = "Delete map";
this.DeleteMapButton.UseVisualStyleBackColor = true;
this.DeleteMapButton.Click += new System.EventHandler(this.DeleteMapButton_Click);
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 15;
this.listBoxMaps.Location = new System.Drawing.Point(8, 122);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(174, 94);
this.listBoxMaps.TabIndex = 12;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// AddMapButton
//
this.AddMapButton.Location = new System.Drawing.Point(6, 81);
this.AddMapButton.Name = "AddMapButton";
this.AddMapButton.Size = new System.Drawing.Size(176, 35);
this.AddMapButton.TabIndex = 11;
this.AddMapButton.Text = "Add map";
this.AddMapButton.UseVisualStyleBackColor = true;
this.AddMapButton.Click += new System.EventHandler(this.AddMapButton_Click);
//
// newMapTextBox
//
this.newMapTextBox.Location = new System.Drawing.Point(6, 22);
this.newMapTextBox.Name = "newMapTextBox";
this.newMapTextBox.Size = new System.Drawing.Size(176, 23);
this.newMapTextBox.TabIndex = 10;
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(600, 450);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// comboBoxMapSelection
//
@@ -128,17 +80,66 @@
this.comboBoxMapSelection.Items.AddRange(new object[] {
"1. Simple map",
"2. NightSky map"});
this.comboBoxMapSelection.Location = new System.Drawing.Point(6, 51);
this.comboBoxMapSelection.Location = new System.Drawing.Point(6, 22);
this.comboBoxMapSelection.Name = "comboBoxMapSelection";
this.comboBoxMapSelection.Size = new System.Drawing.Size(176, 23);
this.comboBoxMapSelection.Size = new System.Drawing.Size(182, 23);
this.comboBoxMapSelection.TabIndex = 9;
this.comboBoxMapSelection.SelectedIndexChanged += new System.EventHandler(this.comboBoxMapSelection_SelectedIndexChanged);
//
// AddAircraftButton
//
this.AddAircraftButton.Location = new System.Drawing.Point(6, 80);
this.AddAircraftButton.Name = "AddAircraftButton";
this.AddAircraftButton.Size = new System.Drawing.Size(182, 35);
this.AddAircraftButton.TabIndex = 10;
this.AddAircraftButton.Text = "Add aircraft";
this.AddAircraftButton.UseVisualStyleBackColor = true;
this.AddAircraftButton.Click += new System.EventHandler(this.AddAircraftButton_Click);
//
// maskedTextBoxPostion
//
this.maskedTextBoxPostion.Location = new System.Drawing.Point(6, 139);
this.maskedTextBoxPostion.Mask = "00";
this.maskedTextBoxPostion.Name = "maskedTextBoxPostion";
this.maskedTextBoxPostion.Size = new System.Drawing.Size(182, 23);
this.maskedTextBoxPostion.TabIndex = 11;
//
// DeleteAircraftButton
//
this.DeleteAircraftButton.Location = new System.Drawing.Point(6, 177);
this.DeleteAircraftButton.Name = "DeleteAircraftButton";
this.DeleteAircraftButton.Size = new System.Drawing.Size(182, 36);
this.DeleteAircraftButton.TabIndex = 12;
this.DeleteAircraftButton.Text = "Delete aircraft";
this.DeleteAircraftButton.UseVisualStyleBackColor = true;
this.DeleteAircraftButton.Click += new System.EventHandler(this.DeleteAircraftButton_Click);
//
// ShowHangarButton
//
this.ShowHangarButton.Location = new System.Drawing.Point(6, 258);
this.ShowHangarButton.Name = "ShowHangarButton";
this.ShowHangarButton.Size = new System.Drawing.Size(182, 30);
this.ShowHangarButton.TabIndex = 13;
this.ShowHangarButton.Text = "Show hangar";
this.ShowHangarButton.UseVisualStyleBackColor = true;
this.ShowHangarButton.Click += new System.EventHandler(this.ShowHangarButton_Click);
//
// ShowMapButton
//
this.ShowMapButton.Location = new System.Drawing.Point(6, 308);
this.ShowMapButton.Name = "ShowMapButton";
this.ShowMapButton.Size = new System.Drawing.Size(182, 36);
this.ShowMapButton.TabIndex = 14;
this.ShowMapButton.Text = "Show map";
this.ShowMapButton.UseVisualStyleBackColor = true;
this.ShowMapButton.Click += new System.EventHandler(this.ShowMapButton_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(99, 581);
this.buttonDown.Location = new System.Drawing.Point(81, 408);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 11;
@@ -150,107 +151,48 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(135, 581);
this.buttonRight.Location = new System.Drawing.Point(117, 408);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 10;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// ShowMapButton
//
this.ShowMapButton.Location = new System.Drawing.Point(6, 483);
this.ShowMapButton.Name = "ShowMapButton";
this.ShowMapButton.Size = new System.Drawing.Size(182, 36);
this.ShowMapButton.TabIndex = 14;
this.ShowMapButton.Text = "Show map";
this.ShowMapButton.UseVisualStyleBackColor = true;
this.ShowMapButton.Click += new System.EventHandler(this.ShowMapButton_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(63, 581);
this.buttonLeft.Location = new System.Drawing.Point(45, 408);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 9;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// ShowHangarButton
//
this.ShowHangarButton.Location = new System.Drawing.Point(6, 447);
this.ShowHangarButton.Name = "ShowHangarButton";
this.ShowHangarButton.Size = new System.Drawing.Size(182, 30);
this.ShowHangarButton.TabIndex = 13;
this.ShowHangarButton.Text = "Show hangar";
this.ShowHangarButton.UseVisualStyleBackColor = true;
this.ShowHangarButton.Click += new System.EventHandler(this.ShowHangarButton_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(99, 545);
this.buttonUp.Location = new System.Drawing.Point(81, 372);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 8;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// DeleteAircraftButton
//
this.DeleteAircraftButton.Location = new System.Drawing.Point(6, 405);
this.DeleteAircraftButton.Name = "DeleteAircraftButton";
this.DeleteAircraftButton.Size = new System.Drawing.Size(182, 36);
this.DeleteAircraftButton.TabIndex = 12;
this.DeleteAircraftButton.Text = "Delete aircraft";
this.DeleteAircraftButton.UseVisualStyleBackColor = true;
this.DeleteAircraftButton.Click += new System.EventHandler(this.DeleteAircraftButton_Click);
//
// maskedTextBoxPostion
//
this.maskedTextBoxPostion.Location = new System.Drawing.Point(6, 358);
this.maskedTextBoxPostion.Mask = "00";
this.maskedTextBoxPostion.Name = "maskedTextBoxPostion";
this.maskedTextBoxPostion.Size = new System.Drawing.Size(182, 23);
this.maskedTextBoxPostion.TabIndex = 11;
//
// AddAircraftButton
//
this.AddAircraftButton.Location = new System.Drawing.Point(6, 317);
this.AddAircraftButton.Name = "AddAircraftButton";
this.AddAircraftButton.Size = new System.Drawing.Size(182, 35);
this.AddAircraftButton.TabIndex = 10;
this.AddAircraftButton.Text = "Add aircraft";
this.AddAircraftButton.UseVisualStyleBackColor = true;
this.AddAircraftButton.Click += new System.EventHandler(this.AddAircraftButton_Click);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(672, 623);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetAircrafts
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(890, 623);
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.PanelGroupBox);
this.Name = "FormMapWithSetAircrafts";
this.Text = "MapWithSelectedAircrafts";
this.PanelGroupBox.ResumeLayout(false);
this.PanelGroupBox.PerformLayout();
this.MapsGroupBox.ResumeLayout(false);
this.MapsGroupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
@@ -270,10 +212,5 @@
private Button buttonRight;
private Button buttonLeft;
private Button buttonUp;
private GroupBox MapsGroupBox;
private Button DeleteMapButton;
private ListBox listBoxMaps;
private Button AddMapButton;
private TextBox newMapTextBox;
}
}

View File

@@ -12,59 +12,52 @@ namespace AirFighter
{
public partial class FormMapWithSetAircrafts : Form
{
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Simple map", new SimpleMap() },
{"Nightsky map", new NightSkyMap()}
};
private readonly MapsCollection _mapsCollection;
private MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap> _mapAircraftsCollectionGeneric;
public FormMapWithSetAircrafts()
{
InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxMapSelection.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxMapSelection.Items.Add(elem.Key);
}
}
private void RefreshMaps()
{
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
}
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{
listBoxMaps.SelectedIndex = index;
}
}
private void ShowMapButton_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
if (_mapAircraftsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
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 (listBoxMaps.SelectedIndex == -1)
if (_mapAircraftsCollectionGeneric == null)
{
return;
}
@@ -72,10 +65,10 @@ namespace AirFighter
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectAircraft aircraft = new(form.SelectedAircraft);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + aircraft != -1)
if (_mapAircraftsCollectionGeneric + aircraft != -1)
{
MessageBox.Show("Object is added");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowSet();
}
else
{
@@ -86,11 +79,6 @@ namespace AirFighter
private void DeleteAircraftButton_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPostion.Text))
{
return;
@@ -100,10 +88,10 @@ namespace AirFighter
return;
}
int pos = Convert.ToInt32(maskedTextBoxPostion.Text);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
if (_mapAircraftsCollectionGeneric - pos != null)
{
MessageBox.Show("Object is deleted");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowSet();
}
else
{
@@ -113,16 +101,16 @@ namespace AirFighter
private void ShowHangarButton_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
if (_mapAircraftsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowSet();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
if (_mapAircraftsCollectionGeneric == null)
{
return;
}
@@ -152,42 +140,7 @@ namespace AirFighter
}
break;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
private void AddMapButton_Click(object sender, EventArgs e)
{
if (comboBoxMapSelection.SelectedIndex == -1 || string.IsNullOrEmpty(newMapTextBox.Text))
{
MessageBox.Show("Not all data is filled", " Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapsDict.ContainsKey(comboBoxMapSelection.Text))
{
MessageBox.Show("There is no such map","Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(newMapTextBox.Text, _mapsDict[comboBoxMapSelection.Text]);
RefreshMaps();
}
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void DeleteMapButton_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?", "Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DeleteMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
RefreshMaps();
}
pictureBox.Image = _mapAircraftsCollectionGeneric.MoveObject(dir);
}
}
}

View File

@@ -34,6 +34,7 @@ namespace AirFighter
public static int operator +(MapWithSetAircraftsGeneric<T, U> map, T aircraft)
{
return map._setAircrafts.Insert(aircraft);
}
@@ -55,13 +56,15 @@ namespace AirFighter
public Bitmap ShowOnMap()
{
Shaking();
foreach (var aircraft in _setAircrafts.GetAircrafts())
for (int i = 0; i < _setAircrafts.Count; i++)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, aircraft);
var aircraft = _setAircrafts.Get(i);
if (aircraft != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, aircraft);
}
}
return new(_pictureWidth, _pictureHeight);
}
public Bitmap MoveObject(Direction direction)
@@ -78,11 +81,11 @@ namespace AirFighter
int j = _setAircrafts.Count - 1;
for (int i = 0; i < _setAircrafts.Count; i++)
{
if (_setAircrafts[i] == null)
if (_setAircrafts.Get(i) == null)
{
for (; j > i; j--)
{
var aircraft = _setAircrafts[j];
var aircraft = _setAircrafts.Get(i);
if (aircraft != null)
{
_setAircrafts.Insert(aircraft, i);
@@ -104,13 +107,11 @@ namespace AirFighter
Pen pen = new(Color.Black, 2);
for (int i = 0; i < _pictureWidth / _placeSizeWidth + 1; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
{
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 135, _placeSizeWidth - 80, j * _placeSizeHeight + 135);
if(i * _placeSizeWidth + _placeSizeWidth + 20 < _pictureWidth - 10)
{
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 60, i * _placeSizeWidth + _placeSizeWidth / 2 + 20, j * _placeSizeHeight + 45);
}
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 135, _pictureWidth - 80, j * _placeSizeHeight + 135);
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 60, i * _placeSizeWidth + _placeSizeWidth /2 + 20, j * _placeSizeHeight + 45);
g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth / 2 + 20, j * _placeSizeHeight + 45, i * _placeSizeWidth + _placeSizeWidth + 20 , j * _placeSizeHeight + 60);
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 135, i * _placeSizeWidth + 20, j * _placeSizeHeight + 60);
@@ -121,13 +122,15 @@ namespace AirFighter
private void DrawAircrafts(Graphics g)
{
int curX = _pictureWidth / _placeSizeWidth - 1;
int curY = _pictureHeight / _placeSizeHeight - 1;
foreach (var aircraft in _setAircrafts.GetAircrafts())
for (int i = 0; i < _setAircrafts.Count; i++)
{
aircraft.SetObject(curX * _placeSizeWidth + 30, curY * _placeSizeHeight + 40, _pictureWidth, _pictureHeight);
aircraft.DrawingObject(g);
_setAircrafts.Get(i)?.SetObject(curX * _placeSizeWidth + 30, curY * _placeSizeHeight + 40, _pictureWidth, _pictureHeight);
_setAircrafts.Get(i)?.DrawingObject(g);
if (curX <= 0)
{
@@ -139,7 +142,9 @@ namespace AirFighter
curX--;
}
}
}
}
}
}

View File

@@ -1,56 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter
{
internal class MapsCollection
{
readonly Dictionary<string, MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>> _mapsVault;
public List<string> Keys => _mapsVault.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private bool flag = false;
public MapsCollection(int pictureWidth, int pictureHeight)
{
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
_mapsVault = new Dictionary<string, MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>>();
}
public void AddMap(string name, AbstractMap map)
{
if (!Keys.Contains(name))
{
_mapsVault.Add(name, new MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
}
public void DeleteMap(string name)
{
if (Keys.Contains(name))
{
_mapsVault.Remove(name);
}
}
public MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap> this[string ind]
{
get
{
return _mapsVault.ContainsKey(ind) ? _mapsVault[ind] : null;
}
}
}
}

View File

@@ -10,16 +10,13 @@ namespace AirFighter
internal class SetAircraftsGeneric<T>
where T : class
{
private readonly List<T> _places;
private readonly T[] _places;
public int Count => _places.Count;
private readonly int _maxCount;
public int Count => _places.Length;
public SetAircraftsGeneric(int count)
{
_maxCount = count;
_places = new List<T>();
_places = new T[count];
}
public int Insert(T aircraft)
@@ -29,74 +26,62 @@ namespace AirFighter
public int Insert(T aircraft, int position)
{
if (position > Count || position < 0 || Count == _maxCount)
int emptypos = -1;
if (position >= Count && position < 0)
{
return -1;
}
_places.Insert(position, aircraft);
if (_places[position] == null)
{
_places[position] = aircraft;
return position;
}
for (int i = position; i < Count; i++)
{
if (_places[i] == null)
{
emptypos = i;
break;
}
}
if (emptypos != -1)
{
for (int i = emptypos; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = aircraft;
return position;
}
return -1;
return position;
}
public T Remove(int position)
{
if (position < Count && position >= 0)
{
if (_places.ElementAt(position) != null)
{
T result = _places.ElementAt(position);
T result = _places[position];
_places.RemoveAt(position);
return result;
}
return null;
_places[position] = null;
return result;
}
return null;
}
public T this[int position]
public T Get(int position)
{
get
if (position >= Count && position < 0)
{
if (position < _maxCount && position >= 0)
{
return _places.ElementAt(position);
}
return null;
}
set
{
if (position < _maxCount && position >= 0)
{
Insert(value,position);
}
}
return _places[position];
}
public IEnumerable<T> GetAircrafts()
{
foreach (var aircraft in _places)
{
if (aircraft != null)
{
yield return aircraft;
}
else
{
yield break;
}
}
}
}
}