Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private bool isCloseToOther(Placement ship)
- {
- for (int i = 0; i < ship_list.Count; i++)
- {
- if (ship_list[i] != ship)
- {
- for (int j = 0; j < ship.Vessel.Length; j++)
- {
- if (isShipHere(new Coordinate(ship.X, ship.Y - 1)) || isShipHere(new Coordinate(ship.X, ship.Y + 1)) || isShipHere(new Coordinate(ship.X + 1, ship.Y)) || isShipHere(new Coordinate(ship.X - 1, ship.Y)))
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- private bool isShipHere(Coordinate cor)
- {
- if (cor.X < 1 || cor.Y < 1) { return false; }
- for (int i = 0; i < ship_list.Count; i++)
- {
- for (int j = 0; j < ship_list[i].Vessel.Length; j++)
- {
- if (ship_list[i].Orientation == Orientation.Horizontal)
- {
- return (ship_list[i].Y == cor.Y) && (ship_list[i].X <= cor.X) && (ship_list[i].X + ship_list[i].Vessel.Length > cor.X);
- }
- else
- {
- return (ship_list[i].X == cor.X) && (ship_list[i].Y <= cor.Y) && (ship_list[i].Y + ship_list[i].Vessel.Length > cor.Y);
- }
- }
- }
- return false;
- }
Add Comment
Please, Sign In to add comment