示例#1
0
        private FuuroGroup HandleAnkan(Player currentPlayer, string tileName)
        {
            tileName = tileName.Replace('0', '5');

            FuuroGroup fuuroGroup = new FuuroGroup();

            fuuroGroup.type = FuuroType.ankan;

            if (currentPlayer == player)
            {
                IEnumerable <Tile> tiles = player.hand.Where(t => t.GeneralName == tileName).ToList();
                fuuroGroup.AddRange(tiles);
                player.hand.RemoveRange(tiles);
            }
            else
            {
                if (tileName[0] == '5' && tileName[1] != 'z') // 暗杠中有红牌
                {
                    fuuroGroup.Add(new Tile(tileName));
                    fuuroGroup.Add(new Tile(tileName));
                    fuuroGroup.Add(new Tile(tileName));
                    fuuroGroup.Add(new Tile("0" + tileName[1]));
                }
                else
                {
                    for (var i = 0; i < 4; i++)
                    {
                        fuuroGroup.Add(new Tile(tileName));
                    }
                }
            }

            currentPlayer.fuuro.Add(fuuroGroup);
            return(fuuroGroup);
        }
示例#2
0
        private FuuroGroup HandleKakan(Player currentPlayer, string tileName)
        {
            FuuroGroup fuuroGroup = currentPlayer.fuuro.First(g => g.type == FuuroType.pon && g.All(t => t.GeneralName == tileName.Replace('0', '5')));

            fuuroGroup.type = FuuroType.kakan;

            if (currentPlayer == player)
            {
                Tile tile = player.hand.First(t => t.GeneralName == tileName.Replace('0', '5'));
                player.hand.Remove(tile);
                fuuroGroup.Add(tile);
            }
            else
            {
                fuuroGroup.Add(new Tile(tileName));
            }

            return(fuuroGroup);
        }
示例#3
0
        private FuuroGroup HandleFuuro(Player currentPlayer, int type, IEnumerable <string> tiles, IEnumerable <int> froms)
        {
            FuuroGroup fuuroGroup = new FuuroGroup();

            switch (type)
            {
            case 0:
                fuuroGroup.type = FuuroType.chii;
                break;

            case 1:
                fuuroGroup.type = FuuroType.pon;
                break;

            case 2:
                fuuroGroup.type = FuuroType.minkan;
                break;
            }

            foreach (var(tileName, from) in tiles.Zip(froms, Tuple.Create))
            {
                if (NormalizedPlayerId(from) != currentPlayer.id) // 从别人那里拿来的牌
                {
                    fuuroGroup.Add(gameData.lastTile);
                    gameData.lastTile.IsTakenAway = true;
                }
                else if (currentPlayer == player) // 自己的手牌
                {
                    Tile tile = player.hand.First(t => t.OfficialName == tileName);
                    player.hand.Remove(tile);
                    fuuroGroup.Add(tile);
                }
                else
                {
                    fuuroGroup.Add(new Tile(tileName));
                }
            }

            currentPlayer.fuuro.Add(fuuroGroup);
            return(fuuroGroup);
        }
示例#4
0
        private FuuroGroup HandleFuuro(Player currentPlayer, int m)
        {
            int type, kui;

            int[] hai = new int[4];
            decodeMeld(m, out type, out kui, out hai[0], out hai[1], out hai[2], out hai[3]);

            FuuroGroup tiles = new FuuroGroup();

            switch (type)
            {
            case 3:
                tiles.type = FuuroType.chii;
                break;

            case 1:
                tiles.type = FuuroType.pon;
                break;

            case 2:
                tiles.type = FuuroType.minkan;
                break;

            case 4:
                tiles.type = FuuroType.ankan;
                gameData.remainingTile--;
                break;

            case 5:
                tiles.type = FuuroType.kakan;
                gameData.remainingTile--;
                break;
            }

            foreach (int num in hai)
            {
                if (num != -1)
                {
                    tiles.Add(new Tile(num));
                    if (gameData.lastTile != null && gameData.lastTile.Id == num)
                    {
                        gameData.lastTile.IsTakenAway = true;
                    }
                }
            }

            if (kui != 0) // 从别人处拿到的牌
            {
                var takenTile = new Tile(hai[3 - kui]);
                takenTile.IsTakenAway = true;
                var fromPlayer = gameData.players[(kui + currentPlayer.id) % 4];
                if (!fromPlayer.graveyard.Exists(t => t.Id == takenTile.Id))
                {
                    fromPlayer.graveyard.Add(takenTile);
                    gameData.remainingTile--;
                }
            }

            currentPlayer.fuuro.Add(tiles);

            // 如果加杠则移除原来的碰
            if (tiles.type == FuuroType.kakan)
            {
                currentPlayer.fuuro.RemoveAll(g => g.type == FuuroType.pon && g.All(t => t.GeneralId == tiles[0].GeneralId));
            }

            if (currentPlayer == player)
            {
                player.hand.RemoveWhere((tile) => tiles.Exists((_tile) => tile.Id == _tile.Id));
            }

            return(tiles);
        }