Пример #1
0
 public override CommandBase GetCommand()
 {
     while (true)
     {
         Console.WriteLine("Your board:");
         Console.WriteLine(Board.ToString(this));
         Console.WriteLine("Enemy board:");
         Console.WriteLine(Opponent.Board.ToString(this));
         Console.WriteLine("Enter a coordinate (in the format \"x,y\") to launch an attack at. Q to quit. (Currently the only supported item)");
         string input = Console.ReadLine();
         if (input.ToLower() == "q")
         {
             return(new ForfeitCommand(this));
         }
         else if (input.Contains(','))
         {
             string[] coords = input.Split(',');
             if (coords.Length == 2)
             {
                 if (int.TryParse(coords[0], out int x) && int.TryParse(coords[1], out int y))
                 {
                     return(new GuessCommand(this, Opponent, x, y));
                 }
             }
         }
         Console.WriteLine("Invalid input");
     }
 }
Пример #2
0
        static void Main(string[] args)
        {
            var board = new Board();

            var battleship1 = new Battleship.Models.Battleship(5);

            board.AddBattleship(battleship1, BattleshipOrientation.Horizontal, new System.Drawing.Point(0, 0));

            var battleship2 = new Battleship.Models.Battleship(3);

            board.AddBattleship(battleship2, BattleshipOrientation.Vertical, new System.Drawing.Point(0, 1));

            var battleship3 = new Battleship.Models.Battleship(5);

            board.AddBattleship(battleship3, BattleshipOrientation.Horizontal, new System.Drawing.Point(4, 0));

            Console.WriteLine(board.ToString());
        }