コード例 #1
0
        public virtual bool RunAndContinue()
        {
            try
            {
                StringBuilder consoleLog = new StringBuilder();

                Console.Clear();
                ConsoleIO.WriteColorTextNewLine(_header, ConsoleColor.Cyan);
                consoleLog.AppendLine(_header);

                ConsoleIO.WriteColorTextNewLine(ConsoleIO.ConsoleRowSeparator);
                consoleLog.AppendLine(string.Format("{0}{1}{0}", ConsoleIO.ConsoleRowSeparator, "\n"));

                string answer = string.Format("{0}{1}{2}",
                                              new string(ReplaceToSymbol, GetTypedValue("first", ref consoleLog)),
                                              Delimiter,
                                              new string(ReplaceToSymbol, GetTypedValue("second", ref consoleLog)));

                Console.Clear();
                ConsoleIO.WriteColorText(consoleLog);
                ConsoleIO.WriteColorTextNewLine("\n-!Well Done! You've made a great thing! Now your PC is trying to process it!-\n", ConsoleColor.Green);

                DoMathOperation(answer);//, ExpressionType.SubtractChecked);

                ConsoleIO.Console_ToMainMenu();
                return(true);
            }
            catch (Exception ex)
            {
                ConsoleIO.Console_ShowErrorDescription(ex);
                Environment.Exit(0);
            }
            return(false);
        }
コード例 #2
0
        public virtual bool RunAndContinue()
        {
            try
            {
                StringBuilder consoleLog = new StringBuilder();

                Console.Clear();
                ConsoleIO.WriteColorTextNewLine(_header, ConsoleColor.Cyan);
                consoleLog.AppendLine(_header);

                ConsoleIO.ResizeConsoleWindow(Console.WindowWidth + 20, Console.WindowHeight);

                ConsoleIO.WriteColorTextNewLine(ConsoleIO.ConsoleRowSeparator);
                consoleLog.AppendLine(string.Format("{0}{1}{0}", ConsoleIO.ConsoleRowSeparator, "\n"));

                int answer = GetTypedValue(ref consoleLog);

                Console.Clear();
                ConsoleIO.WriteColorText(consoleLog);
                ConsoleIO.WriteColorTextNewLine("\n-!Well Done! You've made a great thing! Now your PC is trying to process it!-\n", ConsoleColor.Green);

                Convert(answer);//, ExpressionType.SubtractChecked);

                ConsoleIO.Console_ToMainMenu();
                return(true);
            }
            catch (Exception ex)
            {
                ConsoleIO.Console_ShowErrorDescription(ex);
                Environment.Exit(0);
            }
            return(false);
        }
コード例 #3
0
        public virtual bool RunAndContinue()
        {
            try
            {
                //resize console window
                ConsoleIO.ResizeConsoleWindow(Console.WindowWidth + 20, Console.WindowHeight);
                //to store current operation log (for redrawing in console)
                StringBuilder consoleLog = new StringBuilder();
                //clear console
                Console.Clear();
                //show current task name
                ConsoleIO.WriteColorTextNewLine(this.ToString(), ConsoleColor.Cyan);
                //add current task name to gen log
                consoleLog.AppendLine(this.ToString());
                //show text separator (by default: ------------)
                ConsoleIO.WriteColorTextNewLine(ConsoleIO.ConsoleRowSeparator);
                //add text separator to gen log
                consoleLog.AppendLine(string.Format("{0}{1}{0}", ConsoleIO.ConsoleRowSeparator, "\n"));

                //get user answer
                int answer = GetTypedValue(ref consoleLog);

                //clear console
                Console.Clear();
                //show all log info
                ConsoleIO.WriteColorText(consoleLog);
                //show the congrats message
                ConsoleIO.WriteColorTextNewLine("\n-!Well Done! You've made a great thing! Now your PC is trying to process it!-\n", ConsoleColor.Green);

                //for getting the time of opeartiona
                Stopwatch sw = new Stopwatch();
                sw.Start(); // start the stopwatch
                double factorial = GetFactorial(answer);
                sw.Stop();  // stop the stopwatch

                //show the generic output info (facotrail for -> result -> time of operation)
                ConsoleIO.WriteColorTextNewLine(ConsoleIO.ConsoleRowSeparator);
                ConsoleIO.WriteColorText(string.Format("The factorail of '{0}' -> ", answer), ConsoleColor.White, answer.ToString(), ConsoleColor.Red);
                ConsoleIO.WriteColorTextNewLine(string.Format("'{0}'", factorial), ConsoleColor.White, factorial.ToString(), ConsoleColor.Green);
                ConsoleIO.WriteColorTextNewLine(string.Format("Time of calculation -> '{0}' milliseconds", sw.Elapsed.TotalMilliseconds), ConsoleColor.White, sw.Elapsed.TotalMilliseconds.ToString(), ConsoleColor.Yellow);
                ConsoleIO.WriteColorTextNewLine(ConsoleIO.ConsoleRowSeparator + "\n");

                //show the suggestion of pressing any key to return to the main menu
                ConsoleIO.Console_ToMainMenu();
                return(true);
            }
            catch (Exception ex) //if error has been occured than show the error description and stack trace
            {
                ConsoleIO.Console_ShowErrorDescription(ex);
                Environment.Exit(0);
            }
            return(false);
        }
コード例 #4
0
        public virtual bool RunAndContinue()
        {
            try
            {
                //clear console
                Console.Clear();
                //show current task name
                ConsoleIO.WriteColorTextNewLine(this.ToString(), ConsoleColor.Cyan);
                //add current rues description
                ConsoleIO.WriteColorTextNewLine(_rulesProvider.RulesDescription);

                //for getting the time of opeartiona
                Stopwatch sw = new Stopwatch();
                // start the stopwatch
                sw.Start();
                //play game
                bool IsAWinner = TryToGuessTheNumber();
                // stop the stopwatch
                sw.Stop();

                //check the result
                if (!IsAWinner)
                {
                    ConsoleIO.WriteColorTextNewLine("\n-!-!-!-!-!-!-!GAME OVER!-!-!-!-!-!-!-\n", ConsoleColor.Red);
                }
                else //user find the right answer
                {
                    ConsoleIO.WriteColorTextNewLine("\n-!-!-!-!-!-!-!Well Done!-!-!-!-!-!-!-\n", ConsoleColor.Green);
                    ConsoleIO.WriteColorTextNewLine(string.Format("{0}!, you are a winner! Your Time is: '{1}' sec\n", Environment.UserName, sw.Elapsed.Seconds), ConsoleColor.Green);
                }

                ConsoleIO.WriteColorTextNewLine(ConsoleIO.ConsoleRowSeparator + "\n");
                //show the suggestion of pressing any key to return to the main menu
                ConsoleIO.Console_ToMainMenu();
                return(true);
            }
            catch (Exception ex) //if error has been occured than show the error description and stack trace
            {
                ConsoleIO.Console_ShowErrorDescription(ex);
                Environment.Exit(0);
            }
            return(false);
        }
コード例 #5
0
        public virtual bool RunAndContinue()
        {
            try
            {
                //to store last user answer
                string lastAnswer = string.Empty;
                //all posible answers
                var userAnswersDict = new Dictionary <FarmerPazle_Answers, string>(_rulesProvider.AnswersDict);
                //to store all correct answers as string
                StringBuilder enteredCorrectAnsw = new StringBuilder();
                //get last pressed key info
                ConsoleKeyInfo keyInfo = default(ConsoleKeyInfo);
                //resize console window
                ConsoleIO.ResizeConsoleWindow(Console.WindowWidth, Console.WindowHeight + 10);

                //for getting the time of user game
                Stopwatch sw = new Stopwatch();
                // start the stopwatch
                sw.Start();
                do // while user answer number < MAX attempts And until user find the right answer / key
                {
                    //Clear console and show task header and rules description
                    Console.Clear();
                    ConsoleIO.WriteColorTextNewLine(this.ToString(), ConsoleColor.Cyan);
                    ConsoleIO.WriteColorTextNewLine(_rulesProvider.RulesDescription);

                    //Show all posible answers
                    userAnswersDict.ToList().ForEach(x => ConsoleIO.WriteColorTextNewLine(String.Format(x.Value, string.Empty), ConsoleColor.White, Rules.CorrectAnswerLabel.ToString(), ConsoleColor.DarkGreen));
                    ConsoleIO.WriteColorTextNewLine(ConsoleIO.ConsoleRowSeparator);

                    //Check and show the object that must be tranfer to the other bank of river and which have been already transferred there
                    _transferProvider.ShowCurrentTransferStatus(lastAnswer);

                    //check if last answer was incorrect
                    if (_rulesProvider.CurrenAttempt > 0 && String.IsNullOrWhiteSpace(lastAnswer))
                    {
                        ConsoleIO.WriteColorTextNewLine("Incorrect entered value!", ConsoleColor.Red);
                    }

                    //show how many lifes user has
                    ConsoleIO.WriteColorText("Lifes count: ", ConsoleColor.White);
                    ConsoleIO.WriteColorTextNewLine(_rulesProvider.MaxAttemptsCount - _rulesProvider.CurrenAttempt, _rulesProvider.GetCurrentAttemptColor());

                    //show already enered correct answers / keys
                    ConsoleIO.WriteColorText("Entered correct keys: ", ConsoleColor.White);
                    ConsoleIO.WriteColorTextNewLine(enteredCorrectAnsw.ToString(), ConsoleColor.Green);

                    //show last enered key char
                    if (keyInfo != default(ConsoleKeyInfo))
                    {
                        ConsoleIO.WriteColorTextNewLine(string.Format("Last entered key: '{0}", keyInfo.KeyChar));
                    }

                    //show text separator (by default: ------------)
                    ConsoleIO.WriteColorTextNewLine(ConsoleIO.ConsoleRowSeparator);

                    //chech if user has already found the right answer / key. If Yes then exit from do {...}while(...);
                    if (_rulesProvider.IsAlreadyWin(enteredCorrectAnsw))
                    {
                        break;
                    }

                    //read key
                    keyInfo = Console.ReadKey();
                    //check if current answer is correct (compare with the dictionary of keys)
                    lastAnswer = GetCorrectAnswer(keyInfo.KeyChar.ToString(), userAnswersDict, ref enteredCorrectAnsw);
                } while (!_rulesProvider.IsMaxAttempt()); //check if user answer number < MAX attempts
                sw.Stop();                                // stop the stopwatch

                if (_rulesProvider.IsMaxAttempt())        //check if user answer number >= MAX attempts
                {
                    ConsoleIO.WriteColorTextNewLine("\n-!-!-!-!-!-!-!GAME OVER!-!-!-!-!-!-!-\n", ConsoleColor.Red);
                }
                else //user find the right answer / key
                {
                    ConsoleIO.WriteColorTextNewLine("\n-!-!-!-!-!-!-!Well Done!-!-!-!-!-!-!-\n", ConsoleColor.Green);
                    ConsoleIO.WriteColorTextNewLine(string.Format("{0}!, you are a winner! Your Time is: '{1}' sec\n", Environment.UserName, sw.Elapsed.Seconds), ConsoleColor.Green);
                }
                //show the suggestion of pressing any key to return to the main menu
                ConsoleIO.Console_ToMainMenu();
                return(true);
            }
            catch (Exception ex) //if error has been occured than show the error description and stack trace
            {
                ConsoleIO.Console_ShowErrorDescription(ex);
                Environment.Exit(0);
            }
            return(false);
        }