예제 #1
0
        private void ProcessSequenceCompleted()
        {
            StoredMoves.Add(CurrentPieces.Select(x => x).ToList());

            if (StoredMoves.Count >= MovesAllowedPerTurn)
            {
                foreach (var currentMoves in StoredMoves)
                {
                    SequenceCompleted?.Invoke(currentMoves.ToArray());
                    LogUsedPieces(currentMoves);

                    foreach (var square in currentMoves)
                    {
                        if (square.OnCollection != null)
                        {
                            square.OnCollection.OnCollection();
                        }
                        square.DestroyPiece();
                    }
                }
                MoveCompleted?.Invoke();

                StoredMoves.Clear();
                ResetMovesAllowedPerTurn();
            }

            CurrentPieces.Clear();
            SelectedPiecesChanged?.Invoke(CurrentPieces);
        }
예제 #2
0
        public void Start()
        {
            GameStarted.Raise(this, new BigTwoEventArgs());

            DealHands();

            var activePlayerIndex = 0;

            PlayedCards activeCards = null;

            // while all players have at least one card the game continues
            while (players.All(p => p.CardCount > 0))
            {
                IPlayer activePlayer = players[activePlayerIndex];

                PlayerTurnStart.Raise(this, new BigTwoPlayerEventArgs(activePlayer));

                // If the active cards belong to the active player, It means that
                // all other players have passed meaning this player has won the sequence.
                if (activeCards != null && activePlayer == activeCards.Player)
                {
                    // clear the active card to start a new sequence.
                    SequenceCompleted.Raise(this, new BigTwoPlayerEventArgs(activeCards.Player));
                    activeCards = null;
                }

                PlayedCards nextCards = activePlayer.PlayTurn(activeCards);

                PlayerPlayedTurn.Raise(this, new BigTwoPlayerHandEventArgs(activePlayer, nextCards));

                // null is a passed turn
                if (nextCards != null)
                {
                    // Ensure the cards the player is trying to play are valid
                    nextCards.Validate(activeCards);

                    activeCards = nextCards;

                    // Remove the played cards from the players hand
                    activePlayer.RemoveCards(nextCards);
                }


                // Advance to next player
                activePlayerIndex++;

                if (activePlayerIndex >= players.Count)
                {
                    activePlayerIndex = 0;
                }

                PlayerTurnEnd.Raise(this, new BigTwoPlayerEventArgs(activePlayer));
            }

            // Get the winner and notify everyone that the game is over!
            IPlayer winner = players.Single(p => p.CardCount == 0);

            GameCompleted.Raise(this, new BigTwoPlayerEventArgs(winner));
        }
예제 #3
0
 private void EndSequence()
 {
     SequenceCompleted?.Invoke();
     Dispose();
 }