Exemplo n.º 1
0
        /// <summary>
        /// Handles speech recognition events.
        /// </summary>
        /// <param name="sender">
        /// Object sending the event.
        /// </param>
        /// <param name="e">
        /// Event arguments.
        /// </param>
        private void SpeechRecognized(object sender, SpeechRecognizerEventArgs e)
        {
            // Perform game status check here.
            // If a question was read and we're waiting for answer, proceed.
            // Otherwise return.

            // In other function related to asking a question, set the game status properly


            TriviaDataSource trivia = new TriviaDataSource();

            Question q = trivia.GetQuestion();

            // Semantic value associated with speech commands meant to start a new game.
            const string StartGameSpeechCommand = "START";

            // Semantic value associated with speech commands meant to enable cheating mode (for demo purposes).
            const string EnableRulesSpeechCommand = "RULESENABLE";

            // Semantic value associated with speech commands meant to disable cheating mode (for an honest game).
            const string DisableRulesSpeechCommand = "RULESDISABLE";

            // Semantic value associated with speech commands meant to start a rematch game
            const string RematchSpeechCommand = "REMATCH";

            string[] answers = q.correctAnswers;

            string Answer0 = answers[0];
            string Answer1 = answers[1];
            string Answer2 = answers[2];
            string Answer3 = answers[3];

            if (null == e.SemanticValue)
            {
                return;
            }

            // if theygot the answer correct
            if (e.SemanticValue == Answer0 || e.SemanticValue == Answer1 || e.SemanticValue == Answer2 || e.SemanticValue == Answer3)
            {
            }


            // Handle game mode control commands
            switch (e.SemanticValue)
            {
            case StartGameSpeechCommand:
                DismissWelcome();
                // Call StartGame function to display first question (and maybe begin timer)
                return;

            case DisableRulesSpeechCommand:
                this.rulesEnabled      = false;
                NoRulesText.Visibility = Visibility.Visible;
                return;

            case EnableRulesSpeechCommand:
                // Only restart game if we were currently cheating
                if (!this.rulesEnabled)
                {
                    StartNewGame();
                }

                this.rulesEnabled      = true;
                NoRulesText.Visibility = Visibility.Collapsed;
                return;

            case RematchSpeechCommand:
                StartNewGame();
                return;
            }

            // Handle game play commands
            var square = gameLogic.FindSquare(e.SemanticValue);

            if (null == square)
            {
                UpdateStatusDisplay(Properties.Resources.WrongNumber);
                return;
            }

            // We only handle speech commands with an associated sound source angle, so we can find the
            // associated player
            if (!e.SourceAngle.HasValue)
            {
                return;
            }

            var player = playerTracker.GetClosestPlayer(e.SourceAngle.Value);

            if (null == player)
            {
                // No players found matching sound source angle. Give visual indication of the problem.
                var viewer = GameBoard.GetAt(square.Row, square.Column);
                viewer.BlinkId();
                return;
            }

            var symbol = player2SymbolMap[player];

            this.UpdateGameState(symbol, square);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles speech recognition events.
        /// </summary>
        /// <param name="sender">
        /// Object sending the event.
        /// </param>
        /// <param name="e">
        /// Event arguments.
        /// </param>
        private void SpeechRecognized(object sender, SpeechRecognizerEventArgs e)
        {
            // Semantic value associated with speech commands meant to start a new game.
            const string StartGameSpeechCommand = "START";

            // Semantic value associated with speech commands meant to enable cheating mode (for demo purposes).
            const string EnableRulesSpeechCommand = "RULESENABLE";

            // Semantic value associated with speech commands meant to disable cheating mode (for an honest game).
            const string DisableRulesSpeechCommand = "RULESDISABLE";

            // Semantic value associated with speech commands meant to start a rematch game
            const string RematchSpeechCommand = "REMATCH";

            if (null == e.SemanticValue)
            {
                return;
            }

            // Handle game mode control commands
            switch (e.SemanticValue)
            {
            case StartGameSpeechCommand:
                DismissWelcome();
                return;

            case DisableRulesSpeechCommand:
                this.rulesEnabled      = false;
                NoRulesText.Visibility = Visibility.Visible;
                return;

            case EnableRulesSpeechCommand:
                // Only restart game if we were currently cheating
                if (!this.rulesEnabled)
                {
                    StartNewGame();
                }

                this.rulesEnabled      = true;
                NoRulesText.Visibility = Visibility.Collapsed;
                return;

            case RematchSpeechCommand:
                StartNewGame();
                return;
            }

            // Handle game play commands
            var square = gameLogic.FindSquare(e.SemanticValue);

            if (null == square)
            {
                UpdateStatusDisplay(Properties.Resources.WrongNumber);
                return;
            }

            // We only handle speech commands with an associated sound source angle, so we can find the
            // associated player
            if (!e.SourceAngle.HasValue)
            {
                return;
            }

            var player = playerTracker.GetClosestPlayer(e.SourceAngle.Value);

            if (null == player)
            {
                // No players found matching sound source angle. Give visual indication of the problem.
                var viewer = GameBoard.GetAt(square.Row, square.Column);
                viewer.BlinkId();
                return;
            }

            var symbol = player2SymbolMap[player];

            this.UpdateGameState(symbol, square);
        }