Merge pull request 'Lisov N.A LabWork3' (#3) from LabWork03 into LabWork02
Reviewed-on: http://student.git.athene.tech/1yuee/PIbd-23_Lisov_N.A._AirFighter._Base/pulls/3
This commit is contained in:
commit
059c5c908e
@ -37,16 +37,12 @@ namespace AirFighter
|
||||
{
|
||||
int CollisionFlag = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
Size objSize1 = new Size(100,100);
|
||||
|
||||
//COLLISION CHECK
|
||||
if (direction == Direction.Up)
|
||||
{
|
||||
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
@ -123,12 +119,7 @@ namespace AirFighter
|
||||
{
|
||||
Point LeftTop = new Point((int)(_drawingObject.GetCurrentPosition().Left + _drawingObject.Step), (int)_drawingObject.GetCurrentPosition().Top);
|
||||
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
|
||||
|
||||
|
||||
|
||||
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
|
||||
|
||||
|
||||
if (objectRect.IntersectsWith(rectBarrier))
|
||||
{
|
||||
CollisionFlag = 1;
|
||||
@ -175,11 +166,8 @@ namespace AirFighter
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private Bitmap DrawMapWithObject()
|
||||
@ -208,14 +196,11 @@ namespace AirFighter
|
||||
return bmp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
13
AirFighter/AirFighterForm.Designer.cs
generated
13
AirFighter/AirFighterForm.Designer.cs
generated
@ -39,6 +39,7 @@
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModification = new System.Windows.Forms.Button();
|
||||
this.SelectButton = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
|
||||
this.statusStripAircraft.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -152,11 +153,22 @@
|
||||
this.buttonCreateModification.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModification.Click += new System.EventHandler(this.buttonCreateModification_Click);
|
||||
//
|
||||
// SelectButton
|
||||
//
|
||||
this.SelectButton.Location = new System.Drawing.Point(551, 390);
|
||||
this.SelectButton.Name = "SelectButton";
|
||||
this.SelectButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.SelectButton.TabIndex = 8;
|
||||
this.SelectButton.Text = "Select";
|
||||
this.SelectButton.UseVisualStyleBackColor = true;
|
||||
this.SelectButton.Click += new System.EventHandler(this.SelectButton_Click);
|
||||
//
|
||||
// AirFighterForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.SelectButton);
|
||||
this.Controls.Add(this.buttonCreateModification);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
@ -188,5 +200,6 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateModification;
|
||||
private Button SelectButton;
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ namespace AirFighter
|
||||
{
|
||||
private DrawingAircraft _aircraft;
|
||||
|
||||
public DrawingAircraft SelectedAircraft { get; private set; }
|
||||
|
||||
public AirFighterForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -17,7 +19,6 @@ namespace AirFighter
|
||||
pictureBoxAirFighter.Image = bmp;
|
||||
}
|
||||
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
@ -28,14 +29,21 @@ namespace AirFighter
|
||||
toolStripStatusBodyColor.Text = $"BodyColor: {_aircraft.Plane.BodyColor.Name}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_aircraft = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
Random rnd = new();
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
|
||||
rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_aircraft = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
color);
|
||||
SetData();
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
@ -75,14 +83,34 @@ namespace AirFighter
|
||||
|
||||
private void buttonCreateModification_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_aircraft = 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)));
|
||||
|
||||
Random rnd = new();
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
|
||||
rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
|
||||
rnd.Next(0, 256));
|
||||
ColorDialog dialogDop = new();
|
||||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialogDop.Color;
|
||||
}
|
||||
_aircraft = new DrawingMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
color, dopColor,
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,
|
||||
2)));
|
||||
SetData();
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
||||
private void SelectButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedAircraft = _aircraft;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up =1,
|
||||
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class DrawingAircraft
|
||||
public class DrawingAircraft
|
||||
{
|
||||
public EntityAircraft Plane { get; protected set; }
|
||||
|
||||
@ -140,8 +140,6 @@ namespace AirFighter
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Aircraft Body
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brWhite = new SolidBrush(Plane.BodyColor);
|
||||
@ -150,7 +148,6 @@ namespace AirFighter
|
||||
g.DrawRectangle(pen,_startPosX + 20, _startPosY + 45, 80, 14);
|
||||
|
||||
//Wings
|
||||
|
||||
GraphicsPath pathWing1 = new GraphicsPath();
|
||||
|
||||
Point point1B = new Point((int)(_startPosX + 50), (int)(_startPosY + 45));
|
||||
@ -163,7 +160,6 @@ namespace AirFighter
|
||||
g.DrawPath(pen, pathWing1);
|
||||
g.FillPath(brWhite, pathWing1);
|
||||
|
||||
|
||||
GraphicsPath pathWing2 = new GraphicsPath();
|
||||
|
||||
Point point1B2 = new Point((int)(_startPosX + 50), (int)(_startPosY + 60));
|
||||
|
@ -26,9 +26,6 @@ namespace AirFighter
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
|
||||
|
||||
|
||||
if (militaryAircraft.ExtraWings)
|
||||
{
|
||||
GraphicsPath pathExtraWing1 = new GraphicsPath();
|
||||
@ -57,8 +54,6 @@ namespace AirFighter
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (militaryAircraft.Rockets)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 30,17,4);
|
||||
@ -87,10 +82,6 @@ namespace AirFighter
|
||||
pathRocketHead2.AddLines(pointsExtraRocketHead2);
|
||||
g.DrawPath(pen, pathRocketHead2);
|
||||
g.FillPath(extraBrush, pathRocketHead2);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class EntityAircraft
|
||||
public class EntityAircraft
|
||||
{
|
||||
public int Speed
|
||||
{
|
||||
@ -28,8 +28,7 @@ namespace AirFighter
|
||||
|
||||
//=> оператор подобный return
|
||||
public float Step => Speed * 100 / Weight;
|
||||
|
||||
|
||||
|
||||
public EntityAircraft(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
|
@ -10,12 +10,10 @@ namespace AirFighter
|
||||
{
|
||||
public Color ExtraColor { get; private set; }
|
||||
|
||||
|
||||
public bool Rockets { get; private set; }
|
||||
|
||||
public bool ExtraWings { get; private set; }
|
||||
|
||||
|
||||
public EntityMilitaryAircraft(int speed, float weight, Color bodyColor, Color extraColor, bool rockets, bool extraWings) : base(speed, weight, bodyColor)
|
||||
{
|
||||
ExtraColor = extraColor;
|
||||
|
207
AirFighter/FormMap.Designer.cs
generated
207
AirFighter/FormMap.Designer.cs
generated
@ -1,207 +0,0 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
partial class FormMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxAirFighter = new System.Windows.Forms.PictureBox();
|
||||
this.statusStripAircraft = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModification = new System.Windows.Forms.Button();
|
||||
this.comboBoxMapSelection = new System.Windows.Forms.ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
|
||||
this.statusStripAircraft.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxAirFighter
|
||||
//
|
||||
this.pictureBoxAirFighter.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxAirFighter.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxAirFighter.Name = "pictureBoxAirFighter";
|
||||
this.pictureBoxAirFighter.Size = new System.Drawing.Size(800, 428);
|
||||
this.pictureBoxAirFighter.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxAirFighter.TabIndex = 0;
|
||||
this.pictureBoxAirFighter.TabStop = false;
|
||||
//
|
||||
// statusStripAircraft
|
||||
//
|
||||
this.statusStripAircraft.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusSpeed,
|
||||
this.toolStripStatusWeight,
|
||||
this.toolStripStatusBodyColor});
|
||||
this.statusStripAircraft.Location = new System.Drawing.Point(0, 428);
|
||||
this.statusStripAircraft.Name = "statusStripAircraft";
|
||||
this.statusStripAircraft.Size = new System.Drawing.Size(800, 22);
|
||||
this.statusStripAircraft.TabIndex = 1;
|
||||
//
|
||||
// toolStripStatusSpeed
|
||||
//
|
||||
this.toolStripStatusSpeed.Name = "toolStripStatusSpeed";
|
||||
this.toolStripStatusSpeed.Size = new System.Drawing.Size(42, 17);
|
||||
this.toolStripStatusSpeed.Text = "Speed:";
|
||||
//
|
||||
// toolStripStatusWeight
|
||||
//
|
||||
this.toolStripStatusWeight.Name = "toolStripStatusWeight";
|
||||
this.toolStripStatusWeight.Size = new System.Drawing.Size(48, 17);
|
||||
this.toolStripStatusWeight.Text = "Weight:";
|
||||
//
|
||||
// toolStripStatusBodyColor
|
||||
//
|
||||
this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor";
|
||||
this.toolStripStatusBodyColor.Size = new System.Drawing.Size(66, 17);
|
||||
this.toolStripStatusBodyColor.Text = "BodyColor:";
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(12, 389);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Create";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_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(702, 346);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 3;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_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(666, 382);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 4;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
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(738, 382);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 5;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_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(702, 382);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 6;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonCreateModification
|
||||
//
|
||||
this.buttonCreateModification.Location = new System.Drawing.Point(103, 389);
|
||||
this.buttonCreateModification.Name = "buttonCreateModification";
|
||||
this.buttonCreateModification.Size = new System.Drawing.Size(110, 23);
|
||||
this.buttonCreateModification.TabIndex = 7;
|
||||
this.buttonCreateModification.Text = "Modification";
|
||||
this.buttonCreateModification.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModification.Click += new System.EventHandler(this.buttonCreateModification_Click);
|
||||
//
|
||||
// comboBoxMapSelection
|
||||
//
|
||||
this.comboBoxMapSelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxMapSelection.FormattingEnabled = true;
|
||||
this.comboBoxMapSelection.Items.AddRange(new object[] {
|
||||
"1. Simple map",
|
||||
"2. NightSky map"});
|
||||
this.comboBoxMapSelection.Location = new System.Drawing.Point(12, 12);
|
||||
this.comboBoxMapSelection.Name = "comboBoxMapSelection";
|
||||
this.comboBoxMapSelection.Size = new System.Drawing.Size(121, 23);
|
||||
this.comboBoxMapSelection.TabIndex = 8;
|
||||
this.comboBoxMapSelection.SelectedIndexChanged += new System.EventHandler(this.comboBoxMapSelection_SelectedIndexChanged);
|
||||
//
|
||||
// FormMap
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.comboBoxMapSelection);
|
||||
this.Controls.Add(this.buttonCreateModification);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.pictureBoxAirFighter);
|
||||
this.Controls.Add(this.statusStripAircraft);
|
||||
this.Name = "FormMap";
|
||||
this.Text = "Map";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).EndInit();
|
||||
this.statusStripAircraft.ResumeLayout(false);
|
||||
this.statusStripAircraft.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxAirFighter;
|
||||
private StatusStrip statusStripAircraft;
|
||||
private ToolStripStatusLabel toolStripStatusSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusWeight;
|
||||
private ToolStripStatusLabel toolStripStatusBodyColor;
|
||||
private Button buttonCreate;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateModification;
|
||||
private ComboBox comboBoxMapSelection;
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
216
AirFighter/FormMapWithSetAircrafts.Designer.cs
generated
Normal file
216
AirFighter/FormMapWithSetAircrafts.Designer.cs
generated
Normal file
@ -0,0 +1,216 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
partial class FormMapWithSetAircrafts
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.PanelGroupBox = new System.Windows.Forms.GroupBox();
|
||||
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.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.PanelGroupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// PanelGroupBox
|
||||
//
|
||||
this.PanelGroupBox.Controls.Add(this.buttonDown);
|
||||
this.PanelGroupBox.Controls.Add(this.buttonRight);
|
||||
this.PanelGroupBox.Controls.Add(this.ShowMapButton);
|
||||
this.PanelGroupBox.Controls.Add(this.buttonLeft);
|
||||
this.PanelGroupBox.Controls.Add(this.ShowHangarButton);
|
||||
this.PanelGroupBox.Controls.Add(this.buttonUp);
|
||||
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(600, 0);
|
||||
this.PanelGroupBox.Name = "PanelGroupBox";
|
||||
this.PanelGroupBox.Size = new System.Drawing.Size(200, 450);
|
||||
this.PanelGroupBox.TabIndex = 0;
|
||||
this.PanelGroupBox.TabStop = false;
|
||||
this.PanelGroupBox.Text = "Function panel";
|
||||
//
|
||||
// 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(600, 450);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// comboBoxMapSelection
|
||||
//
|
||||
this.comboBoxMapSelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxMapSelection.FormattingEnabled = true;
|
||||
this.comboBoxMapSelection.Items.AddRange(new object[] {
|
||||
"1. Simple map",
|
||||
"2. NightSky map"});
|
||||
this.comboBoxMapSelection.Location = new System.Drawing.Point(6, 22);
|
||||
this.comboBoxMapSelection.Name = "comboBoxMapSelection";
|
||||
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(81, 408);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 11;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
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(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);
|
||||
//
|
||||
// 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(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);
|
||||
//
|
||||
// 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(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);
|
||||
//
|
||||
// FormMapWithSetAircrafts
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
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();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox PanelGroupBox;
|
||||
private PictureBox pictureBox;
|
||||
private ComboBox comboBoxMapSelection;
|
||||
private Button ShowMapButton;
|
||||
private Button ShowHangarButton;
|
||||
private Button DeleteAircraftButton;
|
||||
private MaskedTextBox maskedTextBoxPostion;
|
||||
private Button AddAircraftButton;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
}
|
||||
}
|
146
AirFighter/FormMapWithSetAircrafts.cs
Normal file
146
AirFighter/FormMapWithSetAircrafts.cs
Normal file
@ -0,0 +1,146 @@
|
||||
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 != -1)
|
||||
{
|
||||
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 != null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -57,7 +57,4 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="statusStripAircraft.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
150
AirFighter/MapWithSetAircraftsGeneric.cs
Normal file
150
AirFighter/MapWithSetAircraftsGeneric.cs
Normal file
@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class MapWithSetAircraftsGeneric<T, U>
|
||||
where T : class, IDrawingObject
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
private readonly int _placeSizeWidth = 145;
|
||||
|
||||
private readonly int _placeSizeHeight = 145;
|
||||
|
||||
private readonly SetAircraftsGeneric<T> _setAircrafts;
|
||||
|
||||
private readonly U _map;
|
||||
|
||||
public MapWithSetAircraftsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setAircrafts = new SetAircraftsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public static int operator +(MapWithSetAircraftsGeneric<T, U> map, T aircraft)
|
||||
{
|
||||
|
||||
return map._setAircrafts.Insert(aircraft);
|
||||
}
|
||||
|
||||
public static T operator -(MapWithSetAircraftsGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setAircrafts.Remove(position);
|
||||
}
|
||||
|
||||
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawAircrafts(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setAircrafts.Count; i++)
|
||||
{
|
||||
var aircraft = _setAircrafts.Get(i);
|
||||
if (aircraft != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, aircraft);
|
||||
}
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setAircrafts.Count - 1;
|
||||
for (int i = 0; i < _setAircrafts.Count; i++)
|
||||
{
|
||||
if (_setAircrafts.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var aircraft = _setAircrafts.Get(i);
|
||||
if (aircraft != null)
|
||||
{
|
||||
_setAircrafts.Insert(aircraft, i);
|
||||
_setAircrafts.Remove(j);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
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, _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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DrawAircrafts(Graphics g)
|
||||
{
|
||||
|
||||
int curX = _pictureWidth / _placeSizeWidth - 1;
|
||||
int curY = _pictureHeight / _placeSizeHeight - 1;
|
||||
|
||||
for (int i = 0; i < _setAircrafts.Count; i++)
|
||||
{
|
||||
_setAircrafts.Get(i)?.SetObject(curX * _placeSizeWidth + 30, curY * _placeSizeHeight + 40, _pictureWidth, _pictureHeight);
|
||||
|
||||
_setAircrafts.Get(i)?.DrawingObject(g);
|
||||
|
||||
if (curX <= 0)
|
||||
{
|
||||
curX = _pictureWidth / _placeSizeWidth - 1;
|
||||
curY--;
|
||||
}
|
||||
else
|
||||
{
|
||||
curX--;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace AirFighter
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormMap());
|
||||
Application.Run(new FormMapWithSetAircrafts());
|
||||
}
|
||||
}
|
||||
}
|
87
AirFighter/SetAircraftsGeneric.cs
Normal file
87
AirFighter/SetAircraftsGeneric.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class SetAircraftsGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly T[] _places;
|
||||
|
||||
public int Count => _places.Length;
|
||||
|
||||
public SetAircraftsGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
|
||||
public int Insert(T aircraft)
|
||||
{
|
||||
return Insert(aircraft, 0);
|
||||
}
|
||||
|
||||
public int Insert(T aircraft, int position)
|
||||
{
|
||||
int emptypos = -1;
|
||||
|
||||
if (position >= Count && position < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < Count && position >= 0)
|
||||
{
|
||||
T result = _places[position];
|
||||
|
||||
_places[position] = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position >= Count && position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user