Exemple #1
0
        public void Start(PracticeSettings pr)
        {
            var stateStack = new Stack <StateID>();

            stateStack.Push(StateID.Menu);

            while (true)
            {
                if (stateStack.Count == 0)
                {
                    break;
                }

                var currentState = stateStack.Peek();
                var stateAction  = m_StateMap[currentState];
                var newState     = stateAction.Run(pr);

                if (newState == StateID.Exit)
                {
                    stateStack.Pop();
                }

                else if (newState == StateID.None)
                {
                    continue;
                }

                else if (m_StateMap.ContainsKey(newState) && !stateStack.Contains(newState))
                {
                    stateStack.Push(newState);
                }

                else if (m_StateMap.ContainsKey(newState) && stateStack.Contains(newState))
                {
                    while (stateStack.Peek() != newState)
                    {
                        stateStack.Pop();
                    }
                }

                else // does not contain
                {
                    Console.WriteLine("Action not yet supported");
                    Console.WriteLine("Press enter to continue...");
                    Console.ReadLine();
                }
            }
        }
Exemple #2
0
        public Bocagoi()
        {
            PracticeSettings = new PracticeSettings();

            var box1 = string.Format(WordBoxFileName, 1);
            var box2 = string.Format(WordBoxFileName, 2);

            if (!File.Exists(box1))
            {
                File.Create(box1);
            }

            if (!File.Exists(box2))
            {
                File.Create(box2);
            }
        }
Exemple #3
0
        public static Run RunGame(PracticeSettings pr)
        {
            var words = LoadAllWords();
            var totalWordsForPractice = words[pr.Box].Skip(pr.WordsMin - 1).Take(pr.WordsMax - pr.WordsMin + 1).ToList();

            var rand      = new Random();
            var score     = new Score();
            var startTime = DateTime.Now;

            while (totalWordsForPractice.Count > 0)
            {
                var wordsLeft = totalWordsForPractice.PartitionListElements(20, rand);

                RunGameWithPartitionedWords(pr, rand, score, wordsLeft);
            }

            var result = CreateAndPrintResults(pr, score, startTime, endTime: DateTime.Now);

            Console.WriteLine("Press enter to continue...");
            Console.ReadLine();
            return(result);
        }
Exemple #4
0
 private static void RunGameWithPartitionedWords(PracticeSettings pr, Random rand, Score score, IList <(string, string)> wordsLeft)