Example #1
0
 public MovementProposed(MovementType type, GameObject obj, TilePoint from, TilePoint to)
 {
     Type  = type;
     Piece = obj;
     From  = from;
     To    = to;
 }
Example #2
0
 /// <summary>
 /// 从建筑区域随机获取一个移动格子(REMARK:如果当前目标已经在建筑区域内,则根据距离作为权重随机获取,否则直接随机获取。)
 /// </summary>
 /// <param name="inBuildArea"></param>
 /// <returns></returns>
 private TilePoint RandomMoveGrid(bool inBuildArea)
 {
     if (inBuildArea)
     {
         if (_buildArea.Count == 1)
         {
             return(_buildArea[0]);
         }
         else
         {
             //  权重算法:距离越大(权重越低、距离越近权重越高、距离0跳过)
             int maxDis = _buildArea.Count - 1;
             List <TilePoint> randomList = new List <TilePoint>();
             TilePoint        selfPos    = Entity.GetTilePos();
             foreach (var grid in _buildArea)
             {
                 int dis = Mathf.Abs(selfPos.x - grid.x) + Mathf.Abs(selfPos.y - grid.y);
                 if (dis > 0)
                 {
                     int weight = maxDis + 1 - dis;
                     for (int i = 0; i < weight; i++)
                     {
                         randomList.Add(grid);
                     }
                 }
             }
             return(randomList[BattleRandom.Range(0, randomList.Count)]);
         }
     }
     else
     {
         return(_buildArea[BattleRandom.Range(0, _buildArea.Count)]);
     }
 }
Example #3
0
    /// <summary>
    /// 开始去建造
    /// </summary>
    /// <param name="targeter"></param>
    public void BuildStart(TileEntity targeter)
    {
        Assert.Should(_state == WorkerState.Free || _state == WorkerState.FinishWork);
        Assert.Should(targeter != null);

        this.enabled = true;

        _buildTargeter       = targeter;
        _buildindLastTilePos = new TilePoint(9999, 9999);
        if (_buildArea == null)
        {
            _buildArea = new List <TilePoint>();
        }

        //  当前休息中则从工人小屋出来 回家中则停止移动
        if (_state == WorkerState.Free)
        {
            Entity.tileOffset = new Vector2(0.0f, 0.0f);
            Entity.SetTilePosition(GetDoorOfTheWorkerHouse());
            Entity.ShowEntity();
        }
        else
        {
            ActorMoveComponent move = Entity.GetComponent <ActorMoveComponent>();
            Assert.Should(move != null);
            move.OnMoveCompleteEvent -= OnMoveCompleteEvent;
            move.CancelMove();
        }
        //  设置上班状态 && 开始移动(3倍速移动)
        RefreshBuildGridArea();
        _state = WorkerState.Working;
        DoActionMove(RandomMoveGrid(IsInBuildArea()), 3.0f);
    }
 public UseItemPacket(int time, int object_id, byte slot_id, TilePoint item_use_position)
 {
     this.Time = time;
     this.ObjectId = object_id;
     this.SlotId = slot_id;
     this.ItemUsePosition = item_use_position;
 }
Example #5
0
 private void OnMoveCompleteEvent(ActorMoveComponent moveComp)
 {
     moveComp.OnMoveCompleteEvent -= OnMoveCompleteEvent;
     if (_state == WorkerState.Working)
     {
         //  移动结束如果在建造区域内则开始建造(否则说明建筑移动过了?则继续移动)
         if (IsInBuildArea())
         {
             DoActionBuild();
         }
         else
         {
             DoActionMove(RandomMoveGrid(false));
         }
     }
     else if (_state == WorkerState.FinishWork)
     {
         TilePoint doorPos = GetDoorOfTheWorkerHouse();
         if (Entity.GetTilePos() != doorPos)
         {
             //  回家时(小屋搬家了(233
             DoActionMove(doorPos);
         }
         else
         {
             //  回到家(
             Entity.HideEntity();
             _state       = WorkerState.Free;
             this.enabled = false;
         }
     }
 }
Example #6
0
    /// <summary>
    /// 从目标列表里根据距离时间等权重筛选最有目标
    /// </summary>
    /// <param name="targeters"></param>
    /// <param name="_targetPos"></param>
    /// <param name="_targetRoute"></param>
    /// <returns></returns>
    private List <TileEntity> SelectTargeters(List <TileEntity> targeters, out TilePoint?_targetPos, out LinkedList <IMoveGrid> _targetRoute)
    {
        _targetPos   = null;
        _targetRoute = null;

        //  先在监视范围内寻找时间消耗最低的目标
        IsoGridTarget targetInfos = FindTargetsNearestTimeCost(Attacker, targeters);

        if (targetInfos != null)
        {
            Assert.Should(targetInfos.MoveRoute != null);
            if (targetInfos.MoveRoute.Count > 1)
            {
                _targetRoute = targetInfos.MoveRoute;
            }
            return(AuxConvertToList(targetInfos.Targeter));
        }

        //  未找到则直接寻找直线最近的目标
        var     nearest_targets = FindTargetsNearestLinear(Attacker.GetCurrentPositionCenter(), targeters, 1);
        var     targeter        = nearest_targets[0];
        Vector2 p = targeter.GetCurrentPositionCenter();
        //int randomOffset = Mathf.Min((int)(targeter.blockingRange / 2.0f + Attacker.model.range), targeter.width / 2);  //  TODO:如果该值过大导致移动结束后目标不在攻击范围内(则会导致重新锁定目标) 则需要酌情调整该值算法
        int randomOffset = Mathf.Min((int)Attacker.model.range, targeter.width / 2);
        int x            = (int)p.x;
        int y            = (int)p.y;

        if (randomOffset > 0)
        {
            x = BattleRandom.Range(x - randomOffset, x + randomOffset);
            y = BattleRandom.Range(y - randomOffset, y + randomOffset);
        }
        _targetPos = new TilePoint(x, y);
        return(nearest_targets);
    }
Example #7
0
    public static Path <TilePoint> FindPath(
        TilePoint start,
        TilePoint destination)
    {
        var closed = new HashSet <TilePoint>();
        var queue  = new PriorityQueue <double, Path <TilePoint> >();

        queue.Enqueue(0, new Path <TilePoint>(start));

        while (!queue.IsEmpty)
        {
            var path = queue.Dequeue();

            if (closed.Contains(path.LastStep))
            {
                continue;
            }
            if (path.LastStep.Equals(destination))
            {
                return(path);
            }

            closed.Add(path.LastStep);
            //Debug.Log("path " + path.LastStep);
            foreach (TilePoint n in path.LastStep.AllNeighbours)
            {
                double d       = distance(path.LastStep, n);
                var    newPath = path.AddStep(n, d);
                queue.Enqueue(newPath.TotalCost + estimate(n, destination),
                              newPath);
            }
        }

        return(null);
    }
 public UseItemPacket(int time, int object_id, byte slot_id, TilePoint item_use_position)
 {
     this.Time            = time;
     this.ObjectId        = object_id;
     this.SlotId          = slot_id;
     this.ItemUsePosition = item_use_position;
 }
Example #9
0
    //Making the AI recognize possible matches after the player turn
    IEnumerator ReadyEnemyTurn()
    {
        yield return(new WaitForSeconds(2f));

        Debug.Log("Enemy turn start");
        Dictionary <TilePoint, Data.TileTypes> st = FindHint();

        List <TilePoint> tileMatchList = new List <TilePoint>();

        foreach (KeyValuePair <TilePoint, Data.TileTypes> item in st)
        {
            tileMatchList.Add(item.Key);
        }

        // Divide size of match list in 2 to get actual number of matches
        int firstMatchIndex = tileMatchList.Count / 2;

        // Choose one of those matches randomly
        int randomMatchIndex = Random.Range(0, firstMatchIndex);

        // Get the first tile coordinate of one of those random matches
        TilePoint tile1 = tileMatchList[randomMatchIndex * 2];

        // Get the second tile coordinate of one of those random matches
        TilePoint tile2 = tileMatchList[randomMatchIndex * 2 + 1];

        MatchItem item1 = FindTile(tile1);
        MatchItem item2 = FindTile(tile2);

        isDoing = true;
        DoSwapTile(item1, item2);
        yield return(StartCoroutine(CheckMatch3Tile(0.5f, item1, item2)));

        Debug.Log("AI turn end");
    }
Example #10
0
    private void TryMove()
    {
        //  尝试移动之前先初始化军营(如果尚未初始化)
        if (!InitCamp())
        {
            m_timePassed = 3.0f;   //  REMARK:没军营?老实呆着吧o.o
            return;
        }

        //  尝试移动
        if (m_passableGrids != null && m_passableGrids.Count > 0)
        {
            TilePoint grid = RandomGrid();
            if (grid == Entity.GetTilePos())
            {
                DoActionIdle();
                return;
            }
            if (!DoActionMove(grid))
            {
                DoActionIdle();
                return;
            }
        }
        else
        {
            DoActionIdle();
        }
    }
Example #11
0
 private void MouseTileHover(TilePoint tp)
 {
     if (OnMouseTileHover != null)
     {
         OnMouseTileHover(this, tp);
     }
 }
Example #12
0
        public PointerResult Up(int mapId, TilePoint tp, MouseButtons button)
        {
            lastTilePointPosition = null;
            isMouseDown           = false;

            return(null);
        }
Example #13
0
 void TileManagerOnMouseTileHover(object sender, TilePoint tp)
 {
     if (OnMouseTileHover != null)
     {
         OnMouseTileHover(sender, tp);
     }
 }
Example #14
0
 public InventorySwapPacket(int time, TilePoint position, SlotObject slot_object1, SlotObject slot_object2)
 {
     this.Time        = time;
     this.Position    = position;
     this.SlotObject1 = slot_object1;
     this.SlotObject2 = slot_object2;
 }
 public InventorySwapPacket(int time, TilePoint position, SlotObject slot_object1, SlotObject slot_object2)
 {
     this.Time = time;
     this.Position = position;
     this.SlotObject1 = slot_object1;
     this.SlotObject2 = slot_object2;
 }
    public void InBetweenTwoSpacesApart_ReturnInBetweenSpace()
    {
        var tilesBetween = new TilePoint(0, 0).InBetween(new TilePoint(0, 2));

        Assert.AreEqual(1, tilesBetween.Count);
        Assert.AreEqual(tilesBetween[0], new TilePoint(0, 1));
    }
Example #17
0
    public static void GetLevelQuadkeys(string quadKey, int fromLevel, int toLevel, List <TilePoint> quadkeylist)
    {
        if (fromLevel + 1 > toLevel)
        {
            return;
        }

        for (int i = 0; i < COUNT_PER_LEVEL; i++)
        {
            TilePoint tempTilePoint = new TilePoint();
            tempTilePoint.QuadKey = string.Format("{0}{1}", quadKey, i);
            if ((fromLevel + 1) != toLevel)
            {
                GetLevelQuadkeys(tempTilePoint.QuadKey, fromLevel + 1, toLevel, quadkeylist);
            }
            else
            {
                int tileX; int tileY;
                int level;
                QuadKeyToTileXY(tempTilePoint.QuadKey, out tileX, out tileY, out level);
                UnityEngine.Debug.Log(" le " + level);
                tempTilePoint.TileX = tileY;
                tempTilePoint.TileY = tileY;
                quadkeylist.Add(tempTilePoint);
            }
        }
    }
Example #18
0
    /// <summary>
    /// 获取街区信息
    /// </summary>
    /// <param name="top_lon"></param>
    /// <param name="top_lat"></param>
    /// <param name="bottom_lon"></param>
    /// <param name="bottom_lat"></param>
    /// <returns></returns>
    public static List <TilePoint> GenerateStreetMapGrid(double top_lon, double top_lat, double bottom_lon, double bottom_lat, int level)
    {
        List <TilePoint> tempList         = new List <TilePoint>();
        TilePoint        start_tile_point = new TilePoint();
        TilePoint        end_tile_point   = new TilePoint();

        LatLongToTileXY(top_lat, top_lon, level, out start_tile_point.TileX, out start_tile_point.TileY);
        LatLongToTileXY(bottom_lat, bottom_lon, level, out end_tile_point.TileX, out end_tile_point.TileY);

        int x_length = UnityEngine.Mathf.Abs(start_tile_point.TileX - end_tile_point.TileX);
        int y_length = UnityEngine.Mathf.Abs(start_tile_point.TileY - end_tile_point.TileY);

        int x_start = Math.Min(start_tile_point.TileX, end_tile_point.TileX);
        int y_start = Math.Min(start_tile_point.TileY, end_tile_point.TileY);

        for (int y = 0; y <= y_length; y++)
        {
            int y_tile = y_start + y;
            for (int x = 0; x <= x_length; ++x)
            {
                int       x_tile    = x_start + x;
                TilePoint tempPoint = new TilePoint();
                tempPoint.TileX   = x_tile;
                tempPoint.TileY   = y_tile;
                tempPoint.QuadKey = TileXYToQuadKey(tempPoint.TileX, tempPoint.TileY, level);
                tempList.Add(tempPoint);
            }
        }

        return(tempList);
    }
Example #19
0
        public PointerResult Up(int mapId, TilePoint tp, MouseButtons button)
        {
            isMouseDown    = false;
            mouseDownStart = null;

            return(null);
        }
Example #20
0
    /// <summary>
    /// 初始化军营
    /// </summary>
    private bool InitCamp()
    {
        if (m_camp == null)
        {
            m_camp = FindCampEntity();
            if (m_camp == null)
            {
                return(false);
            }

            //  军营区域
            RefreshCampGridData(m_camp.GetTilePos());
            return(true);
        }
        else
        {
            //  位置变更了(拖拽等)
            TilePoint campPos = m_camp.GetTilePos();
            if (m_campTilePos != campPos)
            {
                RefreshCampGridData(campPos);
            }
            return(true);
        }
    }
Example #21
0
        private bool PlaceTile(int mapId, TilePoint tp, MouseButtons button)
        {
            var tileManager = GlobalManager.GetManager <TileManager>();

            // Get active tile based on which mouse button is pressed
            int[][] selectedSprites = tileManager.SelectedSprites;

            // Don't place tile if we dont have a tile selected
            if (selectedSprites.Length == 0)
            {
                return(false);
            }

            // Fetch TilePointTable for mapId
            TilePointTable tilePointTable;

            tileManager.GetTilePointTableForMap(mapId, out tilePointTable);

            bool tileChanged = false;

            for (int x = 0; x < selectedSprites.Length; x++)
            {
                for (int y = 0; y < selectedSprites[x].Length; y++)
                {
                    int tpX = tp.X + x;
                    int tpY = tp.Y + y;

                    // Get TilePoint from table, creates new if it doesn't exists
                    var tilePoint = tilePointTable.GetTilePoint(tpX, tpY);
                    tileChanged = tilePoint.IsNew;

                    // Get TilePointLayer, creates new if it doesnt already exists
                    var tpLayer = tilePoint.GetLayer(TileManager.DEFAULT_LAYER, true);
                    if (tpLayer.Movement != tileManager.MovementType)
                    {
                        tpLayer.Movement = tileManager.MovementType;
                        tileChanged      = true;
                    }

                    // Get TilePointTileLayer, create new if it doesn't already exists
                    var tpTileLayer = tpLayer.GetLayer(tileManager.GetCurrentLayer(), true);
                    if (tpTileLayer.TileId != selectedSprites[x][y])
                    {
                        tpTileLayer.TileId = selectedSprites[x][y];
                        tileChanged        = true;
                    }

                    // Add TilePoint to TilePointTable if it's new
                    if (tilePoint.IsNew)
                    {
                        tilePointTable.AddTilePoint(tp);
                    }
                }
            }

            // TODO: Send ConnectionEvent with the tile data, only if tile is changed!

            return(tileChanged);
        }
 public PlayerShootPacket(int time, byte bullet_id, short container_type, TilePoint starting_pos, float angle)
 {
     this.Time = time;
     this.BulletId = bullet_id;
     this.ContainerType = container_type;
     this.StartingPosition = starting_pos;
     this.Angle = angle;
 }
 public PlayerShootPacket(int time, byte bullet_id, short container_type, TilePoint starting_pos, float angle)
 {
     this.Time             = time;
     this.BulletId         = bullet_id;
     this.ContainerType    = container_type;
     this.StartingPosition = starting_pos;
     this.Angle            = angle;
 }
Example #24
0
        public void MouseLeave()
        {
            this.lastTilePoint = null;

            var mouseEvent = new EventTileMouseEvent(this.mapId, EventTileMouseEvent.MouseEvents.Leave);

            mouseEvent.Post();
        }
    public static LevelSimulationSnapshot Create(LevelMap map)
    {
        var iterator = new TwoDimensionalIterator(map.Width, map.Height);

        var floors = new List <TilePoint>();
        var disengagedFailsafes  = new List <TilePoint>();
        var oneHealthSubroutines = new List <TilePoint>();
        var twoHealthSubroutines = new List <TilePoint>();
        var iceSubroutines       = new List <TilePoint>();
        var dataCubes            = new List <TilePoint>();
        var root    = new TilePoint(-999, -999);
        var rootKey = new TilePoint(-999, -999);

        iterator.ForEach(t =>
        {
            var(x, y) = t;
            var point = new TilePoint(x, y);
            if (map.FloorLayer[x, y] == MapPiece.Floor)
            {
                floors.Add(point);
            }
            if (map.FloorLayer[x, y] == MapPiece.FailsafeFloor)
            {
                disengagedFailsafes.Add(point);
            }
            if (map.ObjectLayer[x, y] == MapPiece.Routine)
            {
                oneHealthSubroutines.Add(point);
            }
            if (map.ObjectLayer[x, y] == MapPiece.DoubleRoutine)
            {
                twoHealthSubroutines.Add(point);
            }
            if (map.ObjectLayer[x, y] == MapPiece.JumpingRoutine)
            {
                iceSubroutines.Add(point);
            }
            if (map.ObjectLayer[x, y] == MapPiece.DataCube)
            {
                dataCubes.Add(point);
            }
            if (map.ObjectLayer[x, y] == MapPiece.Root)
            {
                root = point;
            }
            if (map.ObjectLayer[x, y] == MapPiece.RootKey)
            {
                rootKey = point;
            }
        });
        if (root.X == -999 || rootKey.X == -999)
        {
            throw new ArgumentException($"Map {map.Name} is missing it's Root or Root Key!");
        }

        return(new LevelSimulationSnapshot(floors, disengagedFailsafes, oneHealthSubroutines, twoHealthSubroutines, iceSubroutines, dataCubes, root, rootKey));
    }
Example #26
0
    // Find Match-3 Tile Hint
    private Dictionary <TilePoint, Data.TileTypes> FindHint()
    {
        Dictionary <TilePoint, Data.TileTypes> stack = new Dictionary <TilePoint, Data.TileTypes>();

        Cell[,] clone = new Cell[Data.tileWidth, Data.tileHeight];
        for (var x = 0; x < Data.tileWidth - 1; x++)
        {
            for (var y = 0; y < Data.tileHeight; y++)
            {
                System.Array.Copy(cells, clone, Data.tileWidth * Data.tileHeight);
                var thiscell = clone[x, y];
                clone[x, y]     = clone[x + 1, y];
                clone[x + 1, y] = thiscell;
                Dictionary <TilePoint, Data.TileTypes> st = new Dictionary <TilePoint, Data.TileTypes>();
                st = FindMatch(clone);
                if (st.Count > 0)
                {
                    TilePoint tp = new TilePoint(x, y);
                    if (!stack.ContainsKey(tp))
                    {
                        stack.Add(tp, clone[x, y].cellType);
                    }
                    tp = new TilePoint(x + 1, y);
                    if (!stack.ContainsKey(tp))
                    {
                        stack.Add(tp, clone[x + 1, y].cellType);
                    }
                }
            }
        }
        for (var x = 0; x < Data.tileWidth; x++)
        {
            for (var y = 0; y < Data.tileHeight - 1; y++)
            {
                System.Array.Copy(cells, clone, Data.tileWidth * Data.tileHeight);
                var thiscell = clone[x, y];
                clone[x, y]     = clone[x, y + 1];
                clone[x, y + 1] = thiscell;
                Dictionary <TilePoint, Data.TileTypes> st = new Dictionary <TilePoint, Data.TileTypes>();
                st = FindMatch(clone);
                if (st.Count > 0)
                {
                    TilePoint tp = new TilePoint(x, y);
                    if (!stack.ContainsKey(tp))
                    {
                        stack.Add(tp, clone[x, y].cellType);
                    }
                    tp = new TilePoint(x, y + 1);
                    if (!stack.ContainsKey(tp))
                    {
                        stack.Add(tp, clone[x, y + 1].cellType);
                    }
                }
            }
        }
        return(stack);
    }
Example #27
0
    static double estimate(TilePoint tile, TilePoint destTile)
    {
        float dx = Mathf.Abs(destTile.x - tile.x);
        float dy = Mathf.Abs(destTile.y - tile.y);
        int   z1 = -(tile.x + tile.y);
        int   z2 = -(destTile.x + destTile.y);
        float dz = Mathf.Abs(z2 - z1);

        return(Mathf.Max(dx, dy, dz));
    }
Example #28
0
        public PointerResult Down(int mapId, TilePoint tp, MouseButtons button)
        {
            if (button == MouseButtons.Left)
            {
                isMouseDown    = true;
                mouseDownStart = tp;
            }

            return(null);
        }
    public void InBetweenCube_GivesMiddleSquares()
    {
        var tilesBetween = new TilePoint(0, 0).InBetween(new TilePoint(3, 3));

        Assert.AreEqual(4, tilesBetween.Count);
        Assert.True(tilesBetween.Any(x => x.X == 1 && x.Y == 1));
        Assert.True(tilesBetween.Any(x => x.X == 1 && x.Y == 2));
        Assert.True(tilesBetween.Any(x => x.X == 2 && x.Y == 1));
        Assert.True(tilesBetween.Any(x => x.X == 2 && x.Y == 2));
    }
Example #30
0
 public bool StartMove(TilePoint targetPos, List <TileEntity> whilteList = null, float moveSpeedFactor = 1.0f)
 {
     m_moveSpeedFactor = moveSpeedFactor;
     if (IsoMap.Instance.InRouteMap(targetPos.x, targetPos.y))
     {
         var p = IsoMap.Instance.SearchRoutes(Entity.GetTilePos().x, Entity.GetTilePos().y, targetPos.x, targetPos.y, Entity, whilteList);
         return(Move(p));
     }
     return(false);
 }
Example #31
0
    private bool createTile(int x, int y, int tileID, bool check = false, DeviceData device = null)
    {
        TilePoint key = new TilePoint(x, y);

        if (tileSet.ContainsKey(key.index))
        {
            Debug.Log("Existing index " + key.index);
            return(false);
        }
        key.ship = this;

        Vector2 hexpos = ShipData.HexOffset(x, y);

        GameObject obj = Instantiate(ShipData.tileResource, new Vector3(hexpos.x + transform.position.x, hexpos.y + transform.position.y), Quaternion.identity) as GameObject;

        obj.transform.parent = this.transform;
        obj.tag = type;
        HexaTile src = obj.GetComponent <HexaTile>();

        src.tileID = tileID;
        src.key    = key;
        src.createDevice(tileID);

        if (device != null)
        {
            src.device.UpdateData(device);
        }

        tileSet.Add(key.index, src);
        if (tileID == 1)
        {
            zero = src.key;
        }

        if (!check)
        {
            return(true);
        }

        RecalcShip();

        if (src.connected)
        {
            RecalcEnergy();
            return(true);
        }

        tileSet.Remove(src.key.index);
        Destroy(obj);

        RecalcShip();
        RecalcEnergy();

        return(false);
    }
Example #32
0
 // Find Match-3 Tile
 MatchItem FindTile(TilePoint point)
 {
     foreach (MatchItem tile in tiles)
     {
         if (tile.point.Equals(point))
         {
             return(tile);
         }
     }
     return(null);
 }
Example #33
0
        public PointerResult Move(int mapId, TilePoint tp, MouseButtons button)
        {
            var result = new PointerResult();

            if (isMouseDown && lastTilePointPosition != tp)
            {
                result.InvokeRender = PlaceTile(mapId, tp, button);
            }

            return(result);
        }
Example #34
0
        public override void Read(byte[] packet)
        {
            ProtocolReader reader = new ProtocolReader(packet);

            this.BulletId = reader.ReadByte();
            this.OwnerId = reader.ReadInt32();
            this.ContainerType = reader.ReadInt16();
            this.StartingPosition = reader.ReadTilePoint();
            this.Angle = reader.ReadSingle();
            this.Damage = reader.ReadInt16();
        }
Example #35
0
 public MovePacket(int tick_id, int time, TilePoint new_position)
 {
     this.TickId = tick_id;
     this.Time = time;
     this.NewPosition = new_position;
 }
Example #36
0
 // Find Match-3 Tile Hint
 private Dictionary<TilePoint, Data.TileTypes> FindHint()
 {
     Dictionary<TilePoint, Data.TileTypes> stack = new Dictionary<TilePoint, Data.TileTypes>();
     Cell[,] clone = new Cell[Data.tileWidth, Data.tileHeight];
     for (var x = 0; x < Data.tileWidth-1; x++) {
         for (var y = 0; y < Data.tileHeight; y++) {
             System.Array.Copy(cells, clone, Data.tileWidth * Data.tileHeight);
             var thiscell = clone[x, y];
             clone[x, y] = clone[x+1,y];
             clone[x+1,y] = thiscell;
             Dictionary<TilePoint, Data.TileTypes> st = new Dictionary<TilePoint, Data.TileTypes>();
             st = FindMatch(clone);
             if (st.Count>0) {
                 TilePoint tp = new TilePoint(x, y);
                 if (!stack.ContainsKey(tp))
                     stack.Add(tp , clone[x, y].cellType);
                 tp = new TilePoint(x+1, y);
                 if (!stack.ContainsKey(tp))
                     stack.Add(tp , clone[x+1, y].cellType);
             }
         }
     }
     for (var x = 0; x < Data.tileWidth; x++) {
         for (var y = 0; y < Data.tileHeight-1; y++) {
             System.Array.Copy(cells, clone, Data.tileWidth * Data.tileHeight);
             var thiscell = clone[x, y];
             clone[x, y] = clone[x,y+1];
             clone[x,y+1] = thiscell;
             Dictionary<TilePoint, Data.TileTypes> st = new Dictionary<TilePoint, Data.TileTypes>();
             st = FindMatch(clone);
             if (st.Count>0) {
                 TilePoint tp = new TilePoint(x, y);
                 if (!stack.ContainsKey(tp))
                     stack.Add(tp , clone[x, y].cellType);
                 tp = new TilePoint(x, y+1);
                 if (!stack.ContainsKey(tp))
                     stack.Add(tp , clone[x, y+1].cellType);
             }
         }
     }
     return stack;
 }
Example #37
0
 // Find Match-3 Tile
 MatchItem FindTile(TilePoint point)
 {
     foreach (MatchItem tile in tiles) {
         if (tile.point.Equals( point )) return tile;
     }
     return null;
 }