public HitResult Hit(Point point) { if (Sinked) { return(HitResult.Sink); } var square = Squares.SingleOrDefault(e => e.Point.X == point.X && e.Point.Y == point.Y); if (square == null) { return(HitResult.Miss); } square.Result = HitResult.Hit; if (Squares.Any(e => e.Result != HitResult.Hit)) { return(HitResult.Hit); } Sinked = true; return(square.Result = HitResult.Sink); }
private Battleship BuildBattleship(Alingment alingment, int size, int x, int y) { var bs = new Battleship(); if (Squares.Where(s => s.X == x && s.Y == y).FirstOrDefault() == null || Squares.Where(s => (s.X == x + size - 1 && s.Y == y && alingment == Alingment.Horizontal) || (s.Y == y + size - 1 && s.X == x && alingment == Alingment.Vertical)).FirstOrDefault() == null) { bs = null; } else { if (alingment == Alingment.Horizontal) { if (Squares.Any(s => (s.Y == y && (s.X >= x && s.X <= x + size - 1)) && !s.IsEmpty)) { bs = null; } else { bs.AddSquares(Squares.Where(s => (s.Y == y && (s.X >= x && s.X <= x + size)))); } } else { if (Squares.Any(s => (s.X == x && (s.Y >= y && s.Y <= y + size - 1)) && !s.IsEmpty)) { bs = null; } else { bs.AddSquares(Squares.Where(s => (s.X == x && (s.Y >= y && s.Y <= y + size - 1)))); } } } return(bs); }
public bool IsValidLocation(ILocation location) { return(Squares.Any(s => s.Location.Equals(location))); }