Esempio n. 1
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();
        }
Esempio n. 2
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();
                            }
                        }
                    }
                }
            }
        }