コード例 #1
0
        // Eliminates a player
        //
        // Removes from active player list, adds to eliminated player list,
        // returns  all tiles to the draw pile
        public void eliminatePlayer(string color)
        {
            SPlayer p = activePlayers.Find(x => color == x.getColor());

            if (p == null)
            {
                throw new TsuroException("Cannot find an active player with color " + color + " to eliminate.");
            }
            if ((p.playerState != SPlayer.State.Placed) && (p.playerState != SPlayer.State.Playing))
            {
                throw new TsuroException("Player is being eliminated before having placed a start pawn.");
            }


            // Add eliminated player's tiles to draw pile, and remove from his/her hand
            if (p.getHandSize() != 0)
            {
                List <Tile> hand = p.getHand();
                for (int i = 0; i < hand.Count; i++)
                {
                    Tile tempTile = hand[i];
                    p.removeTileFromHand(tempTile);
                    addTileToDrawPile(tempTile);
                    i--;
                }
            }


            // Eliminated player is dragon tile holder
            if (dragonTileHolder != null && dragonTileHolder.getColor() == p.getColor())
            {
                // Get index of eliminated player in active players list
                int currIndex = activePlayers.FindIndex(x => p.getColor() == x.getColor());;

                // Pass dragon tile to next player with less than 3 tiles in hand
                SPlayer nextPlayer;
                do
                {
                    currIndex += 1;
                    nextPlayer = activePlayers[(currIndex) % activePlayers.Count];
                } while (nextPlayer.getHandSize() >= 3);

                if (nextPlayer.getColor() == p.getColor())
                {
                    // Cannot find player with fewer than 3 tiles in hand
                    dragonTileHolder = null;
                }
                else
                {
                    dragonTileHolder = nextPlayer;
                }
            }

            eliminatedPlayers.Add(p);
            activePlayers.Remove(p);
            p.eliminate();
        }
コード例 #2
0
ファイル: Board.cs プロジェクト: leelouisa120/tsuro
        // Eliminates a player by removing from active player list, adding to
        // eliminated player list, and returning all tiles to the draw pile
        public void eliminatePlayer(SPlayer p)
        {
            if ((p.playerState != SPlayer.State.Placed) && (p.playerState != SPlayer.State.Playing))
            {
                throw new Exception("Player is being eliminated before having placed a start pawn.");
            }
            else if (!onBoard.Contains(p))
            {
                throw new Exception("Trying to eliminate a non-active player.");
            }


            // Add eliminated player's tiles to draw pile, and remove from his/her hand
            if (p.getHandSize() != 0)
            {
                List <Tile> hand     = p.returnHand();
                int         handSize = hand.Count;
                for (int i = 0; i < hand.Count; i++)
                {
                    Tile tempTile = hand[i];
                    p.removeTileFromHand(tempTile);
                    addTileToDrawPile(tempTile);
                    i--;
                }
            }

            int onBoardIndex = onBoard.FindIndex(x => p.returnColor() == x.returnColor());

            if (dragonTileHolder != null && dragonTileHolder.returnColor() == p.returnColor())
            {
                // Pass dragon tile to next player with less than 3 tiles in hand
                int     currIndex = onBoardIndex;
                SPlayer nextPlayer;
                do
                {
                    currIndex += 1;
                    nextPlayer = onBoard[(currIndex) % onBoard.Count];
                } while (nextPlayer.getHandSize() >= 3);

                if (nextPlayer.returnColor() == p.returnColor())
                {
                    dragonTileHolder = null;
                }
                else
                {
                    dragonTileHolder = nextPlayer;
                }
            }

            eliminated.Add(p);
            onBoard.Remove(p);
            p.eliminate();
        }