예제 #1
0
        public void NextPlayersTurn()
        {
            List <eActionType> playerActions = new List <eActionType>(); // Stores possible player actions

            // Loop until isPlaying player who waits for turn
            do
            {
                _activePlayer = (_activePlayer + 1) % (PlayerRank.GetLength(0));
            }while (!ActivePlayer.IsPlayering && ActivePlayer.NextAction.Peek() == eActionType.WaitingForTurn);

            if (_activePlayer == 0)
            {
                this.Statistics.Lap += 1;
            }

            NextPlayer?.Invoke(ActivePlayer);

            // Should only dequeue waiting!?
            ActivePlayer.NextAction.Dequeue();

            // Find possible actions till next turn or NIL
            do
            {
                playerActions.Clear();
                do
                {
                    playerActions.Add(ActivePlayer.NextAction.Dequeue());
                }while (!(ActivePlayer.NextAction.Count == 0 || ActivePlayer.NextAction.Peek() == eActionType.WaitingForTurn));
                ActivePlayer.onDelegateControl(new DelegateEventArgs(playerActions.ToArray()));
            }while (!(ActivePlayer.NextAction.Count == 0 || ActivePlayer.NextAction.Peek() == eActionType.WaitingForTurn));

            // Enqueue next default action, isnt't needed
            if (ActivePlayer.IsPlayering)
            {
                if (ActivePlayer.NextAction.Count == 0)
                {
                    ActivePlayer.NextAction.Enqueue(eActionType.WaitingForTurn);
                    ActivePlayer.NextAction.Enqueue(eActionType.Move);
                }

                // Should notify end turn
                if (Settings.END_TURN_EVENT)
                {
                    ActivePlayer.onDelegateControl(new DelegateEventArgs(eActionType.EndTurn));
                }
            }

            ActivePlayer.DoublesCount = 0;
        }
예제 #2
0
        private void InitPlayers()
        {
            System.Collections.SortedList playerRankSort = new System.Collections.SortedList();
            int playerSortKey;

            // Initialize without rank
            for (var i = 0; i < PlayerRank.Length; i++)
            {
                PlayerRank[i].Initialize(this, i);
            }

            // Give every Player On dial for rank
            foreach (var p in PlayerRank)
            {
                _activePlayer = p.Index;
                NextPlayer?.Invoke(ActivePlayer);
                DiceRollResult result = p.DelegateDiceRoll();
                playerSortKey = result.DiceSum * 10;
                while (playerRankSort.ContainsKey(-playerSortKey))
                {
                    playerSortKey += 1;
                }
                playerRankSort.Add(-playerSortKey, p); // negativ for sorting
            }


            playerRankSort.Values.CopyTo(PlayerRank, 0);

            // Initialize Part 2 with rank
            for (ushort i = 0; i < PlayerRank.Length; i++)
            {
                PlayerRank[i].Index = i;
            }

            _activePlayer = -1;

            RaisePlayerRankChanged();
        }
예제 #3
0
 protected virtual void OnNextPlayer(NextPlayerEventArgs e)
 {
     NextPlayer?.Invoke(this, e);
 }