コード例 #1
0
        private void ButtonPressed(int i)
        {
            var index = i;

            if (_firstButtonPressed)
            {
                var termAlreadyPressed = Buttons[_firstButtonPressedIndex];

                if (index == _firstButtonPressedIndex)
                {
                    termAlreadyPressed.Pressed();
                    _firstButtonPressedIndex = -1;
                    _firstButtonPressed      = !_firstButtonPressed;

                    return;
                }

                var termJustPressed = Buttons[index];
                termJustPressed.Pressed();

                if (termJustPressed.CheckForCorrectAnswer(termAlreadyPressed))
                {
                    _firstButtonPressed = false;
                    Buttons[index]      = null;
                    Buttons[_firstButtonPressedIndex] = null;
                    PositionsAtPlay.Remove(index);
                    PositionsAtPlay.Remove(_firstButtonPressedIndex);
                    IsGameOver();
                }
                else
                {
                    // todo
                    _errors += 1;
                }
                _firstButtonPressed      = false;
                _firstButtonPressedIndex = -1;
            }
            else
            {
                if (!PositionsAtPlay.Contains(index))
                {
                    return;
                }
                var termJustPressed = Buttons[index];
                if (termJustPressed == null)
                {
                    return;
                }
                termJustPressed.Pressed();

                _firstButtonPressed      = true;
                _firstButtonPressedIndex = index;
            }
        }
コード例 #2
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);
            }
        }