Beispiel #1
0
 public bool placeShip(Tuple<int, int> start, Tuple<int, int> end, Ship s)
 {
     if (rulebook.validPlacement(start, end, this))
     {
         //Mark the nodes affected as ships o the board
         for (int y = start.Item1; y <= end.Item1; y++)
         {
             for (int x = start.Item2; x <= end.Item2; x++)
             {
                 GameBoard.ElementAt(x).ElementAt(y).setShip(s);
                 s.setStartEnd(start, end);
             }
         }
         if (!this.isLoading)
             xmlStorage.addShip(player, start.Item1, start.Item2, end.Item1, end.Item2, s.getSize());
         printBoard();
         return true;
     }
     else
     {
         Console.WriteLine("Not a valid placement! Try again!");
         return false;
     }
 }
Beispiel #2
0
        bool actionPlaceShip(Board p, Ship s)
        {
            if (p.getIsHuman())
            {
                int x1, y1, x2, y2;
                Console.WriteLine("Enter coordinates to place a ship at, cant be longer or shorter than " + s.getSize());
                Console.Write("x: ");
                x1 = int.Parse(Console.ReadLine());
                Console.Write("y: ");
                y1 = int.Parse(Console.ReadLine());

                Console.Write("x: ");
                x2 = int.Parse(Console.ReadLine());
                Console.Write("y: ");
                y2 = int.Parse(Console.ReadLine());

                Tuple<int, int> posStart = new Tuple<int, int>(x1, y1);
                Tuple<int, int> posEnd = new Tuple<int, int>(x2, y2);
                if (rulebook.validPlacement(posStart, posEnd, p))
                {
                    s.setStartEnd(posStart, posEnd);
                    p.placeShip(posStart, posEnd, s);
                    Console.WriteLine("Ship Placed!");
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                Tuple<Tuple<int, int>, Tuple<int, int>> startEnd = p.ai.placeShip(s);
                Tuple<int, int> posStart = new Tuple<int, int>(startEnd.Item1.Item1, startEnd.Item1.Item2);
                Tuple<int, int> posEnd = new Tuple<int, int>(startEnd.Item2.Item1, startEnd.Item2.Item2);

                if (rulebook.validPlacement(posStart, posEnd, p))
                {
                    s.setStartEnd(posStart, posEnd);
                    p.placeShip(posStart, posEnd, s);
                    Console.WriteLine("Ship Placed!");
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }