Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
a768d109b5 | |||
530345052e | |||
d898e0f034 | |||
e49ac3812f | |||
af229fc84e |
@ -8,4 +8,23 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="MovementStrategy\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
179
AirBomber/BomberForm.Designer.cs
generated
Normal file
179
AirBomber/BomberForm.Designer.cs
generated
Normal file
@ -0,0 +1,179 @@
|
||||
namespace AirBomber
|
||||
{
|
||||
partial class BomberForm
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
BomberPictureBox = new PictureBox();
|
||||
ButtonCreateBomberBase = new Button();
|
||||
ButtonRight = new Button();
|
||||
ButtonDown = new Button();
|
||||
ButtonLeft = new Button();
|
||||
ButtonUp = new Button();
|
||||
MovementStrategyComboBox = new ComboBox();
|
||||
ButtonCreateBomber = new Button();
|
||||
ButtonPerformMove = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)BomberPictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// BomberPictureBox
|
||||
//
|
||||
BomberPictureBox.Dock = DockStyle.Fill;
|
||||
BomberPictureBox.Location = new Point(0, 0);
|
||||
BomberPictureBox.Name = "BomberPictureBox";
|
||||
BomberPictureBox.Size = new Size(884, 461);
|
||||
BomberPictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
BomberPictureBox.TabIndex = 0;
|
||||
BomberPictureBox.TabStop = false;
|
||||
//
|
||||
// ButtonCreateBomberBase
|
||||
//
|
||||
ButtonCreateBomberBase.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonCreateBomberBase.Location = new Point(177, 407);
|
||||
ButtonCreateBomberBase.Name = "ButtonCreateBomberBase";
|
||||
ButtonCreateBomberBase.Size = new Size(159, 42);
|
||||
ButtonCreateBomberBase.TabIndex = 1;
|
||||
ButtonCreateBomberBase.Text = "Создать бомбардировщик";
|
||||
ButtonCreateBomberBase.UseVisualStyleBackColor = true;
|
||||
ButtonCreateBomberBase.Click += ButtonCreateBomberBase_Click;
|
||||
//
|
||||
// ButtonRight
|
||||
//
|
||||
ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonRight.BackgroundImage = Properties.Resources.ArrowRight;
|
||||
ButtonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
ButtonRight.Location = new Point(842, 419);
|
||||
ButtonRight.Name = "ButtonRight";
|
||||
ButtonRight.Size = new Size(30, 30);
|
||||
ButtonRight.TabIndex = 2;
|
||||
ButtonRight.UseVisualStyleBackColor = true;
|
||||
ButtonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// ButtonDown
|
||||
//
|
||||
ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonDown.BackgroundImage = Properties.Resources.ArrowDown;
|
||||
ButtonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
ButtonDown.Location = new Point(806, 419);
|
||||
ButtonDown.Name = "ButtonDown";
|
||||
ButtonDown.Size = new Size(30, 30);
|
||||
ButtonDown.TabIndex = 3;
|
||||
ButtonDown.UseVisualStyleBackColor = true;
|
||||
ButtonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// ButtonLeft
|
||||
//
|
||||
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonLeft.BackgroundImage = Properties.Resources.ArrowLeft;
|
||||
ButtonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
ButtonLeft.Location = new Point(770, 419);
|
||||
ButtonLeft.Name = "ButtonLeft";
|
||||
ButtonLeft.Size = new Size(30, 30);
|
||||
ButtonLeft.TabIndex = 4;
|
||||
ButtonLeft.UseVisualStyleBackColor = true;
|
||||
ButtonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// ButtonUp
|
||||
//
|
||||
ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonUp.BackgroundImage = Properties.Resources.ArrowUp;
|
||||
ButtonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
ButtonUp.Location = new Point(806, 383);
|
||||
ButtonUp.Name = "ButtonUp";
|
||||
ButtonUp.Size = new Size(30, 30);
|
||||
ButtonUp.TabIndex = 5;
|
||||
ButtonUp.UseVisualStyleBackColor = true;
|
||||
ButtonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// MovementStrategyComboBox
|
||||
//
|
||||
MovementStrategyComboBox.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
MovementStrategyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
MovementStrategyComboBox.FormattingEnabled = true;
|
||||
MovementStrategyComboBox.Items.AddRange(new object[] { "Перемещать в центр", "Перемещать вправо вниз" });
|
||||
MovementStrategyComboBox.Location = new Point(706, 12);
|
||||
MovementStrategyComboBox.Name = "MovementStrategyComboBox";
|
||||
MovementStrategyComboBox.Size = new Size(166, 23);
|
||||
MovementStrategyComboBox.TabIndex = 6;
|
||||
//
|
||||
// ButtonCreateBomber
|
||||
//
|
||||
ButtonCreateBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonCreateBomber.Location = new Point(12, 407);
|
||||
ButtonCreateBomber.Name = "ButtonCreateBomber";
|
||||
ButtonCreateBomber.Size = new Size(159, 42);
|
||||
ButtonCreateBomber.TabIndex = 7;
|
||||
ButtonCreateBomber.Text = "Создать продвинутый бомбардировщик";
|
||||
ButtonCreateBomber.UseVisualStyleBackColor = true;
|
||||
ButtonCreateBomber.Click += ButtonCreateBomber_Click;
|
||||
//
|
||||
// ButtonPerformMove
|
||||
//
|
||||
ButtonPerformMove.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonPerformMove.Location = new Point(706, 50);
|
||||
ButtonPerformMove.Name = "ButtonPerformMove";
|
||||
ButtonPerformMove.Size = new Size(166, 31);
|
||||
ButtonPerformMove.TabIndex = 8;
|
||||
ButtonPerformMove.Text = "Сделать шаг";
|
||||
ButtonPerformMove.UseVisualStyleBackColor = true;
|
||||
ButtonPerformMove.Click += ButtonPerformStep_Click;
|
||||
//
|
||||
// BomberForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(884, 461);
|
||||
Controls.Add(ButtonPerformMove);
|
||||
Controls.Add(ButtonCreateBomber);
|
||||
Controls.Add(MovementStrategyComboBox);
|
||||
Controls.Add(ButtonUp);
|
||||
Controls.Add(ButtonLeft);
|
||||
Controls.Add(ButtonDown);
|
||||
Controls.Add(ButtonRight);
|
||||
Controls.Add(ButtonCreateBomberBase);
|
||||
Controls.Add(BomberPictureBox);
|
||||
Name = "BomberForm";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Бомбардировщик";
|
||||
((System.ComponentModel.ISupportInitialize)BomberPictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox BomberPictureBox;
|
||||
private Button ButtonCreateBomberBase;
|
||||
private Button ButtonRight;
|
||||
private Button ButtonDown;
|
||||
private Button ButtonLeft;
|
||||
private Button ButtonUp;
|
||||
private ComboBox MovementStrategyComboBox;
|
||||
private Button ButtonCreateBomber;
|
||||
private Button ButtonPerformMove;
|
||||
}
|
||||
}
|
134
AirBomber/BomberForm.cs
Normal file
134
AirBomber/BomberForm.cs
Normal file
@ -0,0 +1,134 @@
|
||||
using AirBomber.MovementStrategy;
|
||||
using AirBomber.Rendering;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
public partial class BomberForm : Form
|
||||
{
|
||||
private BomberRendererBase? _bomberRenderer;
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public BomberForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_bomberRenderer == null)
|
||||
return;
|
||||
|
||||
Bitmap bmp = new Bitmap(BomberPictureBox.Width, BomberPictureBox.Height);
|
||||
Graphics g = Graphics.FromImage(bmp);
|
||||
_bomberRenderer.DrawEntity(g);
|
||||
|
||||
BomberPictureBox.Image = bmp;
|
||||
}
|
||||
|
||||
private void ButtonCreateBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
|
||||
_bomberRenderer = new BomberRenderer(
|
||||
random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
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)),
|
||||
true,
|
||||
true,
|
||||
BomberPictureBox.Width,
|
||||
BomberPictureBox.Height
|
||||
);
|
||||
_bomberRenderer.SetPosition(random.Next(10, 60), random.Next(10, 60));
|
||||
|
||||
MovementStrategyComboBox.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonCreateBomberBase_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
|
||||
_bomberRenderer = new BomberRendererBase(
|
||||
random.Next(100, 200),
|
||||
random.Next(1000, 1800),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
BomberPictureBox.Width,
|
||||
BomberPictureBox.Height
|
||||
);
|
||||
_bomberRenderer.SetPosition(random.Next(20, 100), random.Next(20, 100));
|
||||
|
||||
MovementStrategyComboBox.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_bomberRenderer == null)
|
||||
return;
|
||||
|
||||
string ButtonName = ((Button)sender)?.Name ?? string.Empty;
|
||||
|
||||
switch (ButtonName)
|
||||
{
|
||||
case "ButtonUp":
|
||||
_bomberRenderer.MoveEntity(DirectionType.Up);
|
||||
break;
|
||||
|
||||
case "ButtonDown":
|
||||
_bomberRenderer.MoveEntity(DirectionType.Down);
|
||||
break;
|
||||
|
||||
case "ButtonLeft":
|
||||
_bomberRenderer.MoveEntity(DirectionType.Left);
|
||||
break;
|
||||
|
||||
case "ButtonRight":
|
||||
_bomberRenderer.MoveEntity(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonPerformStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_bomberRenderer is null)
|
||||
return;
|
||||
|
||||
if (MovementStrategyComboBox.Enabled)
|
||||
{
|
||||
_strategy = MovementStrategyComboBox.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenterStrategy(),
|
||||
1 => new MoveToDownRightStrategy(),
|
||||
|
||||
_ => null,
|
||||
};
|
||||
|
||||
if (_strategy is null)
|
||||
return;
|
||||
|
||||
_strategy.SetData(
|
||||
new ObjectEntityRenderer(_bomberRenderer),
|
||||
BomberPictureBox.Width,
|
||||
BomberPictureBox.Height
|
||||
);
|
||||
|
||||
MovementStrategyComboBox.Enabled = false;
|
||||
}
|
||||
|
||||
if (_strategy is null)
|
||||
return;
|
||||
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
MovementStrategyComboBox.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
AirBomber/Entities/BomberEntity.cs
Normal file
17
AirBomber/Entities/BomberEntity.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace AirBomber.Entities
|
||||
{
|
||||
public class BomberEntity : BomberEntityBase
|
||||
{
|
||||
public Color AdditionalColor { get; private set; }
|
||||
public bool Bombs { get; private set; }
|
||||
public bool FuelTanks { get; private set; }
|
||||
|
||||
public BomberEntity(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool FuelTanks, bool Bombs)
|
||||
: base(Speed, Weight, BodyColor)
|
||||
{
|
||||
this.AdditionalColor = AdditionalColor;
|
||||
this.FuelTanks = FuelTanks;
|
||||
this.Bombs = Bombs;
|
||||
}
|
||||
}
|
||||
}
|
17
AirBomber/Entities/BomberEntityBase.cs
Normal file
17
AirBomber/Entities/BomberEntityBase.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace AirBomber.Entities
|
||||
{
|
||||
public class BomberEntityBase
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public double Step => (double)Speed * 100 / Weight * 5 / 2;
|
||||
|
||||
public BomberEntityBase(int Speed, double Weight, Color BodyColor)
|
||||
{
|
||||
this.Speed = Speed;
|
||||
this.Weight = Weight;
|
||||
this.BodyColor = BodyColor;
|
||||
}
|
||||
}
|
||||
}
|
39
AirBomber/Form1.Designer.cs
generated
39
AirBomber/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace AirBomber
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <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.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace AirBomber
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
76
AirBomber/MovementStrategy/AbstractStrategy.cs
Normal file
76
AirBomber/MovementStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,76 @@
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
private IMovableObject? _movableObject;
|
||||
|
||||
private Status _state = Status.NotInit;
|
||||
|
||||
protected int FieldWidth { get; private set; }
|
||||
protected int FieldHeight { get; private set; }
|
||||
|
||||
public Status GetStatus() { return _state; }
|
||||
|
||||
public void SetData(IMovableObject MovableObject, int Width, int Height)
|
||||
{
|
||||
if (MovableObject is null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
|
||||
_state = Status.InProgress;
|
||||
_movableObject = MovableObject;
|
||||
|
||||
FieldWidth = Width;
|
||||
FieldHeight = Height;
|
||||
}
|
||||
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
return;
|
||||
|
||||
if (IsTargetDestination())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
|
||||
protected ObjectParameters? ObjectParameters => _movableObject?.ObjectPosition;
|
||||
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
return null;
|
||||
|
||||
return _movableObject?.Step;
|
||||
}
|
||||
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
protected abstract bool IsTargetDestination();
|
||||
|
||||
private bool MoveTo(DirectionType DirectionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
return false;
|
||||
|
||||
if (_movableObject?.CanMove(DirectionType) ?? false)
|
||||
{
|
||||
_movableObject.MoveObject(DirectionType);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
10
AirBomber/MovementStrategy/DirectionType.cs
Normal file
10
AirBomber/MovementStrategy/DirectionType.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
||||
Up = 1,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
}
|
12
AirBomber/MovementStrategy/IMovableObject.cs
Normal file
12
AirBomber/MovementStrategy/IMovableObject.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public interface IMovableObject
|
||||
{
|
||||
ObjectParameters? ObjectPosition { get; }
|
||||
int Step { get; }
|
||||
|
||||
bool CanMove(DirectionType Direction);
|
||||
|
||||
void MoveObject(DirectionType Direction);
|
||||
}
|
||||
}
|
44
AirBomber/MovementStrategy/MoveToCenterStrategy.cs
Normal file
44
AirBomber/MovementStrategy/MoveToCenterStrategy.cs
Normal file
@ -0,0 +1,44 @@
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public class MoveToCenterStrategy : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestination()
|
||||
{
|
||||
ObjectParameters? ObjParams = ObjectParameters;
|
||||
if (ObjParams is null)
|
||||
return false;
|
||||
|
||||
float FieldMiddleHorizontal = FieldWidth / 2;
|
||||
float FieldMiddleVertical = FieldHeight / 2;
|
||||
|
||||
return
|
||||
Math.Abs(ObjParams.ObjectMiddleHorizontal - FieldMiddleHorizontal) < GetStep() &&
|
||||
Math.Abs(ObjParams.ObjectMiddleVertical - FieldMiddleVertical) < GetStep();
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? ObjParams = ObjectParameters;
|
||||
if (ObjParams is null)
|
||||
return;
|
||||
|
||||
float diffX = ObjParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
MoveLeft();
|
||||
else
|
||||
MoveRight();
|
||||
}
|
||||
|
||||
float diffY = ObjParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
MoveUp();
|
||||
else
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
43
AirBomber/MovementStrategy/MoveToDownRightStrategy.cs
Normal file
43
AirBomber/MovementStrategy/MoveToDownRightStrategy.cs
Normal file
@ -0,0 +1,43 @@
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public class MoveToDownRightStrategy : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestination()
|
||||
{
|
||||
ObjectParameters? ObjParams = ObjectParameters;
|
||||
if (ObjParams is null)
|
||||
return false;
|
||||
|
||||
return
|
||||
ObjParams.RightBorder <= FieldWidth &&
|
||||
ObjParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
ObjParams.BottomBorder <= FieldHeight &&
|
||||
ObjParams.BottomBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? ObjParams = ObjectParameters;
|
||||
if (ObjParams is null)
|
||||
return;
|
||||
|
||||
float diffX = ObjParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
MoveLeft();
|
||||
else
|
||||
MoveRight();
|
||||
}
|
||||
|
||||
float diffY = ObjParams.BottomBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
MoveUp();
|
||||
else
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
AirBomber/MovementStrategy/ObjectEntityRenderer.cs
Normal file
36
AirBomber/MovementStrategy/ObjectEntityRenderer.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using AirBomber.Rendering;
|
||||
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public class ObjectEntityRenderer : IMovableObject
|
||||
{
|
||||
private readonly BomberRendererBase? _entityRenderer = null;
|
||||
|
||||
public ObjectEntityRenderer(BomberRendererBase? EntityRenderer)
|
||||
{
|
||||
_entityRenderer = EntityRenderer;
|
||||
}
|
||||
|
||||
public ObjectParameters? ObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_entityRenderer is null || _entityRenderer.EntityBomber is null)
|
||||
return null;
|
||||
|
||||
return new ObjectParameters(
|
||||
_entityRenderer.PosX,
|
||||
_entityRenderer.PosY,
|
||||
_entityRenderer.EntityWidth,
|
||||
_entityRenderer.EntityHeight
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public int Step => (int)(_entityRenderer?.EntityBomber?.Step ?? 0);
|
||||
|
||||
public bool CanMove(DirectionType Direction) => _entityRenderer?.CanMove(Direction) ?? false;
|
||||
|
||||
public void MoveObject(DirectionType Direction) => _entityRenderer?.MoveEntity(Direction);
|
||||
}
|
||||
}
|
27
AirBomber/MovementStrategy/ObjectParameters.cs
Normal file
27
AirBomber/MovementStrategy/ObjectParameters.cs
Normal file
@ -0,0 +1,27 @@
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
|
||||
public int LeftBorder => _x;
|
||||
public int TopBorder => _y;
|
||||
public int RightBorder => _x + _width;
|
||||
public int BottomBorder => _y + _height;
|
||||
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
|
||||
public ObjectParameters(int X, int Y, int Width, int Height)
|
||||
{
|
||||
_x = X;
|
||||
_y = Y;
|
||||
_width = Width;
|
||||
_height = Height;
|
||||
}
|
||||
}
|
||||
}
|
9
AirBomber/MovementStrategy/Status.cs
Normal file
9
AirBomber/MovementStrategy/Status.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit = 1,
|
||||
InProgress,
|
||||
Finish,
|
||||
}
|
||||
}
|
@ -2,16 +2,11 @@ namespace AirBomber
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new BomberForm());
|
||||
}
|
||||
}
|
||||
}
|
103
AirBomber/Properties/Resources.Designer.cs
generated
Normal file
103
AirBomber/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace AirBomber.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AirBomber.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap ArrowDown {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("ArrowDown", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap ArrowLeft {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("ArrowLeft", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap ArrowRight {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("ArrowRight", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap ArrowUp {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("ArrowUp", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
133
AirBomber/Properties/Resources.resx
Normal file
133
AirBomber/Properties/Resources.resx
Normal file
@ -0,0 +1,133 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="ArrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
55
AirBomber/Rendering/BomberRenderer.cs
Normal file
55
AirBomber/Rendering/BomberRenderer.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using AirBomber.Entities;
|
||||
|
||||
namespace AirBomber.Rendering
|
||||
{
|
||||
public class BomberRenderer : BomberRendererBase
|
||||
{
|
||||
public BomberRenderer(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool FuelTanks, bool Bombs, int Width, int Height)
|
||||
: base(Speed, Weight, BodyColor, Width, Height, 200, 200)
|
||||
{
|
||||
if (EntityBomber is not null)
|
||||
EntityBomber = new BomberEntity(Speed, Weight, BodyColor, AdditionalColor, FuelTanks, Bombs);
|
||||
}
|
||||
|
||||
public override void DrawEntity(Graphics g)
|
||||
{
|
||||
if (EntityBomber is not BomberEntity DerivedEntityBomber)
|
||||
return;
|
||||
|
||||
base.DrawEntity(g);
|
||||
|
||||
Brush AdditionalBrush = new SolidBrush(DerivedEntityBomber.AdditionalColor);
|
||||
|
||||
/** Отрисовка дополнительных элементов */
|
||||
if (DerivedEntityBomber.FuelTanks)
|
||||
{
|
||||
Point[] LeftGasTank = {
|
||||
new Point(_startPosX + 50, _startPosY + 85),
|
||||
new Point(_startPosX + 75, _startPosY + 85),
|
||||
new Point(_startPosX + 75, _startPosY + 70),
|
||||
new Point(_startPosX + 50, _startPosY + 70),
|
||||
};
|
||||
g.FillPolygon(AdditionalBrush, LeftGasTank);
|
||||
|
||||
Point[] RightGasTank = {
|
||||
new Point(_startPosX + 50, _startPosY + 115),
|
||||
new Point(_startPosX + 75, _startPosY + 115),
|
||||
new Point(_startPosX + 75, _startPosY + 130),
|
||||
new Point(_startPosX + 50, _startPosY + 130),
|
||||
};
|
||||
g.FillPolygon(AdditionalBrush, RightGasTank);
|
||||
}
|
||||
|
||||
if (DerivedEntityBomber.Bombs)
|
||||
{
|
||||
Point LeftBombStartXY = new Point(_startPosX + 110, _startPosY + 115);
|
||||
Size LeftBombSize = new Size(50, 25);
|
||||
g.FillEllipse(AdditionalBrush, new Rectangle(LeftBombStartXY, LeftBombSize));
|
||||
|
||||
Point RightBombStartXY = new Point(_startPosX + 110, _startPosY + 60);
|
||||
Size RightBombSize = new Size(50, 25);
|
||||
g.FillEllipse(AdditionalBrush, new Rectangle(RightBombStartXY, RightBombSize));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
171
AirBomber/Rendering/BomberRendererBase.cs
Normal file
171
AirBomber/Rendering/BomberRendererBase.cs
Normal file
@ -0,0 +1,171 @@
|
||||
using AirBomber.Entities;
|
||||
using AirBomber.MovementStrategy;
|
||||
|
||||
namespace AirBomber.Rendering
|
||||
{
|
||||
public class BomberRendererBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public BomberEntityBase? EntityBomber { get; protected set; }
|
||||
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
|
||||
protected readonly int _bomberWidth = 200;
|
||||
protected readonly int _bomberHeight = 200;
|
||||
|
||||
public int PosX => _startPosX;
|
||||
public int PosY => _startPosY;
|
||||
|
||||
public int EntityWidth => _bomberWidth;
|
||||
public int EntityHeight => _bomberHeight;
|
||||
|
||||
public BomberRendererBase(int Speed, double Weight, Color BodyColor, int Width, int Height)
|
||||
{
|
||||
if (Width < _bomberWidth || Height < _bomberHeight)
|
||||
return;
|
||||
|
||||
_pictureWidth = Width;
|
||||
_pictureHeight = Height;
|
||||
|
||||
EntityBomber = new BomberEntityBase(Speed, Weight, BodyColor);
|
||||
}
|
||||
|
||||
public BomberRendererBase(int Speed, double Weight, Color BodyColor, int Width, int Height, int EntityWidth, int EntityHeight)
|
||||
{
|
||||
if (Width < _bomberWidth || Height < _bomberHeight)
|
||||
return;
|
||||
|
||||
_pictureWidth = Width;
|
||||
_pictureHeight = Height;
|
||||
|
||||
_bomberWidth = EntityWidth;
|
||||
_bomberHeight = EntityHeight;
|
||||
|
||||
EntityBomber = new BomberEntityBase(Speed, Weight, BodyColor);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (EntityBomber is null)
|
||||
return;
|
||||
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
else if (x + _bomberWidth > _pictureWidth)
|
||||
x = _pictureWidth - _bomberWidth;
|
||||
|
||||
_startPosX = x;
|
||||
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
else if (y + _bomberHeight > _pictureHeight)
|
||||
y = _pictureHeight - _bomberHeight;
|
||||
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityBomber is null)
|
||||
return false;
|
||||
|
||||
return direction switch
|
||||
{
|
||||
DirectionType.Left => _startPosX - EntityBomber.Step > 0,
|
||||
DirectionType.Up => _startPosY - EntityBomber.Step > 0,
|
||||
DirectionType.Right => _startPosX + _bomberWidth + EntityBomber.Step <= _pictureWidth,
|
||||
DirectionType.Down => _startPosY + _bomberHeight + EntityBomber.Step <= _pictureHeight,
|
||||
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
public void MoveEntity(DirectionType Direction)
|
||||
{
|
||||
if (EntityBomber == null || !CanMove(Direction))
|
||||
return;
|
||||
|
||||
switch (Direction)
|
||||
{
|
||||
case DirectionType.Left:
|
||||
_startPosX -= (int)EntityBomber.Step;
|
||||
break;
|
||||
|
||||
case DirectionType.Up:
|
||||
_startPosY -= (int)EntityBomber.Step;
|
||||
break;
|
||||
|
||||
case DirectionType.Right:
|
||||
_startPosX += (int)EntityBomber.Step;
|
||||
break;
|
||||
|
||||
case DirectionType.Down:
|
||||
_startPosY += (int)EntityBomber.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawEntity(Graphics g)
|
||||
{
|
||||
if (EntityBomber == null)
|
||||
return;
|
||||
|
||||
Pen Pen = new Pen(EntityBomber.BodyColor);
|
||||
Brush Brush = new SolidBrush(EntityBomber.BodyColor);
|
||||
|
||||
/** Отрисовка основной части */
|
||||
Point[] LeftWing = {
|
||||
new Point(_startPosX + 90, _startPosY),
|
||||
new Point(_startPosX + 100, _startPosY),
|
||||
new Point(_startPosX + 108, _startPosY + 85),
|
||||
new Point(_startPosX + 90, _startPosY + 85),
|
||||
};
|
||||
g.DrawPolygon(Pen, LeftWing);
|
||||
|
||||
Point[] RightWing = {
|
||||
new Point(_startPosX + 90, _startPosY + 200),
|
||||
new Point(_startPosX + 100, _startPosY + 200),
|
||||
new Point(_startPosX + 108, _startPosY + 115),
|
||||
new Point(_startPosX + 90, _startPosY + 115),
|
||||
};
|
||||
g.DrawPolygon(Pen, RightWing);
|
||||
|
||||
Point[] Body = {
|
||||
new Point(_startPosX + 35, _startPosY + 85),
|
||||
new Point(_startPosX + 200, _startPosY + 85),
|
||||
new Point(_startPosX + 200, _startPosY + 115),
|
||||
new Point(_startPosX + 35, _startPosY + 115),
|
||||
};
|
||||
g.DrawPolygon(Pen, Body);
|
||||
|
||||
Point[] Nose = {
|
||||
new Point(_startPosX, _startPosY + 100),
|
||||
new Point(_startPosX + 35, _startPosY + 85),
|
||||
new Point(_startPosX + 35, _startPosY + 115),
|
||||
};
|
||||
g.FillPolygon(Brush, Nose);
|
||||
|
||||
Point[] BackLeftWing = {
|
||||
new Point(_startPosX + 170, _startPosY + 70),
|
||||
new Point(_startPosX + 200, _startPosY + 40),
|
||||
new Point(_startPosX + 200, _startPosY + 85),
|
||||
new Point(_startPosX + 170, _startPosY + 85),
|
||||
};
|
||||
g.DrawPolygon(Pen, BackLeftWing);
|
||||
|
||||
Point[] BackRightWing = {
|
||||
new Point(_startPosX + 170, _startPosY + 130),
|
||||
new Point(_startPosX + 200, _startPosY + 160),
|
||||
new Point(_startPosX + 200, _startPosY + 115),
|
||||
new Point(_startPosX + 170, _startPosY + 115),
|
||||
};
|
||||
g.DrawPolygon(Pen, BackRightWing);
|
||||
}
|
||||
}
|
||||
}
|
BIN
AirBomber/Resources/ArrowDown.png
Normal file
BIN
AirBomber/Resources/ArrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 418 B |
BIN
AirBomber/Resources/ArrowLeft.png
Normal file
BIN
AirBomber/Resources/ArrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 362 B |
BIN
AirBomber/Resources/ArrowRight.png
Normal file
BIN
AirBomber/Resources/ArrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 428 B |
BIN
AirBomber/Resources/ArrowUp.png
Normal file
BIN
AirBomber/Resources/ArrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 412 B |
Loading…
Reference in New Issue
Block a user