コード例 #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();
            }
        }
コード例 #2
0
    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>();
 }
コード例 #5
0
    public CurrentHandState GetHandState(int idx)
    {
        CurrentHandState handState = null;

        if (trackedHands.Count > idx)
        {
            handState = trackedHands[idx];
        }
        return(handState);
    }
コード例 #6
0
    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);
        }
    }
コード例 #9
0
    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
ファイル: MainForm.cs プロジェクト: GrantDuan/Tractor_LAN
 private void ThisPlayer_TrumpUpdated(CurrentHandState currentHandState)
 {
     ThisPlayer.CurrentHandState = currentHandState;
     drawingFormHelper.Trump();
     drawingFormHelper.TrumpMadeCardsShow();
     drawingFormHelper.ReDrawToolbar();
     if (ThisPlayer.CurrentHandState.IsFirstHand)
     {
         drawingFormHelper.Rank();
         drawingFormHelper.Starter();
     }
 }
コード例 #13
0
    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);
        }
    }
コード例 #14
0
    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();
        }
コード例 #16
0
        //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);
            }
        }
    }
コード例 #18
0
    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);
            }
        }
    }
コード例 #21
0
    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();
            }
        }
コード例 #23
0
 public void SourceUpdate(CurrentHandState inputState, Vector3 newPosition)
 {
     inputState.Position = newPosition;
     OnHandMoved(inputState);
 }
コード例 #24
0
 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();
                }
            }
        }
コード例 #26
0
 public bool IsPrimaryHand(CurrentHandState state)
 {
     return(trackedHands.Count > 0 && trackedHands[0] == state);
 }