Сданная 3 лабораторная работа
This commit is contained in:
parent
a89a75da6c
commit
9a45e3fab9
@ -91,7 +91,8 @@ namespace Bus
|
||||
|
||||
//кузов
|
||||
Brush br = new SolidBrush(Bus?.BodyColor ?? Color.Black);
|
||||
g.FillRectangle(br, _startPosX+11, _startPosY+11, 149, 49);
|
||||
g.FillRectangle(br, _startPosX+ 11, _startPosY + 11, 149, 49);
|
||||
|
||||
//колеса
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 50, 20, 20);
|
||||
|
@ -26,13 +26,10 @@ namespace Bus
|
||||
if (sportBus.BodyKit)
|
||||
{
|
||||
Brush br = new SolidBrush(Bus?.BodyColor ?? Color.Black);
|
||||
Brush fireBrush = new SolidBrush(Color.Red);
|
||||
Pen pen1 = new(Color.Black);
|
||||
|
||||
g.DrawRectangle(pen1, _startPosX + 20, _startPosY, 150, 50);
|
||||
g.FillRectangle(br, _startPosX + 21, _startPosY+1, 149, 49);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
_startPosX += 10;
|
||||
@ -44,10 +41,10 @@ namespace Bus
|
||||
if (sportBus.Sportline)
|
||||
{
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 5, 10, 14);
|
||||
g.FillRectangle(dopBrush, _startPosX + 30, _startPosY + 5, 10, 14);
|
||||
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 4, 10, 15);
|
||||
|
||||
g.FillRectangle(brBlue, _startPosX + 60, _startPosY + 5, 10, 14);
|
||||
g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 5, 10, 14);
|
||||
g.DrawRectangle(pen, _startPosX + 59, _startPosY + 4, 10, 15);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ namespace Bus
|
||||
internal class EntitySportBus : EntityBus
|
||||
{
|
||||
public Color DopColor { get; private set; }
|
||||
public Color DopColor1 { get; private set; }
|
||||
public bool BodyKit { get; private set; }
|
||||
public bool Wing { get; private set; }
|
||||
public bool Sportline { get; private set; }
|
||||
@ -17,6 +18,7 @@ namespace Bus
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
DopColor1 = bodyColor;
|
||||
BodyKit = bodyKit = true;
|
||||
Wing = wing = true;
|
||||
Sportline = sportline = true;
|
||||
|
@ -33,7 +33,13 @@ namespace Bus
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_bus = new DrawingBus(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_bus = new DrawingBus(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
@ -67,10 +73,24 @@ namespace Bus
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_bus = new DrawingSportBus(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialogDop = new();
|
||||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialogDop.Color;
|
||||
}
|
||||
|
||||
_bus = new DrawingSportBus(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
|
||||
Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0,1)), Convert.ToBoolean(rnd.Next(0,1)));
|
||||
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
18
Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs
generated
18
Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs
generated
@ -62,7 +62,7 @@
|
||||
this.groupBox1.Size = new System.Drawing.Size(250, 450);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "groupBox1";
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
@ -74,6 +74,7 @@
|
||||
this.buttonRight.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonRight.TabIndex = 10;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
@ -85,6 +86,7 @@
|
||||
this.buttonDown.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonDown.TabIndex = 9;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
@ -96,6 +98,7 @@
|
||||
this.buttonLeft.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonLeft.TabIndex = 8;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
@ -107,6 +110,7 @@
|
||||
this.buttonUp.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonUp.TabIndex = 7;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
@ -128,6 +132,13 @@
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 122);
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(100, 27);
|
||||
this.maskedTextBoxPosition.TabIndex = 11;
|
||||
//
|
||||
// buttonRemoveBus
|
||||
//
|
||||
this.buttonRemoveBus.Location = new System.Drawing.Point(6, 155);
|
||||
@ -151,6 +162,9 @@
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Водная карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 26);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28);
|
||||
@ -174,7 +188,7 @@
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Name = "FormMapWithSetDoubleDeckerBus";
|
||||
this.Text = "FormMapWithSetDoubleDeckerBus";
|
||||
this.Text = "Автобус";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
|
@ -14,11 +14,16 @@ namespace Bus
|
||||
{
|
||||
private MapWithSetDoubleDeckerBusGeneric<DrawingObjectBus, AbstractMap> _mapBusCollectionGeneric;
|
||||
|
||||
//DrawingBus SelectedBus { get; private set; }
|
||||
|
||||
public FormMapWithSetDoubleDeckerBus()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
AbstractMap map = new SimpleMap();
|
||||
_mapBusCollectionGeneric = new MapWithSetDoubleDeckerBusGeneric<DrawingObjectBus, AbstractMap>(
|
||||
pictureBox.Width, pictureBox.Height, map);
|
||||
|
||||
}
|
||||
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
@ -28,6 +33,9 @@ namespace Bus
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Водная карта":
|
||||
map = new MyMap();
|
||||
break;
|
||||
}
|
||||
|
||||
if(map != null)
|
||||
@ -39,8 +47,6 @@ namespace Bus
|
||||
{
|
||||
_mapBusCollectionGeneric = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void ButtonAddBus_Click(object sender, EventArgs e)
|
||||
@ -52,8 +58,15 @@ namespace Bus
|
||||
FormBus form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.SelectedBus == null)
|
||||
{
|
||||
MessageBox.Show("Сначала создайте объект");
|
||||
return;
|
||||
}
|
||||
|
||||
DrawingObjectBus bus = new(form.SelectedBus);
|
||||
if (_mapBusCollectionGeneric + bus)
|
||||
|
||||
if (_mapBusCollectionGeneric + bus != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapBusCollectionGeneric.ShowSet();
|
||||
@ -72,12 +85,12 @@ namespace Bus
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapBusCollectionGeneric - pos)
|
||||
if (_mapBusCollectionGeneric - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapBusCollectionGeneric.ShowSet();
|
||||
@ -86,13 +99,8 @@ namespace Bus
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBusCollectionGeneric == null)
|
||||
@ -136,6 +144,6 @@ namespace Bus
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapBusCollectionGeneric.MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ namespace Bus
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public static bool operator +(MapWithSetDoubleDeckerBusGeneric<T, U> map, T bus)
|
||||
public static int operator +(MapWithSetDoubleDeckerBusGeneric<T, U> map, T bus)
|
||||
{
|
||||
return map._setBus.Insert(bus);
|
||||
}
|
||||
|
||||
public static bool operator -(MapWithSetDoubleDeckerBusGeneric<T, U> map, int position)
|
||||
public static T operator -(MapWithSetDoubleDeckerBusGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setBus.Remove(position);
|
||||
}
|
||||
@ -97,20 +97,49 @@ namespace Bus
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth/_placeSizeWidth; i++)
|
||||
Brush pointColor = new SolidBrush(Color.Orange);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight/_placeSizeHeight; j++)
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
// TODO
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight,
|
||||
i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (40)));
|
||||
|
||||
g.FillPolygon(pointColor, new Point[] {
|
||||
new Point(i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (40))),
|
||||
new Point(i * _placeSizeWidth + _placeSizeWidth / 2 - 10, (int)((j * _placeSizeHeight) - (50))),
|
||||
new Point(i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (60))),
|
||||
new Point(i * _placeSizeWidth + _placeSizeWidth / 2 + 10, (int)((j * _placeSizeHeight) - (50)))
|
||||
});
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBus(Graphics g)
|
||||
{
|
||||
for (int i = 0; i<_setBus.Count; i++)
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int currentWidth = width - 1;
|
||||
int currentHeight = 0;
|
||||
|
||||
for (int i = 0; i < _setBus.Count; i++)
|
||||
{
|
||||
_setBus.Get(i)?.SetObject(currentWidth * _placeSizeWidth,
|
||||
currentHeight * _placeSizeHeight,
|
||||
_pictureWidth, _pictureHeight);
|
||||
_setBus.Get(i)?.DrawingObject(g);
|
||||
|
||||
if (currentWidth > 0)
|
||||
currentWidth--;
|
||||
else
|
||||
{
|
||||
currentWidth = width - 1;
|
||||
currentHeight++;
|
||||
}
|
||||
if (currentHeight > height) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,25 +11,46 @@ namespace Bus
|
||||
{
|
||||
private readonly T[] _places;
|
||||
public int Count => _places.Length;
|
||||
private int BusPlaces = 0;
|
||||
|
||||
public SetDoubleDeckerBusGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
|
||||
public bool Insert(T bus)
|
||||
public int Insert(T bus)
|
||||
{
|
||||
return true;
|
||||
return Insert(bus, 0);
|
||||
}
|
||||
|
||||
public bool Insert(T bus, int position)
|
||||
public int Insert(T bus, int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length || BusPlaces == _places.Length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
BusPlaces++;
|
||||
while (_places[position] != null)
|
||||
{
|
||||
for (int i = _places.Length - 1; i > 0; --i)
|
||||
{
|
||||
if (_places[i] == null && _places[i - 1] != null)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
_places[i - 1] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
_places[position] = bus;
|
||||
return true;
|
||||
return position;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
public T Remove(int position)
|
||||
{
|
||||
return true;
|
||||
if (position < 0 || position >= _places.Length) return null;
|
||||
T savedBus = _places[position];
|
||||
_places[position] = null;
|
||||
return savedBus;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
|
Loading…
Reference in New Issue
Block a user