当前位置: 首页>>代码示例>>C#>>正文


C# TileMap.get方法代码示例

本文整理汇总了C#中TileMap.get方法的典型用法代码示例。如果您正苦于以下问题:C# TileMap.get方法的具体用法?C# TileMap.get怎么用?C# TileMap.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TileMap的用法示例。


在下文中一共展示了TileMap.get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: pathfindFallback

            /// <summary>
            /// Finds the path from source to destination point (does not consider ally unit)
            /// </summary>
            /// <param name="tm">TileMap</param>
            /// <param name="src">Source point (the Unit or Character moving)</param>
            /// <param name="dest">Destination point (the target)</param>
            /// <returns>A point adjacent to the source which is the next move of the character or unit
            /// in order to arrive to destination. or the source point if no path is found</returns>
            public static Point pathfindFallback(TileMap tm, Point src, Point dest)
            {
                Dictionary<Point, int> map = new Dictionary<Point, int>();
                Queue<PointCounter> main = new Queue<PointCounter>();
                Queue<PointCounter> temp = new Queue<PointCounter>();
                PointCounter cur;
                PointCounter tcur;

                main.Enqueue(new PointCounter(dest, 0));
                map[dest] = 0;

                int cc;
                bool f = false;

                while (main.Count > 0)
                {
                    cur = main.Dequeue();
                    temp.Clear();

                    if (cur.p == src)
                    {
                        f = true;
                        break;
                    }

                    cc = cur.c + 1;

                    temp.Enqueue(new PointCounter(cur.p.X, cur.p.Y - 1, cc));
                    temp.Enqueue(new PointCounter(cur.p.X + 1, cur.p.Y, cc));
                    temp.Enqueue(new PointCounter(cur.p.X, cur.p.Y + 1, cc));
                    temp.Enqueue(new PointCounter(cur.p.X - 1, cur.p.Y, cc));

                    while (temp.Count > 0)
                    {
                        tcur = temp.Dequeue();

                        if (tcur.p != src)
                        {
                            if (!tm.inMap(tcur.p) || tm.get(tcur.p.X, tcur.p.Y) == TileMap.Tile_Type.BLOCK_TERRAIN)
                                continue;

                            if (map.ContainsKey(tcur.p) && map[tcur.p] <= tcur.c)
                                continue;
                        }

                        map[tcur.p] = tcur.c;
                        main.Enqueue(tcur);
                    }
                }

                if (!f)
                    return new Point(-1, -1);

                Point ret = src;
                cc = map[src];

                temp.Clear();

                temp.Enqueue(new PointCounter(src.X, src.Y - 1, 0));
                temp.Enqueue(new PointCounter(src.X + 1, src.Y, 0));
                temp.Enqueue(new PointCounter(src.X, src.Y + 1, 0));
                temp.Enqueue(new PointCounter(src.X - 1, src.Y, 0));

                while (temp.Count > 0)
                {
                    tcur = temp.Dequeue();

                    if (map.ContainsKey(tcur.p) && map[tcur.p] < cc)
                    {
                        cc = map[tcur.p];
                        ret = tcur.p;
                    }
                }

                if (tm.get(ret.X, ret.Y) != TileMap.Tile_Type.NOTHING||ret==dest)
                    return src;

                return ret;
            }
开发者ID:nlacombe42,项目名称:forgottenschism,代码行数:87,代码来源:AI.cs


注:本文中的TileMap.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。