コード例 #1
0
ファイル: Game.cs プロジェクト: Ajurgs/Battleship
 private void HitShip(int x, int y)
 {
     for (int i = 0; i < shipList.Count; i++)
     {
         if (shipList[i].BowX == shipList[i].SternX)
         {
             if (shipList[i].BowY > shipList[i].SternY)
             {
                 for (int j = shipList[i].SternY; j <= shipList[i].BowY; j++)
                 {
                     if (shipList[i].BowX == x && j == y)
                     {
                         board.Hit(x, y);
                         bool sunk = shipList[i].shipSunk();
                         if (sunk == true)
                         {
                             Console.WriteLine($"you have sunk a {shipList[i].Type}");
                         }
                         else
                         {
                             Console.WriteLine("You have hit a ship Capitan");
                         }
                     }
                     else
                     {
                         continue;
                     }
                 }
             }
             else if (shipList[i].SternY > shipList[i].BowY)
             {
                 for (int j = shipList[i].BowY; j <= shipList[i].SternY; j++)
                 {
                     if (shipList[i].BowX == x && j == y)
                     {
                         board.Hit(x, y);
                         bool sunk = shipList[i].shipSunk();
                         if (sunk == true)
                         {
                             Console.WriteLine($"you have sunk a {shipList[i].Type}");
                         }
                         else
                         {
                             Console.WriteLine("You have hit a ship Capitan");
                         }
                     }
                     else
                     {
                         continue;
                     }
                     //Console.Write($"{shipList[i].bowX},{j} ");
                 }
                 continue;
             }
         }
         else if (shipList[i].BowY == shipList[i].SternY)
         {
             if (shipList[i].BowX > shipList[i].SternX)
             {
                 for (int j = shipList[i].SternX; j <= shipList[i].BowX; j++)
                 {
                     if (j == x && shipList[i].BowY == y)
                     {
                         board.Hit(x, y);
                         bool sunk = shipList[i].shipSunk();
                         if (sunk == true)
                         {
                             Console.WriteLine($"you have sunk a {shipList[i].Type}");
                         }
                         else
                         {
                             Console.WriteLine("You have hit a ship Capitan");
                         }
                     }
                     else
                     {
                         continue;
                     }
                     //Console.Write($"{j},{shipList[i].bowY} ");
                 }
                 continue;
             }
             else if (shipList[i].SternX > shipList[i].BowX)
             {
                 for (int j = shipList[i].BowX; j <= shipList[i].SternX; j++)
                 {
                     if (j == x && shipList[i].BowY == y)
                     {
                         board.Hit(x, y);
                         bool sunk = shipList[i].shipSunk();
                         if (sunk == true)
                         {
                             Console.WriteLine($"you have sunk a {shipList[i].Type}");
                         }
                         else
                         {
                             Console.WriteLine("You have hit a ship Capitan");
                         }
                     }
                     else
                     {
                         continue;
                     }
                     //Console.Write($"{j},{shipList[i].bowY} ");
                 }
                 continue;
             }
             else
             {
                 Console.WriteLine("Error");
             }
         }
     }
 }