public void ResetGame()
        {
            var random = new Random();

            ShuffledCards = animalEmojis.Concat(animalEmojis)
                            .OrderBy(item => random.Next())
                            .Select(item => AnimalCard.Create(item))
                            .ToList();
            MatchesFound = 0;
            timerStart   = timerEnd = null;
        }
        public async Task SelectCardAsync(AnimalCard card)
        {
            // Make sure the clock is running
            if (!timer.Enabled)
            {
                timerStart = DateTime.Now;
                timer.Start();
            }

            // Can't select cards that were already turned
            if (!card.IsTurned ? isTurningInProgress : true)
            {
                return;
            }

            card.IsTurned = true;

            if (lastCardSelected == null)
            {
                // First selection of the pair. Remember it.
                lastCardSelected = card;
            }
            else
            {
                if (card == lastCardSelected)
                {
                    // Match found!
                    MatchesFound++;
                    card.IsMatched = lastCardSelected.IsMatched = true;
                }
                else
                {
                    // Not a match
                    isTurningInProgress = true;
                    await Task.Delay(turnDelayDuration); // Pause before turning back

                    isTurningInProgress = false;
                    card.IsTurned       = lastCardSelected.IsTurned = false;
                }

                // Reset for next pair.
                lastCardSelected = null;
            }

            // Is the game won?
            if (MatchesFound == animalEmojis.Length)
            {
                timerEnd = DateTime.Now;
                timer.Stop();
                completionTimes.Add(timerEnd.Value.Subtract(timerStart.Value).TotalSeconds);
            }
        }
示例#3
0
        public async Task SelectCardAsync(AnimalCard card)
        {
            if (!timer.Enabled)
            {
                timerStart = DateTime.Now;
                timer.Start();
            }

            // Simplify conditional expression
            if (!card.IsTurned ? isTurningInProgress : true)
            {
                return;
            }

            card.IsTurned = true;

            if (lastCardSelected == null)
            {
                lastCardSelected = card;
            }
            else
            {
                if (card == lastCardSelected)
                {
                    MatchesFound++;
                    card.IsMatched = lastCardSelected.IsMatched = true;
                }
                else
                {
                    isTurningInProgress = true;
                    await Task.Delay(turnDelayDuration); // Pause before turning back

                    isTurningInProgress = false;
                    card.IsTurned       = lastCardSelected.IsTurned = false;
                }

                lastCardSelected = null;
            }

            // IntelliSense in DateTime and TimeSpan literals
            string date = DateTime.Now.ToString("mm:");

            if (MatchesFound == animalEmojis.Length)
            {
                timerEnd = DateTime.Now;
                timer.Stop();
                completionTimes.Add(timerEnd.Value.Subtract(timerStart.Value).TotalSeconds);
            }
        }
        public async Task SelectCardAsync(AnimalCard card)
        {
            if (!timer.Enabled)
            {
                timerStart = DateTime.Now;
                timer.Start();
            }

            // Simplify conditional expression
            if (!card.IsTurned ? isTurningInProgress : true)
            {
                return;
            }

            card.IsTurned = true;

            if (lastCardSelected == null)
            {
                lastCardSelected = card;
            }
            else
            {
                if (card == lastCardSelected)
                {
                    // Remove redundant equality
                    if (playerTurn == true) //Player 1 = true
                    {
                        MatchesFoundP1++;
                    }
                    else
                    {
                        MatchesFoundP2++;
                    }

                    MatchesFound++;
                    card.IsMatched = lastCardSelected.IsMatched = true;
                }
                else
                {
                    isTurningInProgress = true;
                    await Task.Delay(turnDelayDuration); // Pause before turning back

                    isTurningInProgress = false;
                    playerTurn          = !playerTurn;
                    card.IsTurned       = lastCardSelected.IsTurned = false;
                }

                lastCardSelected = null;
            }

            // IntelliSense in DateTime and TimeSpan literals
            string date = DateTime.Now.ToString("mm:");

            DateTime dt = new DateTime(2020, 10, 15, 8, 30, 52);

            // Regex completion
            Regex r = new Regex("");

            if (MatchesFound == animalEmojis.Length)
            {
                timerEnd = DateTime.Now;
                timer.Stop();
                completionTimes.Add(timerEnd.Value.Subtract(timerStart.Value).TotalSeconds);
            }
        }