Esempio n. 1
0
 /// <summary>
 /// Prints the initial splash screen
 /// </summary>
 private static void PrintSplash()
 {
     Visualiser.WriteTitle();
     AsciiHelper.DrawBoat();
     Console.WriteLine();
     Console.WriteLine("Press Any Key to Start");
     Console.ReadKey();
 }
        public void GivenInvalidiBinaryStringExpectCorrectException()
        {
            //Arrange
            const string binaryStringWithRandomDistribution = "asfger";

            //Act
            int maxNumOfConsecutiveZeros = AsciiHelper.GetMaxNumOfConsecutiveZeros(binaryStringWithRandomDistribution);
        }
Esempio n. 3
0
        public int GetMaxNumOfConsecutiveZerosFromAsciiValueSum(FullName fullName)
        {
            int    sumOfAsciiValues = AsciiHelper.SumAsciiValuesInString($"{fullName.FirstName} {fullName.LastName}");
            string sumOfAsciiValuesAsBinaryString = AsciiHelper.ConvertNumToBinaryString(sumOfAsciiValues);
            int    maxNumOfConsecutiveZeros       = AsciiHelper.GetMaxNumOfConsecutiveZeros(sumOfAsciiValuesAsBinaryString);

            return(maxNumOfConsecutiveZeros);
        }
Esempio n. 4
0
        private string escapeValue(string value)
        {
            // modify if special characters are present

            if (value.IndexOfAny(AsciiHelper.GetAllSeperator().ToArray()) != -1)
            {
                value = "\"" + value.Replace("\"", "\"\"") + "\"";
            }
            return(value);
        }
        public void GivenStringExpectCorrectAsciiValueSum()
        {
            //Arrange
            const string name = "Dave Kay";
            const int    expectedAsciiValueSum = 709;

            //Act
            int sumOfAsciiValues = AsciiHelper.SumAsciiValuesInString(name);

            //Assert
            Assert.AreEqual(expectedAsciiValueSum, sumOfAsciiValues);
        }
        public void GivenBinaryStringWith10AtStartExpectCorrectMaxNumOfConsecutiveZeros()
        {
            //Arrange
            const string binaryStringWithRandomDistribution = "10111111111";
            const int    expectedMaxNumOfConsecutiveZeros   = 1;

            //Act
            int maxNumOfConsecutiveZeros = AsciiHelper.GetMaxNumOfConsecutiveZeros(binaryStringWithRandomDistribution);

            //Assert
            Assert.AreEqual(expectedMaxNumOfConsecutiveZeros, maxNumOfConsecutiveZeros);
        }
        public void GivenBinaryStringWith0sAtEndFollowedBy1ExpectCorrectMaxNumOfConsecutiveZeros()
        {
            //Arrange
            const string binaryStringWithRandomDistribution = "111000001";
            const int    expectedMaxNumOfConsecutiveZeros   = 5;

            //Act
            int maxNumOfConsecutiveZeros = AsciiHelper.GetMaxNumOfConsecutiveZeros(binaryStringWithRandomDistribution);

            //Assert
            Assert.AreEqual(expectedMaxNumOfConsecutiveZeros, maxNumOfConsecutiveZeros);
        }
        public void GivenNumExpectCorrectBinaryString()
        {
            //Arrange
            const int    num = 8;
            const string expectedBinaryString = "1000";

            //Act
            string binaryString = AsciiHelper.ConvertNumToBinaryString(num);

            //Assert
            Assert.AreEqual(expectedBinaryString, binaryString);
        }
Esempio n. 9
0
        /// <summary>
        /// When a shot fired misses
        /// </summary>
        /// <param name="game"></param>
        /// <param name="indices"></param>
        private Game ShotMissed(Game game, Indices indices)
        {
            game.GameGrid.Cells[indices.X, indices.Y].Status = GridCellStatus.ShotMissed;

            // Lose a life
            game.Lives--;

            // Reset Streak
            game.Streak = 0;

            // Deduct from Score
            if (game.Score > 0)
            {
                game.Score = game.Score - 1;
            }
            ;

            Console.Clear();
            Visualiser.PrintCurrentGame(game);

            Console.WriteLine();
            Console.WriteLine("'Unlucky Squire! Ya misses.. Try agen'");

            if (game.Lives == 0)
            {
                Console.Clear();
                game.Active = false;
                game.Score  = 0;
                AsciiHelper.DrawYouLose();
                Console.WriteLine();
                Console.WriteLine();
                Console.ReadLine();
            }

            return(game);
        }
Esempio n. 10
0
        /// <summary>
        /// When a shot is landed
        /// </summary>
        /// <param name="game"></param>
        /// <param name="indices"></param>
        private Game ShotLanded(Game game, Indices indices)
        {
            // Update cell and beep
            game.GameGrid.Cells[indices.X, indices.Y].Status = GridCellStatus.ShotLanded;
            Console.Beep(432, 750);

            // Incrememnt streak
            game.Streak++;

            // Initialise first points
            if (game.Score == 0)
            {
                game.Score = 1;
            }
            ;

            // Update score and apply streak if not negative.
            if (game.Score > 0)
            {
                game.Score = game.Score + (game.Score * game.Streak);
            }
            else
            {
                game.Score = game.Score + game.Score;
            }

            // Incremement the boat hit counter
            var target = game.GameGrid.Cells[indices.X, indices.Y];

            game.Boats
            .First(b => b.Id == target.BoatHeld.Id)
            .Hits++;

            Console.Clear();
            Visualiser.PrintCurrentGame(game);
            Console.WriteLine();

            Console.WriteLine("'Arrrgh you scurvy landlubber!!, You've hit me' boat!'");

            // Get the boat
            var boat = game.Boats
                       .First(b => b.Id == target.BoatHeld.Id);

            // Check length vs. hits
            if (boat.Hits == boat.Length)
            {
                game.BoatsSank++;
                Console.Beep(432, 1500);

                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("'Blimey! Boat down'");
                Console.ForegroundColor = ConsoleColor.Magenta;
            }
            ;

            if (game.Boats.Count() == game.BoatsSank)
            {
                Console.Clear();

                // Winner, Winner.
                game.Score  = game.Score + (game.Lives * 10);
                game.Active = false;
                AsciiHelper.DrawWinner();
                Console.WriteLine();
                Console.WriteLine();
                Console.Write("Congratulations, ");
                Console.Write(game.PlayerName);
                Console.Write(", Your Final Score was: ");
                Console.Write(game.Score);
                Console.WriteLine();
                Console.ReadLine();
            }
            ;

            return(game);
        }