Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 253a47e5e7 | |||
| 64abc50ba4 |
75
AirBomber/AbstractStrategy.cs
Normal file
75
AirBomber/AbstractStrategy.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.DrawningObjects;
|
||||
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
private IMoveableObject? _moveableObject;
|
||||
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(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
protected bool MoveLeft() => MoveTo(Diraction.Left);
|
||||
protected bool MoveRight() => MoveTo(Diraction.Right);
|
||||
protected bool MoveUp() => MoveTo(Diraction.Up);
|
||||
protected bool MoveDown() => MoveTo(Diraction.Down);
|
||||
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosit;
|
||||
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
|
||||
protected abstract void MoveToTarget();
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
|
||||
private bool MoveTo(Diraction directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
107
AirBomber/BomberGenericCollection.cs
Normal file
107
AirBomber/BomberGenericCollection.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.DrawningObjects;
|
||||
using AirBomber.MovementStrategy;
|
||||
using ProjectBomber.Generics;
|
||||
|
||||
|
||||
namespace AirBomber.Generics
|
||||
{
|
||||
internal class BomberGenericCollection<T, U>
|
||||
where T : DrawningBomber
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 155;
|
||||
private readonly int _placeSizeHeight = 185;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
public BomberGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
public static int operator +(BomberGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
|
||||
public static bool operator -(BomberGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T obj = collect._collection.Get(pos);
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
|
||||
public Bitmap ShowBomber()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black, 3);
|
||||
int numColumns = _pictureWidth / _placeSizeWidth;
|
||||
int numRows = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i <= numColumns; i++)
|
||||
{
|
||||
for (int j = 0; j <= numRows; ++j)
|
||||
{
|
||||
int x = i * _placeSizeWidth;
|
||||
int y = j * _placeSizeHeight;
|
||||
g.DrawLine(pen, x, y, x + _placeSizeWidth / 2, y);
|
||||
}
|
||||
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, numRows * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int numColumns = _pictureWidth / _placeSizeWidth;
|
||||
int numRows = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawningBomber air = _collection.Get(i);
|
||||
if (air != null)
|
||||
{
|
||||
int row = i / numColumns;
|
||||
int column = numColumns - 1 - (i % numColumns);
|
||||
int x = column * _placeSizeWidth;
|
||||
int y = row * _placeSizeHeight;
|
||||
|
||||
air.SetPosition(x, y);
|
||||
air.DrawBomber(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,113 +4,30 @@ using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.Entities;
|
||||
|
||||
namespace AirBomber
|
||||
namespace AirBomber.DrawningObjects
|
||||
{
|
||||
public class DrawningAirBomber
|
||||
public class DrawningAirBomber : DrawningBomber
|
||||
{
|
||||
public EntityAirBomber? EntityAirBomber { get; private set; }
|
||||
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
private int _PlaneWidth = 160;
|
||||
private int _PlaneHeight = 185;
|
||||
|
||||
public bool Init(int speed, int weight, Color bodycolor, Color dopcolor, bool toplivo, bool rocket, int width, int height)
|
||||
public DrawningAirBomber(int speed, int weight, Color bodycolor, Color dopcolor, bool toplivo, bool rocket, int width, int height) : base(speed, weight, bodycolor, width, height, 160, 185)
|
||||
{
|
||||
if (width < _pictureWidth || height < _pictureHeight)
|
||||
if (EntityBomber != null)
|
||||
{
|
||||
return false;
|
||||
EntityBomber = new EntityAirBomber(speed, weight, bodycolor, dopcolor, toplivo, rocket);
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityAirBomber = new EntityAirBomber();
|
||||
EntityAirBomber.Init(speed, weight, bodycolor, dopcolor, toplivo, rocket);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
public override void DrawBomber(Graphics g)
|
||||
{
|
||||
if (x < 0 || x + _PlaneWidth > _pictureWidth)
|
||||
{
|
||||
x = _pictureWidth - _PlaneWidth;
|
||||
}
|
||||
if (y < 0 || y + _PlaneWidth > _pictureHeight)
|
||||
{
|
||||
y = _pictureHeight - _PlaneWidth;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public void MoveTransport(Diraction diraction)
|
||||
{
|
||||
if (EntityAirBomber == null)
|
||||
if (EntityBomber is not EntityAirBomber airBomber)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int step = (int)EntityAirBomber.Step;
|
||||
|
||||
switch (diraction)
|
||||
{
|
||||
case Diraction.Left:
|
||||
if (_startPosX - step >= 0)
|
||||
{
|
||||
_startPosX -= step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
break;
|
||||
case Diraction.Right:
|
||||
if (_startPosX + step + _PlaneWidth <= _pictureWidth)
|
||||
{
|
||||
_startPosX += step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = _pictureWidth - _PlaneWidth;
|
||||
}
|
||||
break;
|
||||
case Diraction.Up:
|
||||
if (_startPosY - step >= 0)
|
||||
{
|
||||
_startPosY -= step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
break;
|
||||
case Diraction.Down:
|
||||
if (_startPosY + step + _PlaneHeight <= _pictureHeight)
|
||||
{
|
||||
_startPosY += step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = _pictureHeight - _PlaneHeight;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawCar(Graphics g)
|
||||
{
|
||||
if (EntityAirBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopcolor = new SolidBrush(EntityAirBomber.DopColor);
|
||||
if (EntityAirBomber.Toplivo)
|
||||
Brush dopcolor = new SolidBrush(airBomber.DopColor);
|
||||
//отрисовка ракет
|
||||
if (airBomber.Rocket)
|
||||
{
|
||||
//отрисовка ракет
|
||||
GraphicsPath rocket_1 = new GraphicsPath();
|
||||
rocket_1.AddLine(_startPosX + 70, _startPosY + 35, _startPosX + 80, _startPosY + 25);
|
||||
rocket_1.AddLine(_startPosX + 80, _startPosY + 25, _startPosX + 80, _startPosY + 45);
|
||||
@@ -136,7 +53,8 @@ namespace AirBomber
|
||||
g.FillPath(dopcolor, rocket_4);
|
||||
g.DrawPath(Pens.Black, rocket_4);
|
||||
}
|
||||
if (EntityAirBomber.Rocket) {
|
||||
if (airBomber.Toplivo)
|
||||
{
|
||||
//отрисовка баков
|
||||
g.FillRectangle(dopcolor, _startPosX + 82, _startPosY + 5, 8, 10);
|
||||
g.FillRectangle(dopcolor, _startPosX + 82, _startPosY + 25, 8, 10);
|
||||
@@ -145,42 +63,7 @@ namespace AirBomber
|
||||
g.FillRectangle(dopcolor, _startPosX + 82, _startPosY + 150, 8, 10);
|
||||
g.FillRectangle(dopcolor, _startPosX + 82, _startPosY + 170, 8, 10);
|
||||
}
|
||||
//отрисовка крыла 1
|
||||
GraphicsPath fly_1 = new GraphicsPath();
|
||||
fly_1.AddLine(_startPosX + 80, _startPosY + 2, _startPosX + 80, _startPosY + 80);
|
||||
fly_1.AddLine(_startPosX + 80, _startPosY + 2, _startPosX + 90, _startPosY + 2);
|
||||
fly_1.AddLine(_startPosX + 90, _startPosY + 2, _startPosX + 100, _startPosY + 80);
|
||||
fly_1.AddLine(_startPosX + 100, _startPosY + 80, _startPosX + 80, _startPosY + 80);
|
||||
g.DrawPath(Pens.Black, fly_1);
|
||||
//отрисовка кабины пилота
|
||||
GraphicsPath treygol = new GraphicsPath();
|
||||
treygol.AddLine(_startPosX + 3, _startPosY + 95, _startPosX + 30, _startPosY + 80);
|
||||
treygol.AddLine(_startPosX + 30, _startPosY + 80, _startPosX + 30, _startPosY + 105);
|
||||
treygol.CloseFigure();
|
||||
g.FillPath(Brushes.Black, treygol);
|
||||
g.DrawPath(Pens.Black, treygol);
|
||||
//отрисовка корпуса
|
||||
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 80, 120, 25);
|
||||
//отрисовка крыла 2
|
||||
GraphicsPath fly_2 = new GraphicsPath();
|
||||
fly_2.AddLine(_startPosX + 80, _startPosY + 105, _startPosX + 80, _startPosY + 185);
|
||||
fly_2.AddLine(_startPosX + 80, _startPosY + 185, _startPosX + 90, _startPosY + 185);
|
||||
fly_2.AddLine(_startPosX + 90, _startPosY + 185, _startPosX + 100, _startPosY + 105);
|
||||
fly_2.CloseFigure();
|
||||
g.DrawPath(Pens.Black, fly_2);
|
||||
//отриосвка хвоста
|
||||
GraphicsPath wing = new GraphicsPath();
|
||||
wing.AddLine(_startPosX + 135, _startPosY + 80, _startPosX + 135, _startPosY + 70);
|
||||
wing.AddLine(_startPosX + 135, _startPosY + 70, _startPosX + 150, _startPosY + 50);
|
||||
wing.AddLine(_startPosX + 150, _startPosY + 50, _startPosX + 150, _startPosY + 80);
|
||||
wing.CloseFigure();
|
||||
g.DrawPath(Pens.Black, wing);
|
||||
GraphicsPath wing_2 = new GraphicsPath();
|
||||
wing_2.AddLine(_startPosX + 135, _startPosY + 105, _startPosX + 135, _startPosY + 115);
|
||||
wing_2.AddLine(_startPosX + 135, _startPosY + 115, _startPosX + 150, _startPosY + 135);
|
||||
wing_2.AddLine(_startPosX + 150, _startPosY + 135, _startPosX + 150, _startPosY + 105);
|
||||
wing_2.CloseFigure();
|
||||
g.DrawPath(Pens.Black, wing_2);
|
||||
base.DrawBomber(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
165
AirBomber/DrawningBomber.cs
Normal file
165
AirBomber/DrawningBomber.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.Entities;
|
||||
using AirBomber.MovementStrategy;
|
||||
|
||||
namespace AirBomber.DrawningObjects
|
||||
{
|
||||
public class DrawningBomber
|
||||
{
|
||||
public EntityBomber? EntityBomber { get; protected set; }
|
||||
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
protected int _PlaneWidth = 160;
|
||||
protected int _PlaneHeight = 185;
|
||||
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _PlaneWidth;
|
||||
public int GetHeight => _PlaneHeight;
|
||||
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectBomber(this);
|
||||
|
||||
public DrawningBomber(int speed, double weight, Color bodycolor, int width, int height)
|
||||
{
|
||||
if (width < _pictureWidth || height < _pictureHeight)
|
||||
{
|
||||
throw new InvalidOperationException("Invalid weight or height");
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityBomber = new EntityBomber(speed, weight, bodycolor);
|
||||
}
|
||||
|
||||
protected DrawningBomber(int speed, double weight, Color bodycolor, int width, int height, int planeWidth, int planeHeight)
|
||||
{
|
||||
if (width < _pictureWidth || height < _pictureHeight)
|
||||
{
|
||||
throw new InvalidOperationException("Invalid width or height");
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_PlaneWidth = planeWidth;
|
||||
_PlaneHeight = planeHeight;
|
||||
EntityBomber = new EntityBomber(speed, weight, bodycolor);
|
||||
}
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x + _PlaneWidth > _pictureWidth)
|
||||
{
|
||||
x = _pictureWidth - _PlaneWidth;
|
||||
}
|
||||
if (y < 0 || y + _PlaneWidth > _pictureHeight)
|
||||
{
|
||||
y = _pictureHeight - _PlaneWidth;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public bool CanMove(Diraction direction)
|
||||
{
|
||||
if (EntityBomber == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int newPosX = _startPosX;
|
||||
int newPosY = _startPosY;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case Diraction.Left:
|
||||
newPosX -= (int)EntityBomber.Step;
|
||||
break;
|
||||
case Diraction.Right:
|
||||
newPosX += (int)EntityBomber.Step;
|
||||
break;
|
||||
case Diraction.Up:
|
||||
newPosY -= (int)EntityBomber.Step;
|
||||
break;
|
||||
case Diraction.Down:
|
||||
newPosY += (int)EntityBomber.Step;
|
||||
break;
|
||||
}
|
||||
|
||||
return newPosX >= 0 && newPosX <= _pictureWidth - _PlaneWidth &&
|
||||
newPosY >= 0 && newPosY <= _pictureHeight - _PlaneHeight;
|
||||
}
|
||||
|
||||
public void MoveTransport(Diraction diraction)
|
||||
{
|
||||
if (!CanMove(diraction) || EntityBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (diraction)
|
||||
{
|
||||
case Diraction.Left:
|
||||
_startPosX -= (int)EntityBomber.Step;
|
||||
break;
|
||||
case Diraction.Right:
|
||||
_startPosX += (int)EntityBomber.Step;
|
||||
break;
|
||||
case Diraction.Up:
|
||||
_startPosY -= (int)EntityBomber.Step;
|
||||
break;
|
||||
case Diraction.Down:
|
||||
_startPosY += (int)EntityBomber.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public virtual void DrawBomber(Graphics g)
|
||||
{
|
||||
if (EntityBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
//отрисовка крыла 1
|
||||
GraphicsPath fly_1 = new GraphicsPath();
|
||||
fly_1.AddLine(_startPosX + 80, _startPosY + 2, _startPosX + 80, _startPosY + 80);
|
||||
fly_1.AddLine(_startPosX + 80, _startPosY + 2, _startPosX + 90, _startPosY + 2);
|
||||
fly_1.AddLine(_startPosX + 90, _startPosY + 2, _startPosX + 100, _startPosY + 80);
|
||||
fly_1.AddLine(_startPosX + 100, _startPosY + 80, _startPosX + 80, _startPosY + 80);
|
||||
g.DrawPath(Pens.Black, fly_1);
|
||||
//отрисовка кабины пилота
|
||||
GraphicsPath treygol = new GraphicsPath();
|
||||
treygol.AddLine(_startPosX + 3, _startPosY + 95, _startPosX + 30, _startPosY + 80);
|
||||
treygol.AddLine(_startPosX + 30, _startPosY + 80, _startPosX + 30, _startPosY + 105);
|
||||
treygol.CloseFigure();
|
||||
g.FillPath(Brushes.Black, treygol);
|
||||
g.DrawPath(Pens.Black, treygol);
|
||||
//отрисовка корпуса
|
||||
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 80, 120, 25);
|
||||
//отрисовка крыла 2
|
||||
GraphicsPath fly_2 = new GraphicsPath();
|
||||
fly_2.AddLine(_startPosX + 80, _startPosY + 105, _startPosX + 80, _startPosY + 185);
|
||||
fly_2.AddLine(_startPosX + 80, _startPosY + 185, _startPosX + 90, _startPosY + 185);
|
||||
fly_2.AddLine(_startPosX + 90, _startPosY + 185, _startPosX + 100, _startPosY + 105);
|
||||
fly_2.CloseFigure();
|
||||
g.DrawPath(Pens.Black, fly_2);
|
||||
//отриосвка хвоста
|
||||
GraphicsPath wing = new GraphicsPath();
|
||||
wing.AddLine(_startPosX + 135, _startPosY + 80, _startPosX + 135, _startPosY + 70);
|
||||
wing.AddLine(_startPosX + 135, _startPosY + 70, _startPosX + 150, _startPosY + 50);
|
||||
wing.AddLine(_startPosX + 150, _startPosY + 50, _startPosX + 150, _startPosY + 80);
|
||||
wing.CloseFigure();
|
||||
g.DrawPath(Pens.Black, wing);
|
||||
GraphicsPath wing_2 = new GraphicsPath();
|
||||
wing_2.AddLine(_startPosX + 135, _startPosY + 105, _startPosX + 135, _startPosY + 115);
|
||||
wing_2.AddLine(_startPosX + 135, _startPosY + 115, _startPosX + 150, _startPosY + 135);
|
||||
wing_2.AddLine(_startPosX + 150, _startPosY + 135, _startPosX + 150, _startPosY + 105);
|
||||
wing_2.CloseFigure();
|
||||
g.DrawPath(Pens.Black, wing_2);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
AirBomber/DrawningObjectBomber .cs
Normal file
33
AirBomber/DrawningObjectBomber .cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.DrawningObjects;
|
||||
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public class DrawningObjectBomber : IMoveableObject
|
||||
{
|
||||
private readonly DrawningBomber? _drawningBomber = null;
|
||||
|
||||
public DrawningObjectBomber(DrawningBomber drawningBomber)
|
||||
{
|
||||
_drawningBomber = drawningBomber;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosit
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningBomber == null || _drawningBomber.EntityBomber == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningBomber.GetPosX, _drawningBomber.GetPosY, _drawningBomber.GetWidth, _drawningBomber.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningBomber?.EntityBomber?.Step ?? 0);
|
||||
public bool CheckCanMove(Diraction direction) => _drawningBomber?.CanMove(direction) ?? false;
|
||||
public void MoveObject(Diraction direction) => _drawningBomber?.MoveTransport(direction);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
namespace AirBomber.Entities
|
||||
{
|
||||
public class EntityAirBomber
|
||||
public class EntityAirBomber : EntityBomber
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public int Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public Color DopColor { get; private set; }
|
||||
public bool Toplivo { get; private set; }
|
||||
public bool Rocket { get; private set; }
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
|
||||
public void Init(int speed, int weight, Color bodycolor, Color dopcolor, bool toplivo, bool ropcket)
|
||||
public EntityAirBomber(int speed, double weight, Color bodycolor, Color dopcolor, bool toplivo, bool ropcket) : base(speed, weight, bodycolor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodycolor;
|
||||
DopColor = dopcolor;
|
||||
Toplivo = toplivo;
|
||||
Rocket = ropcket;
|
||||
|
||||
23
AirBomber/EntityBomber.cs
Normal file
23
AirBomber/EntityBomber.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber.Entities
|
||||
{
|
||||
public class EntityBomber
|
||||
{
|
||||
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;
|
||||
|
||||
public EntityBomber(int speed, double weight, Color bodycolor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodycolor;
|
||||
}
|
||||
}
|
||||
}
|
||||
58
AirBomber/FormAirBomber.Designer.cs
generated
58
AirBomber/FormAirBomber.Designer.cs
generated
@@ -34,6 +34,10 @@
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreate = new Button();
|
||||
buttonCreateWarBomber = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
ButtonStep = new Button();
|
||||
ButtonSelectCar = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@@ -97,19 +101,63 @@
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(30, 395);
|
||||
buttonCreate.Location = new Point(223, 385);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(131, 43);
|
||||
buttonCreate.Size = new Size(181, 59);
|
||||
buttonCreate.TabIndex = 6;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.Text = "Создать самолёт";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonCreateWarBomber
|
||||
//
|
||||
buttonCreateWarBomber.Location = new Point(12, 385);
|
||||
buttonCreateWarBomber.Name = "buttonCreateWarBomber";
|
||||
buttonCreateWarBomber.Size = new Size(205, 59);
|
||||
buttonCreateWarBomber.TabIndex = 7;
|
||||
buttonCreateWarBomber.Text = "Создать военный самолёт";
|
||||
buttonCreateWarBomber.UseVisualStyleBackColor = true;
|
||||
buttonCreateWarBomber.Click += buttonCreateWarBomber_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "В центр", "В правый нижний угол" });
|
||||
comboBoxStrategy.Location = new Point(637, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(151, 28);
|
||||
comboBoxStrategy.TabIndex = 8;
|
||||
//
|
||||
// ButtonStep
|
||||
//
|
||||
ButtonStep.Location = new Point(694, 60);
|
||||
ButtonStep.Name = "ButtonStep";
|
||||
ButtonStep.Size = new Size(94, 29);
|
||||
ButtonStep.TabIndex = 9;
|
||||
ButtonStep.Text = "Шаг";
|
||||
ButtonStep.UseVisualStyleBackColor = true;
|
||||
ButtonStep.Click += ButtonStep_Click;
|
||||
//
|
||||
// ButtonSelectCar
|
||||
//
|
||||
ButtonSelectCar.Location = new Point(420, 391);
|
||||
ButtonSelectCar.Name = "ButtonSelectCar";
|
||||
ButtonSelectCar.Size = new Size(118, 53);
|
||||
ButtonSelectCar.TabIndex = 10;
|
||||
ButtonSelectCar.Text = "Выбрать";
|
||||
ButtonSelectCar.UseVisualStyleBackColor = true;
|
||||
ButtonSelectCar.Click += ButtonSelectCar_Click;
|
||||
//
|
||||
// FormAirBomber
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(ButtonSelectCar);
|
||||
Controls.Add(ButtonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateWarBomber);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
@@ -130,5 +178,9 @@
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreateWarBomber;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button ButtonStep;
|
||||
private Button ButtonSelectCar;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
using AirBomber.DrawningObjects;
|
||||
using AirBomber.MovementStrategy;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
public partial class FormAirBomber : Form
|
||||
{
|
||||
private DrawningAirBomber? _drawingair;
|
||||
private DrawningBomber? _drawningBomber;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawningBomber? SelectedBomber { get; private set; }
|
||||
|
||||
public FormAirBomber()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -10,37 +16,35 @@ namespace AirBomber
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
|
||||
if (_drawingair == null)
|
||||
if (_drawningBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBox.Width,
|
||||
pictureBox.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingair.DrawCar(gr);
|
||||
_drawningBomber.DrawBomber(gr);
|
||||
pictureBox.Image = bmp;
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingair = new DrawningAirBomber();
|
||||
_drawingair.Init(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)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBox.Width, pictureBox.Height);
|
||||
_drawingair.SetPosition(random.Next(10, 100),
|
||||
random.Next(10, 100));
|
||||
Color bodycolor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog mainColorDialog = new ColorDialog();
|
||||
if (mainColorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodycolor = mainColorDialog.Color;
|
||||
}
|
||||
_drawningBomber = new DrawningBomber(random.Next(100, 300), random.Next(1000, 3000), bodycolor,
|
||||
pictureBox.Width, pictureBox.Height);
|
||||
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingair == null)
|
||||
if (_drawningBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -48,19 +52,85 @@ namespace AirBomber
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingair.MoveTransport(Diraction.Up);
|
||||
_drawningBomber.MoveTransport(Diraction.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingair.MoveTransport(Diraction.Down);
|
||||
_drawningBomber.MoveTransport(Diraction.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingair.MoveTransport(Diraction.Left);
|
||||
_drawningBomber.MoveTransport(Diraction.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingair.MoveTransport(Diraction.Right);
|
||||
_drawningBomber.MoveTransport(Diraction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBottomRight(),
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawningObjectBomber(_drawningBomber), pictureBox.Width,
|
||||
pictureBox.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCreateWarBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
Color bodycolor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog mainColorDialog = new ColorDialog();
|
||||
if (mainColorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodycolor = mainColorDialog.Color;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dopColorDialog = new ColorDialog();
|
||||
if (dopColorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dopColorDialog.Color;
|
||||
}
|
||||
|
||||
_drawningBomber = new DrawningAirBomber(random.Next(100, 300),
|
||||
random.Next(1000, 3000), bodycolor, dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(1, 2)),
|
||||
pictureBox.Width, pictureBox.Height);
|
||||
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonSelectCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedBomber = _drawningBomber;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
123
AirBomber/FormBomberCollection.Designer.cs
generated
Normal file
123
AirBomber/FormBomberCollection.Designer.cs
generated
Normal file
@@ -0,0 +1,123 @@
|
||||
namespace AirBomber
|
||||
{
|
||||
partial class FormBomberCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
Tools = new GroupBox();
|
||||
ButtonRefreshCollection = new Button();
|
||||
ButtonRemoveBomber = new Button();
|
||||
ButtonAddBomber = new Button();
|
||||
MessageBoxBomber = new TextBox();
|
||||
PicBoxBomberCollection = new PictureBox();
|
||||
Tools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)PicBoxBomberCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// Tools
|
||||
//
|
||||
Tools.Controls.Add(ButtonRefreshCollection);
|
||||
Tools.Controls.Add(ButtonRemoveBomber);
|
||||
Tools.Controls.Add(ButtonAddBomber);
|
||||
Tools.Controls.Add(MessageBoxBomber);
|
||||
Tools.Location = new Point(538, 5);
|
||||
Tools.Name = "Tools";
|
||||
Tools.Size = new Size(250, 443);
|
||||
Tools.TabIndex = 0;
|
||||
Tools.TabStop = false;
|
||||
Tools.Text = "Инструменты";
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Location = new Point(25, 243);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new Size(193, 37);
|
||||
ButtonRefreshCollection.TabIndex = 3;
|
||||
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// ButtonRemoveBomber
|
||||
//
|
||||
ButtonRemoveBomber.Location = new Point(25, 178);
|
||||
ButtonRemoveBomber.Name = "ButtonRemoveBomber";
|
||||
ButtonRemoveBomber.Size = new Size(193, 41);
|
||||
ButtonRemoveBomber.TabIndex = 2;
|
||||
ButtonRemoveBomber.Text = "Удалить самолёт";
|
||||
ButtonRemoveBomber.UseVisualStyleBackColor = true;
|
||||
ButtonRemoveBomber.Click += ButtonRemoveBomber_Click;
|
||||
//
|
||||
// ButtonAddBomber
|
||||
//
|
||||
ButtonAddBomber.Location = new Point(25, 42);
|
||||
ButtonAddBomber.Name = "ButtonAddBomber";
|
||||
ButtonAddBomber.Size = new Size(193, 41);
|
||||
ButtonAddBomber.TabIndex = 1;
|
||||
ButtonAddBomber.Text = "Добавить самолёт";
|
||||
ButtonAddBomber.UseVisualStyleBackColor = true;
|
||||
ButtonAddBomber.Click += ButtonAddBomber_Click;
|
||||
//
|
||||
// MessageBoxBomber
|
||||
//
|
||||
MessageBoxBomber.Location = new Point(25, 109);
|
||||
MessageBoxBomber.Name = "MessageBoxBomber";
|
||||
MessageBoxBomber.Size = new Size(193, 27);
|
||||
MessageBoxBomber.TabIndex = 0;
|
||||
//
|
||||
// PicBoxBomberCollection
|
||||
//
|
||||
PicBoxBomberCollection.Location = new Point(1, -2);
|
||||
PicBoxBomberCollection.Name = "PicBoxBomberCollection";
|
||||
PicBoxBomberCollection.Size = new Size(473, 563);
|
||||
PicBoxBomberCollection.TabIndex = 1;
|
||||
PicBoxBomberCollection.TabStop = false;
|
||||
//
|
||||
// FormBomberCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 581);
|
||||
Controls.Add(PicBoxBomberCollection);
|
||||
Controls.Add(Tools);
|
||||
Name = "FormBomberCollection";
|
||||
Text = "FormBomberCollection";
|
||||
Tools.ResumeLayout(false);
|
||||
Tools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)PicBoxBomberCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox Tools;
|
||||
private TextBox MessageBoxBomber;
|
||||
private PictureBox PicBoxBomberCollection;
|
||||
private Button ButtonRefreshCollection;
|
||||
private Button ButtonRemoveBomber;
|
||||
private Button ButtonAddBomber;
|
||||
}
|
||||
}
|
||||
66
AirBomber/FormBomberCollection.cs
Normal file
66
AirBomber/FormBomberCollection.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using AirBomber.DrawningObjects;
|
||||
using AirBomber.Generics;
|
||||
using AirBomber.MovementStrategy;
|
||||
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 AirBomber
|
||||
{
|
||||
public partial class FormBomberCollection : Form
|
||||
{
|
||||
private readonly BomberGenericCollection<DrawningBomber, DrawningObjectBomber> _bomber;
|
||||
|
||||
public FormBomberCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_bomber = new BomberGenericCollection<DrawningBomber, DrawningObjectBomber>(PicBoxBomberCollection.Width, PicBoxBomberCollection.Height);
|
||||
}
|
||||
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
PicBoxBomberCollection.Image = _bomber.ShowBomber();
|
||||
}
|
||||
|
||||
private void ButtonAddBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormAirBomber form = new FormAirBomber();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_bomber + form.SelectedBomber != 1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
PicBoxBomberCollection.Image = _bomber.ShowBomber();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemoveBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(MessageBoxBomber.Text);
|
||||
if (_bomber - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
PicBoxBomberCollection.Image = _bomber.ShowBomber();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
AirBomber/FormBomberCollection.resx
Normal file
120
AirBomber/FormBomberCollection.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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>
|
||||
</root>
|
||||
18
AirBomber/IMoveableObject.cs
Normal file
18
AirBomber/IMoveableObject.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.DrawningObjects;
|
||||
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public interface IMoveableObject
|
||||
{
|
||||
ObjectParameters? GetObjectPosit { get; }
|
||||
|
||||
int GetStep { get; }
|
||||
bool CheckCanMove(Diraction direction);
|
||||
void MoveObject(Diraction direction);
|
||||
}
|
||||
}
|
||||
48
AirBomber/MoveToBottomRight .cs
Normal file
48
AirBomber/MoveToBottomRight .cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.MovementStrategy;
|
||||
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public class MoveToBottomRight : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder - FieldWidth;
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
if (diffX >= 0)
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
else if (diffY >= 0)
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
else if (Math.Abs(diffX) > Math.Abs(diffY))
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
AirBomber/MoveToCenter.cs
Normal file
55
AirBomber/MoveToCenter.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.MovementStrategy;
|
||||
|
||||
namespace AirBomber.MovementStrategy
|
||||
{
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
AirBomber/ObjectParameters.cs
Normal file
29
AirBomber/ObjectParameters.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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 DownBorder => _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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace AirBomber
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormAirBomber());
|
||||
Application.Run(new FormBomberCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
105
AirBomber/SetGeneric.cs
Normal file
105
AirBomber/SetGeneric.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="plane">Добавляемая установка</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane)
|
||||
{
|
||||
return Insert(plane, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="plane">Добавляемая установка</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 && position > Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int d = 0;
|
||||
for (int j = 1; j < Count - position; j++)
|
||||
{
|
||||
if (_places[position + j] == null)
|
||||
{
|
||||
d = position + j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (d == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int j = d; j > position; j--)
|
||||
{
|
||||
_places[j] = _places[j - 1];
|
||||
}
|
||||
}
|
||||
_places[position] = plane;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
/// Проверка позиции
|
||||
if (position < 0 || position >= _places.Length)
|
||||
return false;
|
||||
/// Удаление объекта из массива, присвоив элементу массива значение null
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= _places.Length)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
||||
15
AirBomber/Status.cs
Normal file
15
AirBomber/Status.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user