Exemplo n.º 1
0
    public List <GemModel> Feed()
    {
        feedingGemModels.Clear();

        var matchingTypes = Model.MatchingTypes;

        var spawnerGemModels =
            from GemModel gemModel in Model.GemModels
            where gemModel is SpawnerGemModel
            select gemModel;

        foreach (SpawnerGemModel spawnerGemModel in spawnerGemModels)
        {
            var gravity         = GetGravityModel(spawnerGemModel.Position).vector;
            var spawneePosition = Position.Get(spawnerGemModel.Position, gravity[0], gravity[1]);
            if (GetGemModel(spawneePosition).Type == GemType.EmptyGem)
            {
                var spawneeGemModel = GemModelFactory.Get(GemType.EmptyGem, spawneePosition);
                SetGemModel(spawneeGemModel);
                spawneeGemModel.Type = matchingTypes[RANDOM.Next(matchingTypes.Count)];
                feedingGemModels.Add(spawneeGemModel);
            }
        }

        return(feedingGemModels);
    }
Exemplo n.º 2
0
    GemModel CopyAsSpecial(Int64 replacerID, GemModel targetGemModel, string specialKey, int endurance)
    {
        var copiedGemModel = GemModelFactory.Get(
            ReadGemType(targetGemModel.Type, specialKey),
            targetGemModel.Position
            );

        copiedGemModel.id         = targetGemModel.id;
        copiedGemModel.replacedBy = replacerID;
        SetGemModel(copiedGemModel);
        return(copiedGemModel);
    }
Exemplo n.º 3
0
    GemModel CopyAsBlock(Int64 markerID, GemModel targetGemModel)
    {
        var copiedGemModel = GemModelFactory.Get(GemType.BlockedGem, targetGemModel.Position);

        copiedGemModel.id             = targetGemModel.id;
        copiedGemModel.markedBy       = markerID;
        copiedGemModel.Type           = targetGemModel.Type;
        copiedGemModel.specialKey     = targetGemModel.specialKey;
        copiedGemModel.endurance      = targetGemModel.endurance;
        copiedGemModel.Position       = targetGemModel.Position;
        copiedGemModel.positionBefore = targetGemModel.positionBefore;
        SetGemModel(copiedGemModel);
        return(copiedGemModel);
    }
Exemplo n.º 4
0
    public BrokenGemInfo Break(Position targetPosition, Int64 markerID)
    {
        brokenGemInfo.Clear();

        if (IsMovableTile(targetPosition))
        {
            var targetGemModel = GetGemModel(targetPosition);
            if (targetGemModel.markedBy == markerID || targetGemModel.replacedBy == markerID)
            {
                var newGemModel = GemModelFactory.Get(GemType.EmptyGem, targetGemModel.Position);
                newGemModel.preservedFromFall = Model.currentTurn + 1;
                SetGemModel(newGemModel);

                brokenGemInfo.gemModel = targetGemModel;
            }
        }

        return(brokenGemInfo);
    }
Exemplo n.º 5
0
    public BrokenGemInfo BreakEmptyBlocks(Int64 markerID)
    {
        brokenGemInfo.Clear();

        var emptyBlockGemModels =
            from GemModel gemModel in Model.GemModels
            where gemModel is IBlockable &&
            (gemModel.Type == GemType.EmptyGem || gemModel.Type == GemType.Nil) &&
            gemModel.markedBy == markerID
            select gemModel;

        foreach (var gemModel in emptyBlockGemModels)
        {
            var newGemModel = GemModelFactory.Get(GemType.EmptyGem, gemModel.Position);
            newGemModel.preservedFromFall = Model.currentTurn;
            SetGemModel(newGemModel);

            brokenGemInfo.gemModels.Add(gemModel);
        }

        return(brokenGemInfo);
    }
Exemplo n.º 6
0
    public List <MatchedLineInfo> Match()
    {
        matchedLineInfos.Clear();

        var matchLineModels    = Model.positiveMatchLineModels;
        var matchableGemModels =
            from GemModel gemModel in Model.GemModels
            where gemModel is IMovable &&
            gemModel.Type != GemType.EmptyGem &&
            IsMovableTile(gemModel.Position) &&
            Model.currentTurn > gemModel.preservedFromMatch &&
            !IsFalling(gemModel)
            select gemModel;

        foreach (var matchableGemModel in matchableGemModels)
        {
            foreach (var matchLineModel in matchLineModels)
            {
                var matchedGemModels = GetAnyMatches(matchableGemModel, matchLineModel);
                if (matchedGemModels.Count == 0)
                {
                    continue;
                }

                var newMatchLineInfo = new MatchedLineInfo()
                {
                    gemModels       = matchedGemModels.ToList(),
                    matchLineModels = new List <MatchLineModel>()
                    {
                        matchLineModel
                    }
                };

                // Merge if the matched line has intersection.
                foreach (var matchedLineInfo in matchedLineInfos)
                {
                    if (matchedLineInfo.gemModels.Intersect(newMatchLineInfo.gemModels).Any())
                    {
                        matchedLineInfo.Merge(newMatchLineInfo);
                        break;
                    }
                }

                if (!newMatchLineInfo.isMerged)
                {
                    matchedLineInfos.Add(newMatchLineInfo);
                }
            }
        }

        foreach (var matchedLineInfo in matchedLineInfos)
        {
            // foreach (var matchLineModel in matchedLineInfo.matchLineModels)
            // {
            // UnityEngine.Debug.Log(matchLineModel.ToString());
            // }
            var latestGemModel = matchedLineInfo.gemModels.OrderByDescending(gemModel => gemModel.sequence).FirstOrDefault();

            foreach (var matchedGemModel in matchedLineInfo.gemModels)
            {
                var newGemType = GemType.EmptyGem;
                if (matchedGemModel == latestGemModel)
                {
                    newGemType = ReadGemType(
                        latestGemModel.Type,
                        ReadSpecialKey(matchedLineInfo.matchLineModels, latestGemModel.PositionVector)
                        );
                }

                // Create a new gem model either empty or merged.
                var newGemModel = GemModelFactory.Get(newGemType, matchedGemModel.Position);
                SetGemModel(newGemModel);

                if (newGemType != GemType.EmptyGem)
                {
                    // UnityEngine.Debug.Log("newGemModel : " + newGemModel.ToString());
                    matchedLineInfo.newAdded       = newGemModel;
                    newGemModel.preservedFromBreak = Model.currentTurn + 1;
                }
                newGemModel.preservedFromFall = Model.currentTurn;
            }
        }

        return(matchedLineInfos);
    }
Exemplo n.º 7
0
    public override void Setup()
    {
        allwayMatchLineModels = new List <MatchLineModel> {
            new MatchLineModel(-2, 0, 3, 1),
            new MatchLineModel(0, -2, 1, 3),
            new MatchLineModel(-1, -1, 2, 2),
        };

        positiveMatchLineModels = new List <MatchLineModel> {
            new MatchLineModel(0, 0, 5, 1),
            new MatchLineModel(0, 0, 1, 5),
            new MatchLineModel(0, 0, 4, 1),
            new MatchLineModel(0, 0, 1, 4),
            new MatchLineModel(0, 0, 2, 2),
            new MatchLineModel(0, 0, 3, 1),
            new MatchLineModel(0, 0, 1, 3),
        };

        offsetsCanSwap = new List <int[]> {
            new int[] { 0, 1 },
            new int[] { 0, -1 },
            new int[] { 1, 0 },
            new int[] { -1, 0 }
        };

        Position.Setup(levelModel);

        matchingTypes = new List <GemType>();
        foreach (var gemTypeAvailable in levelModel.gemTypesAvailable)
        {
            matchingTypes.Add((GemType)gemTypeAvailable);
        }

        var gems      = levelModel.gems;
        var tiles     = levelModel.tiles;
        var gravities = levelModel.gravities;
        var count     = 0;

        historyOfGemModels = new List <GemModel[, ]>();

        gemModels     = new GemModel[Rows, Cols];
        tileModels    = new TileModel[Rows, Cols];
        gravityModels = new GravityModel[Rows, Cols];
        for (var row = Rows - 1; row >= 0; row -= 1)
        {
            for (var col = 0; col < Cols; col += 1)
            {
                var gemIndex = row * Cols + col;

                var colByCount = count % Cols;
                var rowByCount = count / Cols;
                var position   = Position.Get(colByCount, rowByCount);
                gemModels[rowByCount, colByCount] = GemModelFactory.Get(
                    (GemType)gems[gemIndex], position
                    );
                tileModels[rowByCount, colByCount] = TileModelFactory.Get(
                    (TileType)tiles[gemIndex], position
                    );
                gravityModels[rowByCount, colByCount] = GravityModelFactory.Get(
                    (GravityType)gravities[gemIndex], position
                    );
                count++;
            }
        }
    }