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)
        {
            GameController controller = new GameController();
            controller.StartGame();

            /*
            Console.WriteLine("Welcome to The Typing Game. Press enter to start. ");
            Console.Write("Please Enter your name: ");
            var username = Console.ReadLine();
            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.", username, countMistakes);
                    Console.WriteLine("Your current time: " + currentTime);
                    Console.ReadLine();
                }
                else Console.WriteLine("Well done {0}! You made zero mistakes.", username);
                Console.WriteLine("Your current time: " + currentTime);
                Console.ReadLine();
            }

            Console.WriteLine("Sorry {0}, Please try again. Input was invalid", username);
            Console.WriteLine("Your current time: " + currentTime);
            Console.ReadLine();
             */
        }