LabWork07

This commit is contained in:
Osyagina_Anna 2024-05-02 11:55:16 +04:00
parent 1597553ddc
commit e5657c372e
22 changed files with 21 additions and 145 deletions

View File

@ -1,10 +1,4 @@
using ProjectMotorboat.Drownings; using ProjectMotorboat.Drownings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat; namespace ProjectMotorboat;
public delegate void BoatDelegate(DrawningBoat car); public delegate void BoatDelegate(DrawningBoat car);

View File

@ -1,4 +1,4 @@
using ProjectMotorboat.CollectionGenericObjects; 
using ProjectMotorboat.Drownings; using ProjectMotorboat.Drownings;
using ProjectMotorboat.Exceptions; using ProjectMotorboat.Exceptions;

View File

@ -1,10 +1,4 @@
using System; namespace ProjectMotorboat.CollectionGenericObjects;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.CollectionGenericObjects;
public enum CollectionType public enum CollectionType
{ {

View File

@ -1,10 +1,4 @@
using System; namespace ProjectMotorboat.CollectionGenericObjects;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.CollectionGenericObjects;
public interface ICollectionGenericObjects<T> public interface ICollectionGenericObjects<T>

View File

@ -1,26 +1,16 @@
using ProjectMotorboat.Exceptions; using ProjectMotorboat.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.CollectionGenericObjects; namespace ProjectMotorboat.CollectionGenericObjects;
public class ListGenericObjects<T> : ICollectionGenericObjects<T> public class ListGenericObjects<T> : ICollectionGenericObjects<T>
where T : class where T : class
{ {
/// <summary>
/// Список объектов, которые храним
/// </summary>
private readonly List<T?> _collection; private readonly List<T?> _collection;
public CollectionType GetCollectionType => CollectionType.List; public CollectionType GetCollectionType => CollectionType.List;
/// <summary>
/// Максимально допустимое число объектов в списке
/// </summary>
private int _maxCount; private int _maxCount;
public int Count => _collection.Count; public int Count => _collection.Count;
@ -40,9 +30,6 @@ where T : class
} }
} }
/// <summary>
/// Конструктор
/// </summary>
public ListGenericObjects() public ListGenericObjects()
{ {
_collection = new(); _collection = new();
@ -50,13 +37,11 @@ where T : class
public T Get(int position) public T Get(int position)
{ {
//TODO выброс ошибки если выход за границу
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) public int Insert(T obj)
{ {
// TODO выброс ошибки если переполнение
if (Count == _maxCount) throw new CollectionOverflowException(Count); if (Count == _maxCount) throw new CollectionOverflowException(Count);
_collection.Add(obj); _collection.Add(obj);
return Count; return Count;
@ -64,8 +49,6 @@ where T : class
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
// TODO выброс ошибки если переполнение
// TODO выброс ошибки если за границу
if (Count == _maxCount) throw new CollectionOverflowException(Count); if (Count == _maxCount) throw new CollectionOverflowException(Count);
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
_collection.Insert(position, obj); _collection.Insert(position, obj);
@ -74,7 +57,6 @@ where T : class
public T Remove(int position) public T Remove(int position)
{ {
// TODO если выброс за границу
if (position >= _collection.Count || position < 0) throw new PositionOutOfCollectionException(position); if (position >= _collection.Count || position < 0) throw new PositionOutOfCollectionException(position);
T obj = _collection[position]; T obj = _collection[position];

View File

@ -61,7 +61,6 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
} }
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
// проверка позиции
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position); if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
if (_collection[position] != null) if (_collection[position] != null)
@ -95,14 +94,11 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
throw new CollectionOverflowException(Count); throw new CollectionOverflowException(Count);
} }
} }
// вставка
_collection[position] = obj; _collection[position] = obj;
return position; return position;
} }
public T Remove(int position) public T Remove(int position)
{ {
// проверка позиции
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position); if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
if (_collection[position] == null) throw new ObjectNotFoundException(position); if (_collection[position] == null) throw new ObjectNotFoundException(position);

View File

@ -1,11 +1,6 @@
using ProjectMotorboat.Drownings; using ProjectMotorboat.Drownings;
using ProjectMotorboat.Exceptions; using ProjectMotorboat.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.CollectionGenericObjects; namespace ProjectMotorboat.CollectionGenericObjects;
public class StorageCollection<T> public class StorageCollection<T>

View File

@ -1,8 +1,4 @@
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.Drownings namespace ProjectMotorboat.Drownings
{ {

View File

@ -1,9 +1,5 @@
using ProjectMotorboat.Entities; using ProjectMotorboat.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.Drownings; namespace ProjectMotorboat.Drownings;
@ -114,28 +110,28 @@ public class DrawningBoat
} }
switch (direction) switch (direction)
{ {
//влево
case DirectionType.Left: case DirectionType.Left:
if (_startPosX.Value - EntityBoat.Step > 0) if (_startPosX.Value - EntityBoat.Step > 0)
{ {
_startPosX -= (int)EntityBoat.Step; _startPosX -= (int)EntityBoat.Step;
} }
return true; return true;
//вверх
case DirectionType.Up: case DirectionType.Up:
if (_startPosY.Value - EntityBoat.Step > 0) if (_startPosY.Value - EntityBoat.Step > 0)
{ {
_startPosY -= (int)EntityBoat.Step; _startPosY -= (int)EntityBoat.Step;
} }
return true; return true;
// вправо
case DirectionType.Right: case DirectionType.Right:
if (_startPosX.Value + EntityBoat.Step + _drawningBoatWidth < _pictureWidth) if (_startPosX.Value + EntityBoat.Step + _drawningBoatWidth < _pictureWidth)
{ {
_startPosX += (int)EntityBoat.Step; _startPosX += (int)EntityBoat.Step;
} }
return true; return true;
//вниз
case DirectionType.Down: case DirectionType.Down:
if (_startPosY.Value + EntityBoat.Step + _drawningBoatHeight < _pictureHeight) if (_startPosY.Value + EntityBoat.Step + _drawningBoatHeight < _pictureHeight)
{ {
@ -155,7 +151,7 @@ public class DrawningBoat
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush mainBrush = new SolidBrush(EntityBoat.BodyColor); Brush mainBrush = new SolidBrush(EntityBoat.BodyColor);
// корпус
Point[] hull = new Point[] Point[] hull = new Point[]
{ {
new Point(_startPosX.Value + 5, _startPosY.Value + 0), new Point(_startPosX.Value + 5, _startPosY.Value + 0),
@ -167,7 +163,7 @@ public class DrawningBoat
g.FillPolygon(mainBrush, hull); g.FillPolygon(mainBrush, hull);
g.DrawPolygon(pen, hull); g.DrawPolygon(pen, hull);
// основная часть
Brush blockBrush = new SolidBrush(EntityBoat.BodyColor); Brush blockBrush = new SolidBrush(EntityBoat.BodyColor);
g.FillRectangle(blockBrush, _startPosX.Value + 20, _startPosY.Value + 15, 80, 40); g.FillRectangle(blockBrush, _startPosX.Value + 20, _startPosY.Value + 15, 80, 40);
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 15, 80, 40); g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 15, 80, 40);

View File

@ -26,15 +26,12 @@ public class DrawningMotorboat : DrawningBoat
Brush additionalBrush = new SolidBrush(motorboat.AdditionalColor); Brush additionalBrush = new SolidBrush(motorboat.AdditionalColor);
base.DrawTransport(g); base.DrawTransport(g);
// стекло впереди
if (motorboat.Glass) if (motorboat.Glass)
{ {
Brush glassBrush = new SolidBrush(Color.LightBlue); Brush glassBrush = new SolidBrush(Color.LightBlue);
g.FillEllipse(glassBrush, _startPosX.Value + 20, _startPosY.Value + 15, 100, 40); g.FillEllipse(glassBrush, _startPosX.Value + 20, _startPosY.Value + 15, 100, 40);
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 15, 100, 40); g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 15, 100, 40);
} }
// двигатель
if (motorboat.Motor) if (motorboat.Motor)
{ {
Brush engineBrush = new Brush engineBrush = new

View File

@ -8,16 +8,8 @@ using System.Threading.Tasks;
namespace ProjectMotorboat.Drownings; namespace ProjectMotorboat.Drownings;
public static class ExtentionDrawningBoat public static class ExtentionDrawningBoat
{ {
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly string _separatorForObject = ":"; private static readonly string _separatorForObject = ":";
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public static DrawningBoat? CreateDrawningBoat(this string info) public static DrawningBoat? CreateDrawningBoat(this string info)
{ {
string[] strs = info.Split(_separatorForObject); string[] strs = info.Split(_separatorForObject);
@ -34,12 +26,6 @@ public static class ExtentionDrawningBoat
} }
return null; return null;
} }
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawingWarship"></param>
/// <returns></returns>
public static string GetDataForSave(this DrawningBoat drawningBoat) public static string GetDataForSave(this DrawningBoat drawningBoat)
{ {
string[]? array = drawningBoat?.EntityBoat?.GetStringRepresentation(); string[]? array = drawningBoat?.EntityBoat?.GetStringRepresentation();

View File

@ -1,8 +1,6 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ProjectMotorboat.CollectionGenericObjects; using ProjectMotorboat.CollectionGenericObjects;
using ProjectMotorboat.Drownings; using ProjectMotorboat.Drownings;
using ProjectMotorboat.Exceptions;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
namespace ProjectMotorboat; namespace ProjectMotorboat;

View File

@ -1,15 +1,5 @@
using ProjectMotorboat.Drownings; using ProjectMotorboat.Drownings;
using ProjectMotorboat.Entities; using ProjectMotorboat.Entities;
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 ProjectMotorboat namespace ProjectMotorboat
{ {
public partial class FormBoatConfig : Form public partial class FormBoatConfig : Form
@ -81,11 +71,9 @@ namespace ProjectMotorboat
private void Panel_MouseDown(object? sender, MouseEventArgs e) private void Panel_MouseDown(object? sender, MouseEventArgs e)
{ {
// TODO отправка цвета в Drag&Drop
(sender as Control)?.DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); (sender as Control)?.DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
} }
// Логика смены цветов: основного и дополнительного (для продвинутого объекта)
private void LabelBodyColor_DragEnter(object sender, DragEventArgs e) private void LabelBodyColor_DragEnter(object sender, DragEventArgs e)
{ {
if (e.Data?.GetDataPresent(typeof(Color)) ?? false) if (e.Data?.GetDataPresent(typeof(Color)) ?? false)

View File

@ -1,9 +1,4 @@
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy; namespace ProjectMotorboat.MovementStrategy;

View File

@ -1,8 +1,4 @@
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy; namespace ProjectMotorboat.MovementStrategy;

View File

@ -1,8 +1,4 @@
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy; namespace ProjectMotorboat.MovementStrategy;
public class MoveToBorder : AbstractStrategy public class MoveToBorder : AbstractStrategy

View File

@ -1,9 +1,4 @@
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy; namespace ProjectMotorboat.MovementStrategy;
public class MoveToCenter : AbstractStrategy public class MoveToCenter : AbstractStrategy
{ {

View File

@ -1,9 +1,5 @@
using ProjectMotorboat.Drownings; using ProjectMotorboat.Drownings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy; namespace ProjectMotorboat.MovementStrategy;

View File

@ -1,10 +1,4 @@
using System; namespace ProjectMotorboat.MovementStrategy;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy;
public enum MovementDirection public enum MovementDirection
{ {

View File

@ -1,10 +1,4 @@
using System; namespace ProjectMotorboat.MovementStrategy;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy;
public class ObjectParameters public class ObjectParameters
{ {

View File

@ -1,9 +1,4 @@
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy; namespace ProjectMotorboat.MovementStrategy;
public enum StrategyStatus public enum StrategyStatus

View File

@ -1,7 +1,6 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Serilog; using Serilog;
namespace ProjectMotorboat; namespace ProjectMotorboat;