Beispiel #1
0
        //Main function of Game Logic
        public void run()
        {
            //Main Loop
            while (true)
            {
                System.Threading.Thread.Sleep(3000);
                updateUserMsg("Versuchen Sie diesen Emoji nachzumachen");

                //Random Emotion Generator
                string emotion = RandomEmotionGenerator.generate();
                updateEmotion(emotion);

                System.Threading.Thread.Sleep(3000);

                //Announce registering the emotion of user in 5 seconds
                for (int i = 5; i > 0; i--)
                {
                    updateUserMsg("Emotion wird analysiert in: " + i);
                    System.Threading.Thread.Sleep(1000);
                }

                //capture Image + save
                BitmapSource img   = null;
                int          count = 5;
                while (count != 0)
                {
                    Application.Current.Dispatcher.Invoke(new Action(() => {
                        img = BitmapConverter.ConvertToBitmapSource(MainWindow.main.webCameraControl.GetCurrentImage());
                        saveImage(img, count);
                    }));
                    --count;
                }

                //Allow 5 captures
                count = 5;

                System.Threading.Thread.Sleep(100);

                //Wait message while processing
                updateUserMsg("Bild wird analysiert...");

                //this try and catch serves handling the exception of a missing user during Gameplay
                try {
                    //Get random generated Emoji from Emotiongenerator in Services. Usually captured Image should be passed here as well
                    bool result = game.CompareEmotion(emotion);

                    //Update Debug Mode Output !!Just for Test, afterward DELETE!!!
                    if (global.Debug)
                    {
                        getDebugModeOutput(game.testObj);
                    }
                    //Rate the results and update UI
                    if (result)
                    {
                        updateUserMsg("Jawohl! Gut gemacht!");
                        refreshPoints();
                        System.Threading.Thread.Sleep(2000);
                    }
                    else
                    {
                        updateUserMsg("Leider falsch! Nächster Versuch..");
                        refreshPoints();
                        System.Threading.Thread.Sleep(2000);
                    }
                } catch (UserMissingException) {
                    logger.Log("GUI says: No ones there anymore. Stop the game.");
                    updateUserMsg("Spiel wurde abgebrochen! Bis zum nächsten mal!");

                    //Update Debug Mode Output !!Just for Test, afterward DELETE!!!
                    if (global.Debug)
                    {
                        getDebugModeOutput(game.testObj);
                    }
                    System.Threading.Thread.Sleep(5000);

                    //reset game
                    resetGame();

                    //exit while loop
                    break;
                } catch (MoreThanOneUserException) {
                    logger.Log("GUI says: More than one face detected.");
                    updateUserMsg("Wir erkennen mehr als eine Person. \n Die Runde wurde abgebrochen!");

                    //Update Debug Mode Output !!Just for Test, afterward DELETE!!!
                    if (global.Debug)
                    {
                        getDebugModeOutput(game.testObj);
                    }
                    System.Threading.Thread.Sleep(5000);
                } catch (UnknownException) {
                    updateUserMsg("Unbekannter Fehler ist aufgetreten! \n Die Runde wurde abgebrochen!");

                    //Update Debug Mode Output !!Just for Test, afterward DELETE!!!
                    if (global.Debug)
                    {
                        getDebugModeOutput(game.testObj);
                    }
                    System.Threading.Thread.Sleep(5000);
                }
            }

            recognizeUser();
        }