Пример #1
0
        public void RestartGame()
        {
            log.Debug("restart game");
            foreach (var player in CurrentGameState.Players)
            {
                player.Rank = 0;
            }

            this.CurrentHandState = new CurrentHandState(this.CurrentGameState);
            this.CurrentHandState.LeftCardsCount = TractorRules.GetCardNumberofEachPlayer(this.CurrentGameState.Players.Count);
            CurrentHandState.IsFirstHand         = true;
            UpdatePlayersCurrentHandState();
            var currentHandId = this.CurrentHandState.Id;

            DistributeCards();
            if (this.CurrentHandState.Id != currentHandId)
            {
                return;
            }
            Thread.Sleep(5000);
            if (this.CurrentHandState.Trump != Suit.None)
            {
                DistributeLast8Cards();
            }
            else if (PlayersProxy.Count == 4)
            {
                RestartGame();
            }
        }
    void UpdateHandedness()
    {
        for (int i = 0; i < trackedHands.Count; i++)
        {
            CurrentHandState handState     = trackedHands[i];
            CurrentHandState oppositeState = GetOppositeHandState(handState);
            if (oppositeState == null)
            {
                handState.Handedness = GetHandedness(HeadTransform.forward, handState.Position, HeadTransform.up, ref handState.HandednessConfidence, handState.Handedness);
            }
            else
            {
                handState.Handedness = GetHandedness(
                    HeadTransform.forward,
                    handState.Position,
                    oppositeState.Position,
                    HeadTransform.up,
                    ref handState.HandednessConfidence,
                    handState.Handedness,
                    oppositeState.Handedness);

                // Do a sanity check - opposite state handedness cannot equal this handdedness

                /*if (oppositeState.Handedness != HandednessEnum.Neither
                 *  && handState.Handedness != HandednessEnum.Neither
                 *  && oppositeState.Handedness != handState.Handedness) {
                 *  // Switch the opposite state
                 *  oppositeState.Handedness = handState.Handedness == HandednessEnum.Left ? HandednessEnum.Right : HandednessEnum.Left;
                 * }*/
            }
        }
    }
Пример #3
0
    public void SourceLost(CurrentHandState inputState)
    {
        lock (trackedHands)
        {
            trackedHands.Remove(inputState);
        }



        OnHandLeft(inputState);



        if (trackedHands.Count == 0)
        {
        }
        else
        {
            trackedHands.Sort(

                delegate(CurrentHandState h1, CurrentHandState h2) {
                return(h1.HandId == h2.HandId ? 0 : h1.HandId < h2.HandId ? -1 : 1);
            }

                );
        }
    }
Пример #4
0
 public TractorHost()
 {
     CurrentGameState = new GameState();
     CurrentHandState = new CurrentHandState(this.CurrentGameState);
     CardsShoe        = new CardsShoe();
     PlayersProxy     = new Dictionary <string, IPlayer>();
 }
    public CurrentHandState GetHandState(int idx)
    {
        CurrentHandState handState = null;

        if (trackedHands.Count > idx)
        {
            handState = trackedHands[idx];
        }
        return(handState);
    }
    private void WSAFingerPressed(UnityEngine.XR.WSA.Input.InteractionSourceState state)
    {
        CurrentHandState inputState = trackedHands.Find(CurrentInputState => CurrentInputState.HandId == state.source.id);

        if (inputState != null)
        {
            UpdateFromWSASource(inputState, state);
            OnFingerPressed(inputState);
        }
    }
Пример #7
0
    private void WSAFingerReleased(InteractionSourceState state)
    {
        CurrentHandState inputState = trackedHands.Find(CurrentInputState => CurrentInputState.HandId == state.source.id);

        if (inputState != null)
        {
            UpdateFromWSASource(inputState, state);
            OnFingerReleased(inputState);
        }
    }
Пример #8
0
    public void WSASourceLost(InteractionSourceState state)
    {
        if (state.source.kind == InteractionSourceKind.Hand)
        {
            CurrentHandState inputState = trackedHands.Find(CurrentInputState => CurrentInputState.HandId == state.source.id); // handID

            UpdateFromWSASource(inputState, state);
            SourceLost(inputState);
        }
    }
    private void UpdateFromWSASource(CurrentHandState currentInputState, UnityEngine.XR.WSA.Input.InteractionSourceState state)
    {
        currentInputState.HandId      = state.source.id;
        currentInputState.LastPressed = currentInputState.Pressed;
        currentInputState.Pressed     = state.anyPressed;
        state.properties.location.TryGetVelocity(out currentInputState.Velocity);

        currentInputState.SourceLossRisk = state.properties.sourceLossRisk;
        currentInputState.SourceLossMitigationDirection = state.properties.sourceLossMitigationDirection;
    }
Пример #10
0
    private void UpdateFromWSASource(CurrentHandState currentInputState, InteractionSourceState state)
    {
        currentInputState.HandId      = state.source.id;
        currentInputState.LastPressed = currentInputState.Pressed;
        currentInputState.Pressed     = state.selectPressed;
        state.sourcePose.TryGetVelocity(out currentInputState.Velocity);

        currentInputState.SourceLossRisk = state.properties.sourceLossRisk;
        currentInputState.SourceLossMitigationDirection = state.properties.sourceLossMitigationDirection;
    }
Пример #11
0
    private void WSAFingerPressed(InteractionSourcePressedEventArgs eventArgs)
    {
        InteractionSourceState state      = eventArgs.state;
        CurrentHandState       inputState = trackedHands.Find(CurrentInputState => CurrentInputState.HandId == state.source.id);

        if (inputState != null)
        {
            UpdateFromWSASource(inputState, state);
            OnFingerPressed(inputState);
        }
    }
Пример #12
0
 private void ThisPlayer_TrumpUpdated(CurrentHandState currentHandState)
 {
     ThisPlayer.CurrentHandState = currentHandState;
     drawingFormHelper.Trump();
     drawingFormHelper.TrumpMadeCardsShow();
     drawingFormHelper.ReDrawToolbar();
     if (ThisPlayer.CurrentHandState.IsFirstHand)
     {
         drawingFormHelper.Rank();
         drawingFormHelper.Starter();
     }
 }
    public void WSASourceEntered(UnityEngine.XR.WSA.Input.InteractionSourceState state)
    {
        // Track Hands
        if (state.source.kind == UnityEngine.XR.WSA.Input.InteractionSourceKind.Hand)
        {
            CurrentHandState inputState = new CurrentHandState();

            state.properties.location.TryGetPosition(out inputState.Position);

            UpdateFromWSASource(inputState, state);
            SourceEntered(inputState);
        }
    }
    public void WSASourceLost(UnityEngine.XR.WSA.Input.InteractionSourceState state)
    {
        if (state.source.kind == UnityEngine.XR.WSA.Input.InteractionSourceKind.Hand)
        {
            CurrentHandState inputState = trackedHands.Find(CurrentInputState => CurrentInputState.HandId == state.source.id); // handID

            if (inputState != null)
            {
                UpdateFromWSASource(inputState, state);
                SourceLost(inputState);
            }
        }
    }
Пример #15
0
        public TractorPlayer()
        {
            CurrentPoker      = new CurrentPoker();
            PlayerId          = Guid.NewGuid().ToString();
            CurrentGameState  = new GameState();
            CurrentHandState  = new CurrentHandState(CurrentGameState);
            CurrentTrickState = new CurrentTrickState();

            var instanceContext = new InstanceContext(this);
            var channelFactory  = new DuplexChannelFactory <ITractorHost>(instanceContext, "NetTcpBinding_ITractorHost");

            _tractorHost = channelFactory.CreateChannel();
        }
        //public void WSASourceEntered(InteractionSourceState state)
        //{
        //    // Track Hands
        //    if (state.source.kind == InteractionSourceKind.Hand)
        //    {
        //        CurrentHandState inputState = new CurrentHandState();

        //        state.properties.location.TryGetPosition(out inputState.Position);

        //        UpdateFromWSASource(inputState, state);
        //        SourceEntered(inputState);
        //    }
        //}

        public void WSASourceEntered(InteractionSourceDetectedEventArgs state)
        {
            // Track Hands
            if (state.state.source.kind == InteractionSourceKind.Hand)
            {
                CurrentHandState inputState = new CurrentHandState();

                state.state.sourcePose.TryGetPosition(out inputState.Position);

                UpdateFromWSASource(inputState, state.state);
                SourceEntered(inputState);
            }
        }
Пример #17
0
    public void WSASourceUpdate(InteractionSourceState state)
    {
        if (state.source.kind == InteractionSourceKind.Hand)
        {
            Vector3 newPosition;
            if (state.properties.location.TryGetPosition(out newPosition))
            {
                CurrentHandState inputState = trackedHands.Find(CurrentInputState => CurrentInputState.HandId == state.source.id); // handID

                UpdateFromWSASource(inputState, state);
                SourceUpdate(inputState, newPosition);
            }
        }
    }
    public CurrentHandState GetOppositeHandState(CurrentHandState hand)
    {
        CurrentHandState oppositeHand = null;

        for (int i = 0; i < trackedHands.Count; i++)
        {
            if (trackedHands[i] != hand)
            {
                oppositeHand = trackedHands[i];
                break;
            }
        }
        return(oppositeHand);
    }
Пример #19
0
        public void StartNextHand(PlayerEntity nextStarter)
        {
            UpdateGameState();
            this.CurrentHandState                = new CurrentHandState(this.CurrentGameState);
            this.CurrentHandState.Starter        = nextStarter.PlayerId;
            this.CurrentHandState.Rank           = nextStarter.Rank;
            this.CurrentHandState.LeftCardsCount = TractorRules.GetCardNumberofEachPlayer(this.CurrentGameState.Players.Count);

            log.Debug("start next hand, starter: " + this.CurrentHandState.Starter + " Rank: " + this.CurrentHandState.Rank.ToString());

            UpdatePlayersCurrentHandState();

            var currentHandId = this.CurrentHandState.Id;

            DistributeCards();
            if (this.CurrentHandState.Id != currentHandId)
            {
                return;
            }

            Thread.Sleep(5000);
            if (this.CurrentHandState.Trump != Suit.None)
            {
                DistributeLast8Cards();
            }

            else if (PlayersProxy.Count == 4)
            {
                //如果庄家TEAM亮不起,则庄家的下家成为新的庄家
                var nextStarter2 = CurrentGameState.GetNextPlayerAfterThePlayer(false, CurrentHandState.Starter);
                this.CurrentHandState.Starter = nextStarter2.PlayerId;
                this.CurrentHandState.Rank    = nextStarter2.Rank;
                log.Debug("starter team fail to make trump, next starter: " + this.CurrentHandState.Starter + " Rank: " + this.CurrentHandState.Rank.ToString());

                UpdatePlayersCurrentHandState();

                //10 seconds to make trump
                Thread.Sleep(10000);
                if (this.CurrentHandState.Trump != Suit.None)
                {
                    DistributeLast8Cards();
                }
                else if (PlayersProxy.Count == 4)
                {
                    //如果下家也亮不起,重新发牌
                    StartNextHand(nextStarter);
                }
            }
        }
Пример #20
0
    public void WSASourceUpdate(InteractionSourceUpdatedEventArgs eventArgs)
    {
        InteractionSourceState state = eventArgs.state;

        if (state.source.kind == InteractionSourceKind.Hand)
        {
            Vector3 newPosition;
            if (state.sourcePose.TryGetPosition(out newPosition))
            {
                CurrentHandState inputState = trackedHands.Find(CurrentInputState => CurrentInputState.HandId == state.source.id); // handID

                UpdateFromWSASource(inputState, state);
                SourceUpdate(inputState, newPosition);
            }
        }
    }
    public CurrentHandState GetHandState(HandednessEnum handedness, float minConfidence = 0.15f)
    {
        CurrentHandState handState = null;

        for (int i = 0; i < trackedHands.Count; i++)
        {
            if (trackedHands[i].Handedness == handedness)
            {
                if (trackedHands[i].HandednessConfidence >= minConfidence)
                {
                    handState = trackedHands[i];
                }
                break;
            }
        }
        return(handState);
    }
Пример #22
0
        public void NotifyCurrentHandState(CurrentHandState currentHandState)
        {
            bool trumpChanged   = false;
            bool newHandStep    = false;
            bool starterChanged = false;

            trumpChanged   = this.CurrentHandState.Trump != currentHandState.Trump || (this.CurrentHandState.Trump == currentHandState.Trump && this.CurrentHandState.TrumpExposingPoker < currentHandState.TrumpExposingPoker);
            newHandStep    = this.CurrentHandState.CurrentHandStep != currentHandState.CurrentHandStep;
            starterChanged = this.CurrentHandState.Starter != currentHandState.Starter;

            this.CurrentHandState = currentHandState;

            //断线重连后重画手牌
            if (this.IsTryingReenter || this.IsTryingResumeGame)
            {
                this.CurrentPoker       = (CurrentPoker)this.CurrentHandState.PlayerHoldingCards[this.MyOwnId].Clone();
                this.CurrentPoker.Rank  = this.CurrentHandState.Rank;
                this.CurrentPoker.Trump = this.CurrentHandState.Trump;
                if (AllCardsGot != null)
                {
                    AllCardsGot();
                }

                return;
            }

            this.CurrentPoker.Trump = this.CurrentHandState.Trump;

            if (trumpChanged)
            {
                if (TrumpChanged != null)
                {
                    TrumpChanged(currentHandState);
                }

                //resort cards
                if (currentHandState.CurrentHandStep > HandStep.DistributingCards)
                {
                    if (AllCardsGot != null)
                    {
                        AllCardsGot();
                    }
                }
            }

            if (currentHandState.CurrentHandStep == HandStep.BeforeDistributingCards)
            {
                StartGame();
            }
            else if (newHandStep)
            {
                if (currentHandState.CurrentHandStep == HandStep.DistributingCardsFinished)
                {
                    if (AllCardsGot != null)
                    {
                        AllCardsGot();
                    }
                }

                else if (currentHandState.CurrentHandStep == HandStep.DistributingLast8Cards)
                {
                    if (DistributingLast8Cards != null)
                    {
                        DistributingLast8Cards();
                    }
                }

                else if (currentHandState.CurrentHandStep == HandStep.DiscardingLast8Cards)
                {
                    if (DiscardingLast8 != null)
                    {
                        DiscardingLast8();
                    }
                }
                else if (currentHandState.CurrentHandStep == HandStep.DiscardingLast8CardsFinished)
                {
                    if (Last8Discarded != null)
                    {
                        Last8Discarded();
                    }
                }
                //player begin to showing card
                //开始出牌
                else if (currentHandState.CurrentHandStep == HandStep.Playing)
                {
                    if (AllCardsGot != null)
                    {
                        AllCardsGot();
                    }

                    if (ShowingCardBegan != null)
                    {
                        ShowingCardBegan();
                    }
                }

                else if (currentHandState.CurrentHandStep == HandStep.Ending)
                {
                    if (HandEnding != null)
                    {
                        HandEnding();
                    }
                }
                else if (currentHandState.CurrentHandStep == HandStep.SpecialEnding)
                {
                    if (SpecialEndingEvent != null)
                    {
                        SpecialEndingEvent();
                    }
                }
            }

            //显示庄家
            if (starterChanged || this.CurrentHandState.CurrentHandStep == HandStep.Ending || currentHandState.CurrentHandStep == HandStep.SpecialEnding)
            {
                if (StarterChangedEvent != null)
                {
                    StarterChangedEvent();
                }
            }

            //摸完牌,庄家亮不起主,所以换庄家
            if (currentHandState.CurrentHandStep == HandStep.DistributingCardsFinished && starterChanged)
            {
                this.CurrentPoker.Rank = this.CurrentHandState.Rank;
                if (StarterFailedForTrump != null)
                {
                    StarterFailedForTrump();
                }
            }

            if (this.isObserver &&
                this.CurrentHandState.PlayerHoldingCards != null &&
                this.CurrentHandState.PlayerHoldingCards.ContainsKey(this.PlayerId) &&
                this.CurrentHandState.PlayerHoldingCards[this.PlayerId] != null)
            {
                //即时更新旁观手牌
                this.CurrentPoker = this.CurrentHandState.PlayerHoldingCards[this.PlayerId];
                ObservePlayerByIDEvent();
            }
        }
 public void SourceUpdate(CurrentHandState inputState, Vector3 newPosition)
 {
     inputState.Position = newPosition;
     OnHandMoved(inputState);
 }
 public void SourceEntered(CurrentHandState inputState)
 {
     trackedHands.Add(inputState);
     OnHandEntered(inputState);
 }
Пример #25
0
        public void NotifyCurrentHandState(CurrentHandState currentHandState)
        {
            bool trumpChanged   = false;
            bool newHandStep    = false;
            bool starterChanged = false;

            trumpChanged   = this.CurrentHandState.Trump != currentHandState.Trump || (this.CurrentHandState.Trump == currentHandState.Trump && this.CurrentHandState.TrumpExposingPoker < currentHandState.TrumpExposingPoker);
            newHandStep    = this.CurrentHandState.CurrentHandStep != currentHandState.CurrentHandStep;
            starterChanged = this.CurrentHandState.Starter != currentHandState.Starter;

            this.CurrentHandState   = currentHandState;
            this.CurrentPoker.Trump = this.CurrentHandState.Trump;

            if (trumpChanged)
            {
                if (TrumpChanged != null)
                {
                    TrumpChanged(currentHandState);
                }

                //resort cards
                if (currentHandState.CurrentHandStep > HandStep.DistributingCards)
                {
                    if (AllCardsGot != null)
                    {
                        AllCardsGot();
                    }
                }
            }

            if (currentHandState.CurrentHandStep == HandStep.BeforeDistributingCards)
            {
                StartGame();
            }
            else if (newHandStep)
            {
                if (currentHandState.CurrentHandStep == HandStep.DistributingCardsFinished)
                {
                    if (AllCardsGot != null)
                    {
                        AllCardsGot();
                    }
                }

                else if (currentHandState.CurrentHandStep == HandStep.DiscardingLast8Cards)
                {
                    if (DiscardingLast8 != null)
                    {
                        DiscardingLast8();
                    }
                }

                else if (currentHandState.CurrentHandStep == HandStep.DistributingCardsFinished)
                {
                    if (AllCardsGot != null)
                    {
                        AllCardsGot();
                    }
                }

                else if (currentHandState.CurrentHandStep == HandStep.DiscardingLast8CardsFinished)
                {
                    if (Last8Discarded != null)
                    {
                        Last8Discarded();
                    }
                }
                //player begin to showing card
                //开始出牌
                else if (currentHandState.CurrentHandStep == HandStep.Playing)
                {
                    if (AllCardsGot != null)
                    {
                        AllCardsGot();
                    }

                    if (ShowingCardBegan != null)
                    {
                        ShowingCardBegan();
                    }
                }

                else if (currentHandState.CurrentHandStep == HandStep.Ending)
                {
                    if (HandEnding != null)
                    {
                        HandEnding();
                    }
                }
            }

            //出完牌,庄家亮不起主,所以换庄家
            if (currentHandState.CurrentHandStep == HandStep.DistributingCardsFinished && starterChanged)
            {
                this.CurrentPoker.Rank = this.CurrentHandState.Rank;
                if (StarterFailedForTrump != null)
                {
                    StarterFailedForTrump();
                }
            }
        }
 public bool IsPrimaryHand(CurrentHandState state)
 {
     return(trackedHands.Count > 0 && trackedHands[0] == state);
 }