コード例 #1
0
        private void Shuffle(List <DoorsCardViewModel> list)
        {
            int    n   = list.Count;
            Random rnd = new Random();

            while (n > 1)
            {
                int k = (rnd.Next(0, n));
                n--;
                DoorsCardViewModel value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }
コード例 #2
0
        private async void DoorsCardFlipped(DoorsCardViewModel card)
        {
            if (flippegImage == false)
            {
                card.Visibility = true;

                int nrflipped = doorsCards.Count(c => c.Visibility && !c.Hidden);

                if (DoorsCards[DoorsCards.IndexOf(card)].FrontImage == $"../../Images/Doors/door4.jpg")
                {
                    // MessageBox.Show("You win! Try next door!");
                    await Task.Delay(200);

                    flippegImage = true;
                    int oldScore = Score;
                    StartGame(level);
                    Score = oldScore + 10;
                }
                else if (DoorsCards[DoorsCards.IndexOf(card)].FrontImage == $"../../Images/Doors/blackcat.jpg")
                {
                    MessageBox.Show("You Lost!", "Message", MessageBoxButton.OK,
                                    MessageBoxImage.Exclamation);
                    flippegImage  = true;
                    IsEnabledSave = false;
                    if (Score != 0)
                    {
                        GameRecord gameRecord = new GameRecord
                        {
                            Date   = DateTime.Now,
                            Game   = "DoorsGame",
                            Player = App.CurrentApp.MainViewModel.LoginViewModel.Player,
                            Score  = Score
                        };
                        _gameRecordManager.Add(gameRecord);
                        App.CurrentApp.MainViewModel.Refresh();
                    }
                    ResetGame();
                    ResetScore();
                }
            }
        }
コード例 #3
0
        public void StartGame(string param)
        {
            Output = _playerManager.GetGameState(App.CurrentApp.MainViewModel.LoginViewModel.Player.Id, "DoorsGame");
            if (Output != "")
            {
                IsEnabledOpen = true;
            }
            else
            {
                IsEnabledOpen = false;
            }
            IsEnabledSave = true;


            int nrcartiBune = 0;
            int nrcartiRele = 0;

            level        = param;
            flippegImage = false;
            if (param == "Easy")
            {
                nrcartiBune = 2;
                nrcartiRele = 1;
            }
            if (param == "Medium")
            {
                nrcartiBune = 4;
                nrcartiRele = 2;;
            }
            if (param == "Hard")
            {
                nrcartiBune = 6;
                nrcartiRele = 3;
            }

            List <DoorsCardViewModel> doorsCards = new List <DoorsCardViewModel>();

            for (int i = 0; i < nrcartiBune; i++)
            {
                DoorsCardViewModel dcvm = new DoorsCardViewModel()
                {
                    Visibility = false,
                    BackImage  = $"../../Images/Doors/door.jpg",
                    FrontImage = $"../../Images/Doors/door4.jpg"
                };
                doorsCards.Add(dcvm);
            }
            for (int j = 0; j < nrcartiRele; j++)
            {
                DoorsCardViewModel dcvm3 = new DoorsCardViewModel()
                {
                    Visibility = false,
                    BackImage  = $"../../Images/Doors/door.jpg",
                    FrontImage = $"../../Images/Doors/blackcat.jpg"
                };
                doorsCards.Add(dcvm3);
            }
            Shuffle(doorsCards);
            DoorsCards = doorsCards;
            ResetScore();
        }