ISE_22.Aparyan.Bulldozer.Base Lab03 #3
@ -1,6 +1,4 @@
|
||||
|
||||
|
||||
namespace ProjectBulldozer
|
||||
namespace ProjectBulldozer
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
||||
|
@ -11,9 +11,7 @@ namespace ProjectBulldozer.Drawning
|
||||
EntityTractor = new EntityBulldozer(speed, width, bodyColor, additionalColor, horns, seifBatteries);
|
||||
}
|
||||
}
|
||||
|
||||
public object Otval { get; private set; }
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTractor is not EntityBulldozer Bulldozer)
|
||||
@ -22,48 +20,28 @@ namespace ProjectBulldozer.Drawning
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
|
||||
Brush blackBrush = new SolidBrush(Color.Black);
|
||||
Brush windows = new SolidBrush(Color.LightBlue);
|
||||
Brush bodyColor = new SolidBrush(Bulldozer.BodyColor);
|
||||
|
||||
Brush additionalColor = new SolidBrush(Bulldozer.AdditionalColor);
|
||||
|
||||
Brush grayBrush = new SolidBrush(Color.Gray);
|
||||
|
||||
//otval
|
||||
Point[] Otval =
|
||||
{
|
||||
new Point(_startPosX + 118, _startPosY + 50),
|
||||
new Point(_startPosX + 148, _startPosY + 111),
|
||||
new Point(_startPosX+ 118, _startPosY + 111),
|
||||
|
||||
|
||||
};
|
||||
|
||||
g.FillPolygon(additionalColor, Otval);
|
||||
g.DrawPolygon(pen, Otval);
|
||||
|
||||
|
||||
|
||||
//гусеницы
|
||||
Brush gg = new SolidBrush(Color.LightGray);
|
||||
g.FillEllipse(gg, _startPosX + 16, _startPosY + 65, 101, 63);
|
||||
g.DrawEllipse(pen, _startPosX + 16, _startPosY + 65, 101, 63);
|
||||
|
||||
|
||||
|
||||
|
||||
g.FillEllipse(grayBrush, _startPosX + 65, _startPosY + 100, 13, 13);
|
||||
g.DrawEllipse(pen, _startPosX + 65, _startPosY + 100, 13, 13);
|
||||
|
||||
|
||||
|
||||
|
||||
Point[] Ttt =
|
||||
{
|
||||
|
||||
new Point(_startPosX + 16, _startPosY + 79),
|
||||
new Point(_startPosX + 16, _startPosY + 120),
|
||||
new Point(_startPosX, _startPosY + 48),
|
||||
@ -71,9 +49,6 @@ namespace ProjectBulldozer.Drawning
|
||||
};
|
||||
g.FillPolygon(blackBrush, Ttt);
|
||||
g.DrawPolygon(pen, Ttt);
|
||||
|
||||
|
||||
|
||||
if (Bulldozer.SeifBatteries)
|
||||
{
|
||||
g.FillRectangle(blackBrush, _startPosX + 110, _startPosY + 60, 5, 10);
|
||||
|
@ -1,31 +1,21 @@
|
||||
|
||||
using Bulldozer;
|
||||
using ProjectBulldozer.Entities;
|
||||
using ProjectBulldozer.Entities;
|
||||
using ProjectBulldozer.MovementStrategy;
|
||||
|
||||
|
||||
namespace ProjectBulldozer.Drawning
|
||||
{
|
||||
public class DrawingTractor
|
||||
{
|
||||
public EntityTractor? EntityTractor { get; protected set; }
|
||||
|
||||
protected int _pictureWidth;
|
||||
|
||||
protected int _pictureHeight;
|
||||
|
||||
protected int _startPosX;
|
||||
|
||||
protected int _startPosY;
|
||||
|
||||
protected readonly int _tractWidth = 120;
|
||||
|
||||
protected readonly int _tractHeight = 110;
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _tractWidth;
|
||||
public int GetHeight => _tractHeight;
|
||||
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectTractor(this);
|
||||
public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth)
|
||||
{
|
||||
@ -37,7 +27,6 @@ namespace ProjectBulldozer.Drawning
|
||||
_pictureHeight = heigth;
|
||||
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
protected DrawingTractor(int speed, double weight, Color bodyColor, int width,
|
||||
int height, int tractWidth, int tractHeight)
|
||||
{
|
||||
@ -51,7 +40,6 @@ namespace ProjectBulldozer.Drawning
|
||||
_tractHeight = tractHeight;
|
||||
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
//Установка позиции
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
@ -107,44 +95,26 @@ namespace ProjectBulldozer.Drawning
|
||||
{
|
||||
if (EntityTractor == null) return;
|
||||
}
|
||||
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brownBrush = new SolidBrush(Color.Brown);
|
||||
Brush windows = new SolidBrush(Color.LightYellow);
|
||||
Brush bodyColor = new SolidBrush(EntityTractor.BodyColor);
|
||||
|
||||
Brush grayBrush = new SolidBrush(Color.Gray);
|
||||
|
||||
//основное тело
|
||||
g.FillRectangle(bodyColor, _startPosX + 18, _startPosY + 42, 99, 56);
|
||||
g.DrawRectangle(pen, _startPosX + 18, _startPosY + 42, 99, 56);
|
||||
|
||||
|
||||
|
||||
//кабина водителя
|
||||
g.FillRectangle(windows, _startPosX + 18, _startPosY + 4 , 37, 37);
|
||||
g.DrawRectangle(pen, _startPosX + 18, _startPosY +4 , 37, 37);
|
||||
|
||||
|
||||
|
||||
//колеса
|
||||
|
||||
g.FillEllipse(grayBrush, _startPosX + 19, _startPosY + 76, 45, 45);
|
||||
g.DrawEllipse(pen, _startPosX + 19, _startPosY + 76, 45, 45);
|
||||
|
||||
|
||||
g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 87, 33, 33);
|
||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 87, 33, 33);
|
||||
|
||||
|
||||
//выхлопная труба
|
||||
g.FillRectangle(brownBrush, _startPosX + 88, _startPosY+ 6, 14, 35);
|
||||
g.DrawRectangle(pen, _startPosX + 88, _startPosY + 6, 14, 35);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityTractor == null)
|
||||
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBulldozer.Entities
|
||||
{
|
||||
public class EntityBulldozer : EntityTractor
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBulldozer.Entities
|
||||
namespace ProjectBulldozer.Entities
|
||||
{
|
||||
public class EntityTractor
|
||||
{
|
||||
|
22
ProjectBulldozer/FormBulldozer.Designer.cs
generated
22
ProjectBulldozer/FormBulldozer.Designer.cs
generated
@ -1,16 +1,9 @@
|
||||
namespace Bulldozer
|
||||
|
||||
namespace Bulldozer
|
||||
{
|
||||
partial class FormBulldozer
|
||||
{
|
||||
/// <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))
|
||||
@ -19,13 +12,7 @@
|
||||
}
|
||||
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()
|
||||
{
|
||||
pictureBoxBulldozer = new PictureBox();
|
||||
@ -188,9 +175,12 @@
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxBulldozer;
|
||||
private Button buttonCreateBulldozer;
|
||||
private Button buttonLeft;
|
||||
|
@ -2,24 +2,19 @@ using ProjectBulldozer;
|
||||
using ProjectBulldozer.Drawning;
|
||||
using ProjectBulldozer.Generics;
|
||||
using ProjectBulldozer.MovementStrategy;
|
||||
|
||||
namespace Bulldozer
|
||||
{
|
||||
public partial class FormBulldozer : Form
|
||||
{
|
||||
|
||||
private DrawingTractor? _drawingTractor;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawingTractor? SelectedTractor { get; private set; }
|
||||
|
||||
public FormBulldozer()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedTractor = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingTractor == null)
|
||||
@ -31,34 +26,26 @@ namespace Bulldozer
|
||||
_drawingTractor.DrawTransport(gr);
|
||||
pictureBoxBulldozer.Image = bmp;
|
||||
}
|
||||
|
||||
private void buttonCreateBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
|
||||
ColorDialog colorDialog = new ColorDialog();
|
||||
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = colorDialog.Color;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = colorDialog.Color;
|
||||
}
|
||||
|
||||
_drawingTractor = new DrawingBulldozer(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
||||
_drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonCreateTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
@ -73,7 +60,6 @@ namespace Bulldozer
|
||||
_drawingTractor.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingTractor == null)
|
||||
@ -98,7 +84,6 @@ namespace Bulldozer
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingTractor == null)
|
||||
@ -133,16 +118,10 @@ namespace Bulldozer
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSelect_Tractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedTractor = _drawingTractor;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -2,15 +2,7 @@
|
||||
{
|
||||
partial class FormTractorCollections
|
||||
{
|
||||
/// <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))
|
||||
@ -21,11 +13,6 @@
|
||||
}
|
||||
|
||||
#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()
|
||||
{
|
||||
Instruments = new Panel();
|
||||
@ -124,9 +111,11 @@
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
private void pictureBoxCollections_Click(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
private Panel Instruments;
|
||||
private Button ButtonRefreshCollection;
|
||||
private Button ButtonRemoveTractor;
|
||||
|
@ -2,7 +2,6 @@
|
||||
using ProjectBulldozer.Drawning;
|
||||
using ProjectBulldozer.Generics;
|
||||
using ProjectBulldozer.MovementStrategy;
|
||||
|
||||
namespace ProjectBulldozer
|
||||
{
|
||||
public partial class FormTractorCollections : Form
|
||||
@ -14,7 +13,6 @@ namespace ProjectBulldozer
|
||||
_Tractors = new TractorGenericCollection<DrawingTractor, DrawingObjectTractor>(pictureBoxCollections.Width,
|
||||
pictureBoxCollections.Height);
|
||||
}
|
||||
|
||||
private void ButtonAddTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_Tractors == null) return;
|
||||
@ -33,7 +31,6 @@ namespace ProjectBulldozer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
@ -51,15 +48,9 @@ namespace ProjectBulldozer
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollections.Image = _Tractors.ShowTractors();
|
||||
}
|
||||
|
||||
private void pictureBoxCollections_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,13 +31,6 @@ namespace ProjectBulldozer.Generics
|
||||
}
|
||||
return collect._collection.Insert(tract);
|
||||
}
|
||||
/// Перегрузка оператора вычитания
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(TractorGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
|
||||
namespace ProjectBulldozer.Generics
|
||||
namespace ProjectBulldozer.Generics
|
||||
{
|
||||
internal class SetGeneric<T> where T : class
|
||||
{
|
||||
@ -10,13 +8,11 @@ namespace ProjectBulldozer.Generics
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
|
||||
/// Добавление объекта в набор
|
||||
public int Insert(T tract)
|
||||
{
|
||||
return Insert(tract, 0);
|
||||
}
|
||||
|
||||
public int Insert(T tract, int position)
|
||||
{
|
||||
int NoEmpty = 0, temp = 0;
|
||||
@ -44,16 +40,11 @@ namespace ProjectBulldozer.Generics
|
||||
_places[position] = tract;
|
||||
return position;
|
||||
}
|
||||
return -1;
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент //
|
||||
return -1;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (position >= Count || position < 0)
|
||||
return null;
|
||||
|
||||
|
@ -2,9 +2,6 @@
|
||||
|
||||
namespace ProjectBulldozer.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Абстрактный класс стратегии
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
private IMoveableObject? _moveableObject;
|
||||
@ -13,7 +10,6 @@ namespace ProjectBulldozer.MovementStrategy
|
||||
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)
|
||||
@ -40,18 +36,12 @@ namespace ProjectBulldozer.MovementStrategy
|
||||
}
|
||||
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? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
@ -61,9 +51,7 @@ namespace ProjectBulldozer.MovementStrategy
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
|
||||
private bool MoveTo(DirectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
|
@ -1,11 +1,9 @@
|
||||
|
||||
using ProjectBulldozer.Drawning;
|
||||
using ProjectBulldozer.Drawning;
|
||||
namespace ProjectBulldozer.MovementStrategy
|
||||
{
|
||||
public class DrawingObjectTractor : IMoveableObject
|
||||
{
|
||||
private readonly DrawingTractor? _drawningTractor = null;
|
||||
|
||||
public DrawingObjectTractor(DrawingTractor drawningTractor)
|
||||
{
|
||||
_drawningTractor = drawningTractor;
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Bulldozer;
|
||||
|
||||
namespace ProjectBulldozer.MovementStrategy
|
||||
namespace ProjectBulldozer.MovementStrategy
|
||||
{
|
||||
public interface IMoveableObject
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
|
||||
namespace ProjectBulldozer.MovementStrategy
|
||||
namespace ProjectBulldozer.MovementStrategy
|
||||
{
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
@ -13,7 +11,6 @@ namespace ProjectBulldozer.MovementStrategy
|
||||
+ GetStep() >= FieldWidth / 2 && objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
|
||||
namespace ProjectBulldozer.MovementStrategy
|
||||
namespace ProjectBulldozer.MovementStrategy
|
||||
{
|
||||
public class MoveToRightCorner : AbstractStrategy
|
||||
{
|
||||
@ -11,12 +9,10 @@ namespace ProjectBulldozer.MovementStrategy
|
||||
|
||||
return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep();
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null) return;
|
||||
|
||||
if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight();
|
||||
if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown();
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// Середина объекта по вертикали
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
|
@ -1,17 +1,12 @@
|
||||
using ProjectBulldozer;
|
||||
|
||||
namespace Bulldozer
|
||||
{
|
||||
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.
|
||||
https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormTractorCollections());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user