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

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

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

using ProjectMotorboat.Drownings;
using ProjectMotorboat.Exceptions;

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

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

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

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

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

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

namespace ProjectMotorboat.Drownings
{

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

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

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

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

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

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

namespace ProjectMotorboat.MovementStrategy;

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

namespace ProjectMotorboat.MovementStrategy;

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

namespace ProjectMotorboat.MovementStrategy;
public class MoveToBorder : AbstractStrategy

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

namespace ProjectMotorboat.MovementStrategy;
public class MoveToCenter : AbstractStrategy
{

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

@ -1,10 +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 MovementDirection
{

@ -1,10 +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 ObjectParameters
{

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

namespace ProjectMotorboat.MovementStrategy;
public enum StrategyStatus

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