コード例 #1
0
ファイル: LoadGame.xaml.cs プロジェクト: ttimt/fyp-mmu
        private void playGame(object sender, RoutedEventArgs e)
        {
            //	Delete game
            GameRepository gameRepository = new GameRepository();

            gameRepository.DeleteGame(playerID);

            //	Load a new game
            GameMode gameMode = new GameMode(kinectSensorChooser, playerID);

            Close();
            gameMode.ShowDialog();
        }
コード例 #2
0
        //	Temporary click function
        private void back_Click(object sender, RoutedEventArgs e)
        {
            //	Save Game
            if (watch.IsRunning)
            {
                watch.Stop();
                GameRepository gro = new GameRepository();
                currentTime = previousTime + watch.ElapsedMilliseconds / 1000;
                if (gro.GetGame(playerID).Count == 0)
                {
                    gro.AddGame(currentLives, playerID, currentTime, currentScore, itemGame, gameMode);
                }
                else
                {
                    gro.ModifyGame(currentLives, playerID, currentTime, currentScore, itemGame, gameMode);
                }
                watch.Reset();
            }

            //	Close the game window
            Close();
        }
コード例 #3
0
        private void InteractionStreamOnInteractionFrameReady(object sender, InteractionFrameReadyEventArgs args)
        {
            using (var iaf = args.OpenInteractionFrame())             //dispose as soon as possible
            {
                if (iaf == null)
                {
                    return;
                }

                iaf.CopyInteractionDataTo(_userInfos);
            }

            foreach (var userInfo in _userInfos)
            {
                var userID = userInfo.SkeletonTrackingId;
                if (userID == 0)
                {
                    continue;
                }

                var hands = userInfo.HandPointers;

                foreach (var hand in hands)
                {
                    var lastHandEvents = hand.HandType == InteractionHandType.Left
                                                                                                ? _lastLeftHandEvents
                                                                                                : _lastRightHandEvents;
                    if (lastHandEvents == _lastLeftHandEvents)
                    {
                        continue;
                    }

                    if (hand.HandEventType != InteractionHandEventType.None)
                    {
                        lastHandEvents[userID] = hand.HandEventType;
                    }

                    var lastHandEvent = lastHandEvents.ContainsKey(userID)
                                                                                        ? lastHandEvents[userID]
                                                                                        : InteractionHandEventType.None;

                    if (lastHandEvent == InteractionHandEventType.Grip)
                    {
                        //	Set value
                        isGripped = true;

                        //	If hand gripped, show gripped cursor and move the item with the cursor
                        handCursor.Source = new BitmapImage(new Uri("Resources/pointerWhite.png", UriKind.Relative));

                        //	Find the item number of which the hand cursor is on
                        if (itemGripped.HandCursorOn == -1 && itemGripped.HandCursorOnSet == false)
                        {
                            for (int i = itemChildrenStart; i < canvas.Children.Count; i++)
                            {
                                var childrenPoint   = canvas.Children[i].TranslatePoint(new Point(0, 0), canvas);
                                var handCursorPoint = handCursor.TranslatePoint(new Point(0, 0), canvas);
                                if (handCursorPoint.X > childrenPoint.X && handCursorPoint.X < childrenPoint.X +
                                    itemWidth && handCursorPoint.Y > childrenPoint.Y && handCursorPoint.Y < childrenPoint.Y + itemHeight)
                                {
                                    itemGripped.HandCursorOn            = i;
                                    itemGripped.HandCursorOnLeftDistant = handCursorPoint.X - childrenPoint.X;
                                    itemGripped.HandCursorOnTopDistant  = handCursorPoint.Y - childrenPoint.Y;
                                    itemGripped.HandCursorOnSet         = true;
                                    break;
                                }
                            }
                        }

                        //	Move the item with the hand cursor
                        if (itemGripped.HandCursorOn != -1)
                        {
                            var p = handCursor.TranslatePoint(new Point(0, 0), canvas);

                            try
                            {
                                Canvas.SetLeft(canvas.Children[itemGripped.HandCursorOn], p.X - itemGripped.HandCursorOnLeftDistant);
                                Canvas.SetTop(canvas.Children[itemGripped.HandCursorOn], p.Y - itemGripped.HandCursorOnTopDistant);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else if (lastHandEvent == InteractionHandEventType.GripRelease)
                    {
                        //	Set value
                        isGripped = false;

                        //	If hand grip released, show normal cursor
                        handCursor.Source           = new BitmapImage(new Uri("Resources/handWhite.png", UriKind.Relative));
                        itemGripped.HandCursorOn    = -1;
                        itemGripped.HandCursorOnSet = false;
                    }

                    if (hand.IsPressed)
                    {
                        //	If hand pressed the back, go back:

                        //	Get points of hand cursor and back button
                        var handCursorPoint = handCursor.TranslatePoint(new Point(0, 0), canvas);
                        var backPoint       = back.TranslatePoint(new Point(0, 0), canvas);

                        //	Left and Right check:
                        if (back.ActualWidth + backPoint.X >= handCursorPoint.X && handCursorPoint.X + handCursor.ActualWidth / 2 >= backPoint.X)
                        {
                            //	Top and Bottom check:
                            if (back.ActualHeight + backPoint.Y >= handCursorPoint.Y && handCursorPoint.Y + handCursor.ActualHeight / 2 >= backPoint.Y)
                            {
                                //	If 'watch' timer is running, then save the game first
                                //	If not, just close the window
                                if (watch.IsRunning)
                                {
                                    //	Stop the timer
                                    watch.Stop();

                                    //	Create new GameRepository object
                                    GameRepository gro = new GameRepository();
                                    //	Get the playing time

                                    currentTime = previousTime + watch.ElapsedMilliseconds / 1000;

                                    //	If the player ID exists in the database (Playing loaded game), update the row to the current game, else insert a new row
                                    if (gro.GetGame(playerID).Count == 0)
                                    {
                                        //	Add a new game to the database
                                        gro.AddGame(currentLives, playerID, currentTime, currentScore, itemGame, gameMode);
                                    }
                                    else
                                    {
                                        //	Modify the game in the database
                                        gro.ModifyGame(currentLives, playerID, currentTime, currentScore, itemGame, gameMode);
                                    }

                                    //	Reset the timer
                                    watch.Reset();
                                }
                                //	Close the game window
                                Close();
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
        //  Execute press function
        private void OnHandPointerPressRelease(object sender, HandPointerEventArgs e)
        {
            if (capturedHandPointer == e.HandPointer)
            {
                e.HandPointer.Capture(null);
                if (e.HandPointer.GetIsOver(btn_login))
                {
                    VisualStateManager.GoToState(btn_login, "MouseOver", true);

                    if (playerID == -1)
                    {
                        //	No user logged in, proceed to show login screen
                        Login login = new Login(kinectSensorChooser);
                        playerID = login.CustomShowDialog();
                    }
                    else
                    {
                        //	A user is logged in, prompt current user to logout before a new login
                        Logout logout = new Logout(kinectSensorChooser, playerID);

                        if (logout.CustomShowDialog())
                        {
                            PersonalBestValue.Visibility = Visibility.Hidden;
                            PersonalBestText.Visibility  = Visibility.Hidden;

                            //	Reset player ID
                            playerID = -1;

                            //	User logged out, proceed to show login screen
                            Login login = new Login(kinectSensorChooser);
                            playerID = login.CustomShowDialog();
                        }
                    }

                    //	If logged in, get highest score
                    if (playerID != -1)
                    {
                        PlayersRepository playersRepository = new PlayersRepository();
                        playerScore            = playersRepository.GetPlayerScore(playerID);
                        PersonalBestValue.Text = playerScore.ToString();

                        PersonalBestValue.Visibility = Visibility.Visible;
                        PersonalBestText.Visibility  = Visibility.Visible;
                    }
                    else
                    {
                        PersonalBestValue.Visibility = Visibility.Hidden;
                        PersonalBestText.Visibility  = Visibility.Hidden;
                    }
                }
                else if (e.HandPointer.GetIsOver(btn_register))
                {
                    VisualStateManager.GoToState(btn_register, "MouseOver", true);

                    if (playerID == -1)
                    {
                        //	No user logged in, proceed to show register screen
                        Register register = new Register(kinectSensorChooser);
                        register.ShowDialog();
                    }
                    else
                    {
                        //	A user is logged in, prompt current user to logout before a new registration
                        Logout logout = new Logout(kinectSensorChooser, playerID);

                        if (logout.CustomShowDialog())
                        {
                            //	Reset player ID
                            playerID = -1;

                            PersonalBestValue.Visibility = Visibility.Hidden;
                            PersonalBestText.Visibility  = Visibility.Hidden;

                            //	User logged out, proceed to show register screen
                            Register register = new Register(kinectSensorChooser);
                            register.ShowDialog();
                        }
                    }
                }
                else if (e.HandPointer.GetIsOver(btn_singlePlayer))
                {
                    VisualStateManager.GoToState(btn_singlePlayer, "MouseOver", true);

                    if (playerID == -1)
                    {
                        CustomMessageBox customMessageBox = new CustomMessageBox(kinectSensorChooser);
                        customMessageBox.ShowText("Please login to continue");
                    }
                    else
                    {
                        GameRepository gameRepository = new GameRepository();
                        if (gameRepository.GetGame(playerID).Count > 0)
                        {
                            LoadGame loadGame = new LoadGame(kinectSensorChooser, playerID);
                            loadGame.ShowDialog();
                        }
                        else
                        {
                            GameMode gameMode = new GameMode(kinectSensorChooser, playerID);
                            gameMode.ShowDialog();
                        }
                    }
                }
                else if (e.HandPointer.GetIsOver(btn_multiPlayer))
                {
                    VisualStateManager.GoToState(btn_multiPlayer, "MouseOver", true);

                    //	Multiplayer doesnt need login, player ID = -1
                    GameMode gameMode = new GameMode(kinectSensorChooser, -1);
                    gameMode.ShowDialog();
                }
                else if (e.HandPointer.GetIsOver(btn_loadGame))
                {
                    VisualStateManager.GoToState(btn_loadGame, "MouseOver", true);

                    if (playerID == -1)
                    {
                        CustomMessageBox customMessageBox = new CustomMessageBox(kinectSensorChooser);
                        customMessageBox.ShowText("Please login to continue");
                    }
                    else
                    {
                        GameRepository gameRepository         = new GameRepository();
                        List <GameRepository.GameDto> getGame = gameRepository.GetGame(playerID);
                        if (getGame.Count == 0)
                        {
                            //	No game saved, display the dialog
                            CustomMessageBox customMessageBox = new CustomMessageBox(kinectSensorChooser);
                            customMessageBox.ShowText("You have no saved game!");
                        }
                        else
                        {
                            //	Load the game
                            kinectSensorChooser.Stop();
                            DragDropImages dragDropImages = new DragDropImages(playerID, getGame[0].GameMode);
                            dragDropImages.GetLoadGameData(getGame[0].Lives, getGame[0].Time, getGame[0].Score, getGame[0].ItemGame);
                            dragDropImages.ShowDialog();

                            kinectSensorChooser.Start();
                        }
                    }
                }
                else if (e.HandPointer.GetIsOver(btn_highScores))
                {
                    VisualStateManager.GoToState(btn_highScores, "MouseOver", true);

                    GameMode gameMode = new GameMode(kinectSensorChooser, playerID, 0);
                    gameMode.ShowDialog();
                }
                else if (e.HandPointer.GetIsOver(btn_help))
                {
                    VisualStateManager.GoToState(btn_help, "MouseOver", true);

                    Help help = new Help(kinectSensorChooser);
                    help.ShowDialog();
                }
                else if (e.HandPointer.GetIsOver(btn_exit))
                {
                    VisualStateManager.GoToState(btn_exit, "MouseOver", true);

                    Close();
                }
                else
                {
                    VisualStateManager.GoToState(btn_login, "Normal", true);
                    VisualStateManager.GoToState(btn_register, "Normal", true);
                    VisualStateManager.GoToState(btn_singlePlayer, "Normal", true);
                    VisualStateManager.GoToState(btn_multiPlayer, "Normal", true);
                    VisualStateManager.GoToState(btn_loadGame, "Normal", true);
                    VisualStateManager.GoToState(btn_highScores, "Normal", true);
                    VisualStateManager.GoToState(btn_help, "Normal", true);
                    VisualStateManager.GoToState(btn_exit, "Normal", true);
                }
                e.Handled = true;
            }
        }