Esempio n. 1
0
        public void StartSentenceGame(ConsoleView _view, GameController controller, SentenceDB _sentencedb)
        {
            _view.Countdown();
            TimeSpan startTime = StartTimer();
            int wordCounter = 1;

            while (wordCounter <= 5)
            {
                Sentence sentence1 = _sentencedb.GetRandomSentence(Difficulty);
                string randomSentence = sentence1.SentenceString;
                controller.TotalSentenceLength += sentence1.SentenceLength;

                _view.PrintSentence(wordCounter, randomSentence);
                string sentence = Console.ReadLine();
                string[] sentenceArray = sentence.Split(' ');

                int mistakes = GetMistakes(sentenceArray, randomSentence);

                controller.TotalMistakes += mistakes;
                Console.WriteLine("Number of mistakes: " + mistakes);
                Console.WriteLine();
                wordCounter++;
            }
            TimeSpan endTime = EndTimer();
            TimeSpan elapsedTime = endTime - startTime;

            _view.EndGamePrinter(elapsedTime, controller.TotalMistakes, controller.TotalSentenceLength);

            Console.Clear();
            StartSentenceGame(_view, new GameController(), _sentencedb);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            ConsoleView welcome = new ConsoleView();
            welcome.PrintWelcome();

            string sentence1 = "The quick brown fox jumped over the lazy dog?";

            //print out output
            Console.WriteLine(sentence1);
            var now = DateTime.Now.TimeOfDay;
            //input
            var sentence = Console.ReadLine();
            var end = DateTime.Now.TimeOfDay;
            Console.WriteLine("--------------------------------------------------------------------");

            var elasped = end - now;
            var currentTime = elasped.Seconds + ":" + elasped.Milliseconds;

            var countMistakes = 0;

            var sentenceToWords = sentence1.Split();
            var sentenceToWords1 = sentence.Split();

            if (sentenceToWords.Length == sentenceToWords1.Length)
            {
                for (int i = 0; i < sentenceToWords.Length; i++)
                {
                    if (sentenceToWords[i] != sentenceToWords1[i])
                    {
                        countMistakes++;
                    }
                }
            }

            if(sentence.Length == sentence1.Length)
            {
                if (sentence.Equals(sentence1) == false)
                {
                    Console.WriteLine("Sorry {0}, you have made {1} mistake.", welcome.UserName, countMistakes);
                    Console.WriteLine("Your current time: " + currentTime);
                    Console.ReadLine();
                }
                else Console.WriteLine("Well done {0}! You made zero mistakes.", welcome.UserName);
                Console.WriteLine("Your current time: " + currentTime);
                Console.ReadLine();
            }

            Console.WriteLine("Sorry {0}, Please try again. Input was invalid", welcome.UserName);
            Console.WriteLine("Your current time: " + currentTime);
            Console.ReadLine();
        }
Esempio n. 3
0
 public GameController()
 {
     _view = new ConsoleView();
     _sentence = new Sentence();
     _sentencedb = new SentenceDB();
 }
Esempio n. 4
0
 public GameController()
 {
     _view       = new ConsoleView();
     _sentence   = new Sentence();
     _sentencedb = new SentenceDB();
 }