示例#1
0
        public static bool FireWeapon(this Player thisPlayer, Player otherPlayer, IConsoleWriter consoleWriter)
        {
            if (!thisPlayer.IsVictor)
            {
                consoleWriter.ClearScreen();

                PrintEnemyBattlefield(otherPlayer, consoleWriter);
                var coordinates = consoleWriter.ReadCoordinates();

                var avatar = otherPlayer.Battlefield[coordinates.PosX, coordinates.PosY];
                if (string.Equals(avatar, Constants.OCEAN_AVATAR) ||
                    string.Equals(avatar, Constants.DEBRIS) ||
                    string.Equals(avatar, Constants.HIT_ALREADY))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"{thisPlayer.Name} : It's a Miss.");
                    Console.ResetColor();
                    otherPlayer.MaskedBattlefield[coordinates.PosX, coordinates.PosY] = Constants.HIT_ALREADY;
                }
                else
                {
                    otherPlayer.Battlefield[coordinates.PosX, coordinates.PosY]       = Constants.DEBRIS;
                    otherPlayer.MaskedBattlefield[coordinates.PosX, coordinates.PosY] = Constants.DEBRIS;
                    otherPlayer.BattlefieldAnalyzer[avatar] -= 1;
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine($"{thisPlayer.Name} : It's a Hit!");
                    Console.ResetColor();
                }
                var gameOn = AnalyzeBattlefield(otherPlayer);

                thisPlayer.IsVictor = gameOn ? false : true;
                Thread.Sleep(1000);
                return(gameOn);
            }
            return(false);
        }