Ejemplo n.º 1
0
        private void CreateMemoryCards(IList<SetDTO> sets)
        {
            var gameboardSets = new List<GameboardCardSetItem>();

            MemoryCards.Clear();

            foreach (var set in sets)
            {
                var setItemPair1 = new GameboardCardSetItem(set);
                var setItemPair2 = new GameboardCardSetItem(set);

                gameboardSets.Add(setItemPair1);
                gameboardSets.Add(setItemPair2);
            }

            gameboardSets.Shuffle();
            
            foreach (var gameboard in gameboardSets)
            {
                MemoryCards.Add(gameboard);
            }
        }
Ejemplo n.º 2
0
 private bool IsSameCardType(GameboardCardSetItem instance1, GameboardCardSetItem instance2)
 {
     return instance1.SetKey == instance2.SetKey;
 }
Ejemplo n.º 3
0
 private bool IsSameCardInstance(GameboardCardSetItem instance1, GameboardCardSetItem instance2)
 {
     return instance1.Key == instance2.Key;
 }
Ejemplo n.º 4
0
        private void IsMatch(GameboardCardSetItem selectedMatchItem, Action isMatchAction)
        {
            // this way we can show the front to the user
            selectedMatchItem.CardState = CardState.Flipped;
            
            var tempTimer = new DispatcherTimer { Interval = new TimeSpan(0,0,0,0,500) };
            tempTimer.Tick += (s,e) =>
            {
                tempTimer.Stop();

                if (PotentialMatchItem == null)
                {
                    PotentialMatchItem = selectedMatchItem;
                    UpdateCardInListStatus(selectedMatchItem.SetKey, CardState.Flipped);
                    SelectedMemoryCard = null;
                }
                else
                {
                    if (IsSameCardInstance(PotentialMatchItem, selectedMatchItem))
                    {
                        UpdateCardInListStatus(selectedMatchItem.Key, CardState.Initial);
                    }
                    else if (IsSameCardType(PotentialMatchItem, selectedMatchItem))
                    {
                        // we have a match
                        UpdateCardInListStatus(selectedMatchItem.Key, CardState.Match);
                        UpdateCardInListStatus(PotentialMatchItem.Key, CardState.Match);

                        // update the match stats
                        OnPropertyChanged("TotalMatches");

                        // if all cards are matches than we ROCK and can be done
                        if (IsAllMatchesFound())
                        {
                            Pause();
                            _audioManager.PlayWonGame();                            
                            CurrentGameMode = GameMode.Completed;

                            OnTellUserTheyWon(() => 
                            {
                                // open the leaderboard
                                ActiveLeaderBoardItem = new GameLeaderBoardItem(new GameResultDTO
                                                                    {
                                                                        GameCategory = _category.Key,
                                                                        GameLevel = CurrentGameBoardLevel,
                                                                        PlayerId = CurrentUser.Id,
                                                                        PlayerName = CurrentUser.UserName,
                                                                        Attempts = TotalAttempts,
                                                                        GameDate = DateTime.Now,
                                                                        GameTime = new TimeSpan(0, 0, GameDurationInSeconds)
                                                                    });

                                SaveLeaderBoardItem();
                                
                                ResetBoard();
                            }
                            ,
                            () => { ResetBoard(); });

                        }
                        else
                        {
                            isMatchAction.Invoke();
                        }
                    }
                    else
                    {
                        ResetAllNonMatches();

                        TotalAttempts = TotalAttempts + 1;
                    }

                    PotentialMatchItem = null;
                }
            };

            tempTimer.Start();

            
        }
Ejemplo n.º 5
0
        private void GameCardSelected(GameboardCardSetItem selectedMatchItem)
        {
            if (selectedMatchItem.CardState == CardState.Match) { return; }
            if (selectedMatchItem.CardState == CardState.Flipped) { return; }

            if ( IsGameAwaitingToBeStarted )
            {
                Play();
            }
            else if (IsGamePaused)
            {
                // need to ask the user to do something special here
                OnAskToUnPauseGame(selectedMatchItem);    
                return;
            }

            _audioManager.PlayItemSelected();
            
            IsMatch(selectedMatchItem, () => _audioManager.PlaySelectedItemMatch());
        }
Ejemplo n.º 6
0
        private async void OnAskToUnPauseGame(GameboardCardSetItem selectedMatchItem)
        {
            var yesSelected = false;

            var dialog = new MessageDialog("The board is currently paused, would you like to start playing now?");
            var yesHandler = new UICommandInvokedHandler(cmd =>
                                                    {
                                                        yesSelected = true;
                                                    });

            dialog.Commands.Add(new UICommand("Yes", yesHandler));
            dialog.Commands.Add(new UICommand("No"));

            await dialog.ShowAsync();

            if (yesSelected)
            {
                Play();
                GameCardSelected(selectedMatchItem);
            }
        }