Пример #1
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));
        }
Пример #2
0
        private void OnPlayerTurnEnd(PlayerTurn sender, EventArgs e)
        {
            Console.WriteLine(sender.Player.Name + " ended turn.");

            PlayerTurnEnd?.Invoke(sender, e);

            if (++_currentPlayerTurnIndex == _players.Count)
            {
                End();
            }
            else
            {
                NewPlayerTurn();
            }
        }
Пример #3
0
    public IEnumerator Attack(Vector2Int pos)
    {
        PlayerTurnEnd?.Invoke();
        myAnim.SetBool("Shoot", true);
        yield return(new WaitForSecondsRealtime(time));

        myAnim.SetBool("Shoot", false);
        var tmp = Instantiate(plate, (Vector3Int)(currentPos + pos), Quaternion.identity).GetComponent <vinyl>();

        tmp.dir        = pos;
        tmp.MM         = MM;
        tmp.time       = time;
        PlayerTurnEnd += tmp.MoveVinyl;
        MM.pros.Add(tmp);
    }
Пример #4
0
    public IEnumerator MoveToPosition(Vector2 position, float timeToMove)
    {
        PlayerTurnEnd?.Invoke();
        StartCoroutine(MoveToPositionCam((Vector3Int)currentPos, timeToMove, Camera.main.transform));
        yield return(new WaitUntil(() => movementEnded));

        movementEnded = false;
        myAnim.SetBool("Move", true);
        yield return(new WaitForSecondsRealtime(timeToMove / 2));

        transform.position += (Vector3)(position / 2);
        yield return(new WaitForSecondsRealtime(timeToMove / 2));

        transform.position += (Vector3)(position / 2);
        movementEnded       = true;
    }
Пример #5
0
 public void EndPlayerTurn()
 {
     PlayerTurnEnd?.Invoke();
 }