Ejemplo n.º 1
0
        public void MapUserInputtedColourLetterToColours()
        {
            var colourMapper = new ColourMapper();
            var actual       = colourMapper.Map("r,g,y,c");
            var expected     = new List <Colour>()
            {
                Colour.Red, Colour.Green, Colour.Yellow, Colour.Cyan
            };

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        private static void PlayGame()
        {
            var          code         = new CodeGenerator();
            var          codeChecker  = new CodeChecker();
            var          colourMapper = new ColourMapper();
            var          randomCode   = code.Create();
            var          guess        = "";
            const string response     = "The mark was: ";

            Console.WriteLine("Welcome to Code Breaker!");
            while (guess != "stop")
            {
                Console.WriteLine("Please insert your guess (e.g \"r,g,y,c\"): ");
                guess = Console.ReadLine();
                if (guess == "stop")
                {
                    return;
                }

                try
                {
                    var convertedGuess = colourMapper.Map(guess);
                    var mark           = codeChecker.CheckGuess(randomCode, convertedGuess);
                    if (mark == "bbbb")
                    {
                        Console.WriteLine("You have won the game!");
                        Console.ReadKey();
                        return;
                    }
                    Console.WriteLine(response + mark + Environment.NewLine);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message + Environment.NewLine);
                }
            }
            Console.ReadKey();
        }