Guest User

Untitled

a guest
Oct 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. private bool isCloseToOther(Placement ship)
  2.         {
  3.             for (int i = 0; i < ship_list.Count; i++)
  4.             {
  5.                 if (ship_list[i] != ship)
  6.                 {
  7.                     for (int j = 0; j < ship.Vessel.Length; j++)
  8.                     {
  9.                         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)))
  10.                         {
  11.                             return true;
  12.                         }
  13.                     }
  14.                 }
  15.             }
  16.             return false;
  17.         }
  18.         private bool isShipHere(Coordinate cor)
  19.         {
  20.             if (cor.X < 1 || cor.Y < 1) { return false; }
  21.             for (int i = 0; i < ship_list.Count; i++)
  22.             {
  23.                 for (int j = 0; j < ship_list[i].Vessel.Length; j++)
  24.                 {
  25.                     if (ship_list[i].Orientation == Orientation.Horizontal)
  26.                     {
  27.                         return (ship_list[i].Y == cor.Y) && (ship_list[i].X <= cor.X) && (ship_list[i].X + ship_list[i].Vessel.Length > cor.X);
  28.                     }
  29.                     else
  30.                     {
  31.                         return (ship_list[i].X == cor.X) && (ship_list[i].Y <= cor.Y) && (ship_list[i].Y + ship_list[i].Vessel.Length > cor.Y);
  32.                     }
  33.                 }
  34.             }
  35.             return false;
  36.         }
Add Comment
Please, Sign In to add comment