コード例 #1
0
ファイル: Program.cs プロジェクト: prince0349/BattleShipGame
        static void Main(string[] args)
        {
            Console.WriteLine("ThoughtWorks Battleship game!");
            Console.WriteLine("-------------------------------------------");

            Console.WriteLine();
            Console.WriteLine("Please chhose your option:");
            Console.WriteLine("1. Read Inputs from File.");
            Console.WriteLine("2. Enter Inputs Mannually.");
            Console.WriteLine("3. Exit the game.");
            Console.WriteLine();

            //We can Implement dependency injection and object life management here
            var battleshipBoardService = new BattleshipBoardService();
            var gamePlayBoardService   = new GamePlayBoardService();
            var interpreter            = new Interpreter(battleshipBoardService, gamePlayBoardService);

            Console.WriteLine("Please enter your option");
            int  option        = 0;
            bool isValidOption = false;

            while (isValidOption == false)
            {
                if (!int.TryParse(Console.ReadLine(), out option))
                {
                    Console.WriteLine(ApplicationConstants.InvalidOptionErrorMessage);
                }
                isValidOption = option == 1 || option == 2 || option == 3;
            }

            switch (option)
            {
            case 1:
                Console.WriteLine("File");
                Console.ReadKey();
                break;

            case 2:
                Console.WriteLine("Please enter input manually");
                Console.WriteLine("Type 'Exit' to exit the game.");
                Console.Write("Enter width and height of battle area (for example: 5 E): ");
                var exit = false;
                while (exit == false)
                {
                    var isContinue = interpreter.Parse(battleshipBoardService.GetCurrentInput() + Console.ReadLine());
                    exit = isContinue;
                }
                break;

            default:
                Console.WriteLine("Thank you for playing, ThoughtWorks Battleship game!\n Press any key to Exit:");
                Console.ReadKey();
                break;
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: deepak-rathi/BattleShip
        private static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Battleship game!");
            Console.WriteLine("There are two type of ships - type P and type Q. Type P ships can be destroyed by a single hit in each of their cells and type Q ships require 2 hits in each of their cells.");
            Console.WriteLine("A ship is considered destroyed when all of its cells are destroyed. The player who destroys all the ships of other player first wins the game.");
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("Rules:");
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("1 <= Width of Battle area(M') <= 9");
            Console.WriteLine("A <= Height of Battle area(N') <= Z");
            Console.WriteLine("1 <= Number of battleships <= M'*N'");
            Console.WriteLine("Type of ship = {'P','Q'}");
            Console.WriteLine("1 <= Width of battleship <= M'");
            Console.WriteLine("A <= Height of battleship <= N'");
            Console.WriteLine("1 <= X coordinate of ship <= M'");
            Console.WriteLine("A <= Y coordinate of ship <= N'");
            Console.WriteLine("Note: Use space ' ' to seperate your input.");
            Console.WriteLine("Type 'EXIT' to quit the game.");
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine();

            Console.Write("Enter width and height of battle area (for example: 5 E): ");

            //TODO:Implement a IOC for dependency injection and object life management
            var battleshipBoardService = new BattleshipBoardService();
            var gamePlayBoardService   = new GamePlayBoardService();
            var interpreter            = new Interpreter(battleshipBoardService, gamePlayBoardService);

            var exit = false;

            while (exit == false)
            {
                var command = interpreter.Parse(battleshipBoardService.GetCurrentInput() + Console.ReadLine());
                exit = command.Execute();
            }
        }