ПИбд-21 Ярускин Салих 8 лаб простая #8

Closed
Salikh wants to merge 6 commits from laba8 into laba7
3 changed files with 17 additions and 25 deletions
Showing only changes of commit 683225f26e - Show all commits

View File

@ -17,12 +17,14 @@ namespace AirBomber.Generics
}
public bool Equals(BomberCollectionInfo? other)
{
return Name == other.Name;
if (other == null || Name == null || other.Name == null) return false;
if (Name == other.Name) return true;
throw new NotImplementedException();
}
public override int GetHashCode()
{
return this.Name.GetHashCode();
return Name?.GetHashCode() ?? 0;
}
}
}

View File

@ -14,36 +14,26 @@ namespace AirBomber
public int Compare(DrawningBomber? x, DrawningBomber? y)
{
if (x == null || x.EntityBomber == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityBomber == null)
{
throw new ArgumentNullException(nameof(y));
if (x.EntityBomber.BodyColor.Name != y.EntityBomber.BodyColor.Name)
}
if (x.EntityBomber.BodyColor != y.EntityBomber.BodyColor)
{
return x.EntityBomber.BodyColor.Name.CompareTo(y.EntityBomber.BodyColor.Name);
}
if (x.GetType().Name != y.GetType().Name)
if (x.GetType() == y.GetType() && x is EntityBomber)
{
if (x is EntityBomber)
return -1;
else
return 1;
}
if (x.GetType().Name == y.GetType().Name && x is DrawningAirBomber)
{
EntityAirBomber EntityX = (EntityAirBomber)x.EntityBomber;
EntityAirBomber EntityY = (EntityAirBomber)y.EntityBomber;
if (EntityX.DopColor.Name != EntityY.DopColor.Name)
{
return EntityX.DopColor.Name.CompareTo(EntityY.DopColor.Name);
}
return (x.EntityBomber as EntityAirBomber).DopColor.Name.CompareTo((y.EntityBomber as EntityAirBomber).DopColor.Name);
}
var speedCompare = x.EntityBomber.Speed.CompareTo(y.EntityBomber.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityBomber.Weight.CompareTo(y.EntityBomber.Weight);
}
}

View File

@ -52,13 +52,13 @@ namespace AirBomber.DrawningObjects
}
public void SetPosition(int x, int y)
{
if (x < 0 || x + _PlaneWidth > _pictureWidth)
if (_startPosX + _PlaneWidth > _pictureWidth)
{
x = _pictureWidth - _PlaneWidth;
_startPosX = _pictureWidth - _PlaneWidth;
}
if (y < 0 || y + _PlaneWidth > _pictureHeight)
if (_startPosY + _PlaneHeight > 740)
{
y = _pictureHeight - _PlaneWidth;
_startPosY = 740 - _PlaneHeight;
}
_startPosX = x;
_startPosY = y;