Exemplo n.º 1
0
        public void BuildGame()
        {
            var random     = new Random();
            var randomList = Terms
                             .Select(x => new { term = x, number = random.Next(Terms.Count) })
                             .OrderBy(x => x.number)
                             .Select(x => x.term)
                             .Take(_gameSize)
                             .ToList();

            var listOfNumbers = new List <int>();

            for (int i = 0; i < _gameSize * 2; i++)
            {
                listOfNumbers.Add(i);
            }

            var listOfRands = listOfNumbers
                              .Select(x => new { Id = x, rand = random.Next() })
                              .OrderBy(x => x.rand)
                              .Select(x => x.Id)
                              .ToList();

            SetupButtons();
            PositionsAtPlay.Clear();
            _errors = 0;

            for (int i = 0; i < _gameSize; i++)
            {
                var index = i * 2;
                var rand0 = listOfRands[index];
                var rand1 = listOfRands[index + 1];
                var term  = randomList[i];
                PositionsAtPlay.Add(rand0);
                PositionsAtPlay.Add(rand1);

                var menuButton01 = Buttons[rand0];
                var menuButton02 = Buttons[rand1];

                menuButton01.ResetWithTerm(term, MatchButtonType.Answer);
                menuButton02.ResetWithTerm(term, MatchButtonType.Question);
            }
        }