コード例 #1
0
        public void IsGameOver(int countGuess)
        {
            // Website: Youtube
            // Title: Behavior & BindableProperty in Xamarin.Forms by Houssem Dellai
            //URL: https://www.youtube.com/watch?v=dzviFuEU09Y
            var vm = BindingContext as HangmanModel;

            if (countGuess == 6)
            {
                // Player lost the game
                var hangmanModel = new HangmanModel
                {
                    StateOfGame  = "You Have Lost the Game",
                    NameOfPlayer = vm.NameOfPlayer,
                    Score        = points,
                    Difficulty   = vm.Difficulty
                };
                var gameOverPage = new GameOverPage();
                gameOverPage.BindingContext = hangmanModel;
                Navigation.PushAsync(gameOverPage);
            }

            int countCorrentGuess = 0;

            for (int i = 0; i < Word.Length; i++)
            {
                var labelList = gridTopChildBottom.Children;
                var reqLabel  = labelList[i];
                var theLabel  = reqLabel.GetType();
                if (theLabel == typeof(Label))
                {
                    Label randomLabel = (Label)reqLabel;
                    if (!randomLabel.Text.Contains('_'))
                    {
                        countCorrentGuess++;
                    }
                }
            }

            if (countCorrentGuess == Word.Length && countGuess != 6)
            {
                // Player Won the game
                var hangmanModel = new HangmanModel
                {
                    StateOfGame  = "You Have Won the Game",
                    NameOfPlayer = vm.NameOfPlayer,
                    Score        = points,
                    Difficulty   = vm.Difficulty
                };

                var gameOverPage = new GameOverPage();
                gameOverPage.BindingContext = hangmanModel;
                Navigation.PushAsync(gameOverPage);
            }
        }
コード例 #2
0
        public void getPlayerName(object sender, EventArgs e)
        {
            var hangmanModel = new HangmanModel
            {
                NameOfPlayer = MyEntry.Text
            };
            var gameDifficultyPage = new GameDifficultyPage();

            gameDifficultyPage.BindingContext = hangmanModel;
            Navigation.PushAsync(gameDifficultyPage);
        }
コード例 #3
0
        public void Difficulty(object sender, EventArgs e)
        {
            var btn = (Button)sender;

            var vm = BindingContext as HangmanModel;

            var hangmanModel = new HangmanModel
            {
                NameOfPlayer = vm.NameOfPlayer,
                Difficulty   = btn.Text
            };

            var HangmanPage = new HangmanPage();

            HangmanPage.BindingContext = hangmanModel;
            Navigation.PushAsync(HangmanPage);
        }