public static GameMap LoadMap(StrategyGame game, string name)
        {
            SimpleGameMap map;

            switch (name)
            {
            case RandomMapName_Small:
                map = RandomMap.GenerateSimpleMap(EMapSize.Small);

                break;

            case RandomMapName_Normal:
                map = RandomMap.GenerateSimpleMap(EMapSize.Normal);
                break;

            case RandomMapName_Large:
                map = RandomMap.GenerateSimpleMap(EMapSize.Large);
                break;

            default:
                map = Utils.DeserialiseFromFile <SimpleGameMap>(StrategyGame.MapFolder + "\\" + name + ".map");
                break;
            }

            if (map == null)
            {
                return(Brawl(game));
            }

            return(GameMap.FromSimpleMap(game, map));
        }
Beispiel #2
0
    public List <Vector2> EatSmartGrass()
    {
        if (RandomMap.food.Count == 0)
        {
            return(null);
        }
        Vector2 next = RandomMap.food[0];

        foreach (Vector2 v in RandomMap.food)//找最近的食物
        {
            if (Vector3.Distance(transform.position, v) < Vector3.Distance(transform.position, next))
            {
                next = v;
            }
        }
        MapPoint       target = new MapPoint(next);
        List <Vector2> path   = new List <Vector2>();

        path = RandomMap.Astar(target);
        line.positionCount = path.Count; //画线
        for (int i = 0; i <= path.Count - 1; i++)
        {
            line.SetPosition(i, path[i]);
        }
        return(path);
    }
        public void AfterHorizonalLine()
        {
            _target.Sectors.Add(new SimpleMapSector(0, new Point(3, 3)));

            var clear = RandomMap.IsPathClear(_target, new Point(4, 3), new Point(6, 3));

            clear.ShouldBe(true);
        }
        public void SamePoint()
        {
            _target.Sectors.Add(new SimpleMapSector(0, new Point(3, 3)));

            var clear = RandomMap.IsPathClear(_target, new Point(3, 3), new Point(3, 4));

            clear.ShouldBe(true);
        }
        public void JustOnHorizontalLine2()
        {
            _target.Sectors.Add(new SimpleMapSector(0, new Point(2, 1)));

            var clear = RandomMap.IsPathClear(_target, new Point(0, 0), new Point(3, 1));

            clear.ShouldBe(false);
        }
        public void JustOffVerticalLine()
        {
            _target.Sectors.Add(new SimpleMapSector(0, new Point(3, 3)));

            var clear = RandomMap.IsPathClear(_target, new Point(3, 0), new Point(4, 3));

            clear.ShouldBe(true);
        }
        public void OnDiagonalLine()
        {
            _target.Sectors.Add(new SimpleMapSector(0, new Point(3, 3)));

            var clear = RandomMap.IsPathClear(_target, new Point(0, 0), new Point(6, 6));

            clear.ShouldBe(false);
        }
        public void Horizontal_FarBottom()
        {
            var s = new Point(0, 6);
            var m = RandomMap.MirrorPoint(s, EMirrorType.Vertical);

            m.X.ShouldBe(s.X);
            m.Y.ShouldBe(0);
        }
        public void Horizontal_Mid()
        {
            var s = new Point(3, 0);
            var m = RandomMap.MirrorPoint(s, EMirrorType.Horizontal);

            m.X.ShouldBe(3);
            m.Y.ShouldBe(s.Y);
        }
        public void Horizontal_FarRight()
        {
            var s = new Point(6, 0);
            var m = RandomMap.MirrorPoint(s, EMirrorType.Horizontal);

            m.X.ShouldBe(0);
            m.Y.ShouldBe(s.Y);
        }
        public void Vertical_Mid()
        {
            var s = new Point(0, 3);
            var m = RandomMap.MirrorPoint(s, EMirrorType.Vertical);

            m.X.ShouldBe(s.X);
            m.Y.ShouldBe(3);
        }
        public void Vertical_Bottom()
        {
            var s = new Point(0, 4);
            var m = RandomMap.MirrorPoint(s, EMirrorType.Vertical);

            m.X.ShouldBe(s.X);
            m.Y.ShouldBe(2);
        }
        private void RandomSmall_Click(object sender, EventArgs e)
        {
            var type = (EMapSize)MapSize.SelectedIndex;

            _map = RandomMap.GenerateSimpleMap(type);

            Clear_Click(sender, e);
            LoadMap(_map);
        }
Beispiel #14
0
        private void RandomSmall_Click(object sender, EventArgs e)
        {
            SoundEffect.Play(ESounds.mousedown);

            var type = (EMapSize)MapSize.SelectedIndex;

            _map = RandomMap.GenerateMirroredMap(type);

            Clear_Click(sender, e);
            LoadMap(_map);
        }
Beispiel #15
0
 // Use this for initialization
 void Start()
 {
     quitMenu         = quitMenu.GetComponent <Canvas>();
     startText        = startText.GetComponent <Button>();
     quitText         = quitText.GetComponent <Button>();
     settingsMenu     = Object.FindObjectOfType <SettingsMenu>();
     quitMenu.enabled = false;
     inv.SetActive(false);
     healthController = Object.FindObjectOfType <playerHealth>();
     playerController = Object.FindObjectOfType <PlayerMovement>();
     randomMap        = Object.FindObjectOfType <RandomMap>();
 }
Beispiel #16
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        RandomMap tiled = (RandomMap)target;

        if (GUILayout.Button("Generate"))
        {
            tiled.Generate();
        }
        if (GUILayout.Button("Clear"))
        {
            tiled.Clear();
        }
    }
        //re-call-able floor getting methods, caching where needed
        protected override void generateFloor(int floor)
        {
            //borders are orders to the floor generator for entrance/exit data: requirements of where they need to be, and which direction they are
            List <FloorBorder> borders = new List <FloorBorder>();

            borders.Add(new FloorBorder(null, Direction3D.Forth));
            borders.Add(new FloorBorder(null, Direction3D.Back));

            //borderLinks are orders to the floor generator for entrance/exit data: requirements of which nodes must connect to each other
            Dictionary <int, List <int> > borderLinks = new Dictionary <int, List <int> >();
            List <int> ends = new List <int>();

            ends.Add(1);
            borderLinks.Add(0, ends);

            RandomMap map = GameData.FloorAlgorithmDex[entry.Floors[floor].Algorithm].CreateFloor();

            map.Generate(rand.Next(), entry.Floors[floor], borders, borderLinks);
            maps.Add(floor, map);
        }
Beispiel #18
0
 // Start is called before the first frame update
 void Start()
 {
     if (sceneName == "Mode1")
     {
         head.GetComponent <Mode2>().enabled = false;
     }
     else
     {
         head.GetComponent <Mode1>().enabled = false;
     }
     //head.transform.localScale = new Vector3(Node.scale, Node.scale, 1);
     //bodyObj = Resources.Load<GameObject>("Prefabs/SnakeBody" + Node.bodySkin);
     //GameObject initBody1 = Instantiate(bodyObj);//初始身体
     //GameObject initBody2 = Instantiate(bodyObj);
     if (sceneName == "Mode1")
     {
         RandomMap.Init();
     }
     //获取屏幕宽高
 }
    static void Main(string[] args)
    {
        ImportMap           importMap           = new ImportMap();
        MapTransformer      mapTrans            = new MapTransformer();
        ImportTraj          importTraj          = new ImportTraj();
        RandomMap           rand                = new RandomMap();
        TrajGenerator       trajGenerator       = new TrajGenerator();
        TrajSaver           trajSaver           = new TrajSaver();
        MapPruner           mapPruner           = new MapPruner();
        SampleNeighbourhood sampleNeighbourhood = new SampleNeighbourhood();
        MapSaver            mapSaver            = new MapSaver();
        Evaluator           eval                = new Evaluator(rand, sampleNeighbourhood);

        Map gt = importMap.ReadMap($"Chicago/Chicago-200-directed-50-100");
        Map cm = importMap.ReadMap($"Kharita/Directed/Chicago-200-50-100");

        (float, float)precall = eval.EvalNeighbourhood(gt, cm);

        Console.WriteLine(precall);
    }
Beispiel #20
0
    static void Main(string[] args)
    {
        var       SIZE = 6;
        RandomMap map  = new RandomMap(SIZE, (int)(SIZE * SIZE * 0.8));

        map.Print();

        Solver s      = new Solver(map);
        bool   result = s.PathExists(new Point(0, 0), new Point(SIZE - 1, 0));

        Console.WriteLine(result);

        if (result)
        {
            foreach (Point p in s.path)
            {
                Console.Write(p + " > ");
            }
            Console.Write("YEAH!");
        }

        Console.ReadLine();
    }
Beispiel #21
0
    public override void _Process(float delta)
    {
        if (!ok)
        {
            var t1 = OS.GetTicksMsec();
            ok  = true;
            map = new RandomMap();
            Utils.AddNode("ground", "res://prefabs/Ground2SB.tscn", GlobalsCS.root, map);
            var t2 = OS.GetTicksMsec();
            Utils.Log("time: " + (t2 - t1));
        }

        if (Input.IsKeyPressed((int)KeyList.Enter))
        {
            var t1 = OS.GetTicksMsec();
            for (int q = 0; q < 100; q++)
            {
                map.AddRandom(GetNode("/root/objs"));
            }
            var t2 = OS.GetTicksMsec();
            Utils.Log("time: " + (t2 - t1));
            Utils.Log("objs: " + GlobalsCS.map.Count);
        }
    }
 public Evaluator(RandomMap rand, SampleNeighbourhood sample)
 {
     this.rand = rand;
     this.sampleNeighbourhood = sample;
 }
Beispiel #23
0
    public EventManager(RandomMap rm)
    {
        allEvents   = new List <EventItem>();
        allHexItems = new List <HexItem>();
        allPoints   = new List <Vector3Int>();
        randomMap   = rm;

        for (int i = 0; i < rm.hexagons.Count; i++)
        {
            for (int j = 0; j < rm.hexagons[i].hexItems.Count; j++)
            {
                bool repeat = false;
                for (int k = 0; k < allHexItems.Count; k++)
                {
                    if (rm.hexagons[i].hexItems[j].posX == allHexItems[k].posX && rm.hexagons[i].hexItems[j].posY == allHexItems[k].posY)
                    {
                        repeat = true;
                    }
                }
                if (repeat == false)
                {
                    allHexItems.Add(rm.hexagons[i].hexItems[j]);
                }
            }
        }

        //点
        for (int i = 0; i < allHexItems.Count; i++)
        {
            Vector3Int vector3Int = new Vector3Int(allHexItems[i].posX, allHexItems[i].posY, 0);
            allPoints.Add(vector3Int);
        }

        //生成事件

        /*
         * 开始0
         * 普通1
         * 精英2
         * 酒馆3
         * 商店4
         * 奇遇5
         * boss9
         *
         */

        jingyingCount  = allPoints.Count / 8;
        jiuguanCount   = allPoints.Count / 10;
        shangdianCount = allPoints.Count / 8;
        qiyuCount      = allPoints.Count / 8;

        EventItem startEvent = new EventItem(allPoints[0].x, allPoints[0].y, 0);
        EventItem bossEvent  = new EventItem(allPoints[allPoints.Count - 2].x, allPoints[allPoints.Count - 2].y, 9);

        allEvents.Add(startEvent);
        allEvents.Add(bossEvent);

        allPoints.RemoveAt(0);
        allPoints.RemoveAt(allPoints.Count - 2);

        for (int i = 0; i < jingyingCount; i++)
        {
            int       index     = Random.Range(0, allPoints.Count);
            int       x         = allPoints[index].x;
            int       y         = allPoints[index].y;
            int       eventType = 2;
            EventItem eventItem = new EventItem(x, y, eventType);

            allEvents.Add(eventItem);
            allPoints.RemoveAt(index);
        }

        for (int i = 0; i < jiuguanCount; i++)
        {
            int       index     = Random.Range(0, allPoints.Count);
            int       x         = allPoints[index].x;
            int       y         = allPoints[index].y;
            int       eventType = 3;
            EventItem eventItem = new EventItem(x, y, eventType);

            allEvents.Add(eventItem);
            allPoints.RemoveAt(index);
        }

        for (int i = 0; i < shangdianCount; i++)
        {
            int       index     = Random.Range(0, allPoints.Count);
            int       x         = allPoints[index].x;
            int       y         = allPoints[index].y;
            int       eventType = 4;
            EventItem eventItem = new EventItem(x, y, eventType);

            allEvents.Add(eventItem);
            allPoints.RemoveAt(index);
        }

        for (int i = 0; i < qiyuCount; i++)
        {
            int       index     = Random.Range(0, allPoints.Count);
            int       x         = allPoints[index].x;
            int       y         = allPoints[index].y;
            int       eventType = 5;
            EventItem eventItem = new EventItem(x, y, eventType);

            allEvents.Add(eventItem);
            allPoints.RemoveAt(index);
        }

        for (int i = 0; i < allPoints.Count; i++)
        {
            int       x         = allPoints[i].x;
            int       y         = allPoints[i].y;
            int       eventType = 1;
            EventItem eventItem = new EventItem(x, y, eventType);

            allEvents.Add(eventItem);
        }
    }
Beispiel #24
0
    // Start is called before the first frame update
    void Start()
    {
        RandomMap    map;
        EventManager eventManager;

        if (PlayerController.eventManager == null || PlayerController.map == null)
        {
            map = new RandomMap();
            map.createMap(10);
            eventManager = new EventManager(map);
            PlayerController.eventManager = eventManager;
            PlayerController.map          = map;
        }
        else
        {
            map          = PlayerController.map;
            eventManager = PlayerController.eventManager;
        }

        for (int i = 0; i < map.hexagons.Count; i++)
        {
            for (int j = 0; j < map.hexagons[i].hexItems.Count; j++)
            {
                Vector3Int pos = new Vector3Int(map.hexagons[i].hexItems[j].posX, map.hexagons[i].hexItems[j].posY, 0);
                if (tilemap.GetTile(pos) == null)
                {
                    tilemap.SetTile(pos, roundTile);
                }
            }

            GameObject hexbg = Instantiate(hexBgPrefab);
            hexbg.GetComponent <Transform>().SetParent(tilemap.transform, true);
            hexbg.GetComponent <Transform>().position    = map.hexagons[i].hexBgPosition;
            hexbg.GetComponent <SpriteRenderer>().sprite = hexBgs[map.hexagons[i].bgIndex];
        }

        for (int i = 0; i < map.arrow.arrowItems.Count; i++)
        {
            ArrowItem  arrowItem = map.arrow.arrowItems[i];
            Vector3Int pos       = new Vector3Int(arrowItem.posX, arrowItem.posY, 0);
            if (tilemap.GetTile(pos) == null)
            {
                Tile   t = ScriptableObject.CreateInstance <Tile>();
                string d = arrowItem.direction;
                //Debug.Log(arrowItem.direction);
                switch (arrowItem.direction)
                {
                case "rightUp":
                    t = arrRightUp;
                    break;

                case "right":
                    t = arrRight;
                    break;

                case "rightDown":
                    t = arrRightDown;
                    break;

                case "leftRight":
                    t = arrLeftRight;
                    break;

                case "rightLeft":
                    t = arrRightLeft;
                    break;

                case "leftUp":
                    t = arrLeftUp;
                    break;

                case "leftDown":
                    t = arrLeftDown;
                    break;
                }

                tilemap.SetTile(pos, t);
            }
        }

        for (int i = 0; i < eventManager.allEvents.Count; i++)
        {
            float eventPosX = eventManager.allEvents[i].posX;
            float eventPosY = (float)(eventManager.allEvents[i].posY / 2 * 1.73);
            int   eventType = eventManager.allEvents[i].eventType;

            //Debug.Log(eventType);
            int index = 0;
            switch (eventType)
            {
            case 1:
                index = 0;
                break;

            case 2:
                index = 1;
                break;

            case 3:
                index = 2;
                break;

            case 4:
                index = 3;
                break;

            case 5:
                index = 4;
                break;

            case 9:
                index = 5;
                break;
            }

            GameObject eventObj = Instantiate(eventPrefabs[index]);
            eventObj.GetComponent <Transform>().SetParent(tilemap.transform, true);
            eventObj.GetComponent <Transform>().position = new Vector3(eventPosX, eventPosY, 0);
        }
        //PlayerController.Save();
    }
Beispiel #25
0
        public void LargeCheck()
        {
            var m = RandomMap.GenerateSimpleMap(EMapSize.Large);

            m.Sectors.Count.ShouldBeGreaterThan(6);
        }
Beispiel #26
0
        public void NormalCheck()
        {
            var m = RandomMap.GenerateSimpleMap(EMapSize.Normal);

            m.Sectors.Count.ShouldBeGreaterThan(4);
        }
 public float RandomAt(int x, int y)
 {
     x = x % RandomMap.GetLength(0);
     y = y % RandomMap.GetLength(1);
     return(RandomMap[x, y]);
 }
Beispiel #28
0
        public void SmallCheck()
        {
            var m = RandomMap.GenerateMirroredMap(EMapSize.Small);

            m.Sectors.Count.ShouldBeGreaterThan(2);
        }
        public SceneMapSelect()
        {
            sceneType = scene.SceneType.MapSelect;

            _loader              = new MapLoader();
            _loader.OnMapLoaded += (s, e) =>
            {
                _loadedMap = e.Map;
                _loadEnd   = true;
                _loading   = false;
            };
            _loader.OnMapLoadCanceled += (s, e) =>
            {
                _loadedException = e.Exception;
                _loadedMap       = null;
                _loadingMapInfo  = null;
                _loadEnd         = true;
                _loading         = false;
            };

            _mapInfos = new List <MapInfo>();

            _keys = new Key[]
            {
                Key.UpArrow, Key.DownArrow, Key.LeftArrow, Key.RightArrow, Key.Return, Key.Escape,
                Key.One, Key.Two, Key.R
            };
            _builtinMapInfos = new MapInfo[]
            {
                EmptyMap.GetMapInfo(),
                    EmptyFixedMap.GetMapInfo(),
                    RandomMap.GetMapInfo(3),
                RandomMap.GetMapInfo(5),
                RandomEndlessMap.GetMapInfo(3)
            };

            _randItems = new string[_builtinMapInfos.Length + 1];
            for (int i = 0; i < _builtinMapInfos.Length; i++)
            {
                _randItems[i] = _builtinMapInfos[i].MapName;
            }
            _randItems[_randItems.Length - 1] = Properties.Resources.MenuItem_ReloadMap;


            _cursor       = ResourceManager.GetColoredCursorGraphic(Constants.Color_Foreground);
            _strongCursor = ResourceManager.GetColoredCursorGraphic(Constants.Color_Strong);

            #region レイアウト初期化
            Size escSize = ResourceManager.MiddlePFont.SizeText(_escItems[0].ToString());
            _escRect = new Rectangle(
                Constants.ScreenWidth - Constants.RightBottomItemMargin - escSize.Width - Constants.CursorMargin,
                Constants.ScreenHeight - Constants.RightBottomItemMargin - escSize.Height,
                escSize.Width + Constants.CursorMargin, escSize.Height);

            _expRect = new Rectangle(
                Constants.HeaderX + Constants.UnderHeaderMargin,
                Constants.HeaderY + ResourceManager.LargePFont.Height + Constants.HeaderBottomMargin,
                Constants.ScreenWidth - Constants.UnderHeaderMargin * 2,
                ResourceManager.SmallPFont.Height);

            int top    = _expRect.Bottom + Constants.SubHeaderBottomMargin;
            int bottom = _escRect.Top - Constants.UnderHeaderMargin;
            _mapRect = new Rectangle(
                Constants.HeaderX + Constants.UnderHeaderMargin + Constants.CursorMargin,
                top,
                (int)((Constants.ScreenWidth - (Constants.HeaderX + Constants.UnderHeaderMargin * 2) - Constants.MenuColumnGap) / 2.0) - Constants.CursorMargin,
                bottom - top);
            _randRect = new Rectangle(
                _mapRect.Right + Constants.MenuColumnGap + Constants.CursorMargin,
                _mapRect.Top, _mapRect.Width, _mapRect.Height);
            #endregion

            _randSurfaces = new SurfaceCollection();
            _randRects    = new Rectangle[_randItems.Length];
            ImageUtil.CreateStrMenu(_randItems, Constants.Color_Foreground,
                                    ref _randSurfaces, ref _randRects, _randRect.Width);
            _randRects[_randRects.Length - 1].Offset(0, ResourceManager.SmallPFont.Height);

            _escSurfaces = new SurfaceCollection();
            _escRects    = new Rectangle[_escItems.Length];
            ImageUtil.CreateStrMenu(_escItems, Constants.Color_Strong, ResourceManager.MiddlePFont,
                                    ref _escSurfaces, ref _escRects, _escRect.Width, ResourceManager.MiddlePFont.Height);
        }
Beispiel #30
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        string tag = collision.gameObject.tag;

        if (collision.gameObject.tag == "Bomb")
        {
            Vector2 m = RandomMap.PostoMap(collision.transform.position);//重置地图
            RandomMap.canMap[(int)m.x, (int)m.y] = true;
            Destroy(collision.gameObject);
            if (defence == true)
            {
                defence = false;
                HudunImage.GetComponent <CanvasGroup>().alpha = 0;
                return;
            }
            Node.score -= 10;
            int length = Head.instance.snake.Count + 1;
            if (length <= 1)
            {
                instance.Die();
            }
            for (int i = 1; i <= length / 2; i++)
            {
                instance.Lengthdec();
            }
        }
        if (collision.gameObject.tag == "AddSpeed")
        {
            Destroy(collision.gameObject);

            if (addSpeedTime <= 0)
            {
                addSpeedTime = 6f;
                Node.speed  *= 1.5f;
            }
            else
            {
                addSpeedTime = 6f;
            }
            Node.score += 2;
        }
        if (collision.gameObject.tag == "Mogu")
        {
            Destroy(collision.gameObject);
            int length = instance.snake.Count + 1;
            for (int i = 0; i <= length - 1; i++)
            {
                instance.Lengthadd();
            }
            Node.score += 10;
        }
        if (collision.gameObject.tag == "Hudun")
        {
            Destroy(collision.gameObject);
            defence = true;
            HudunImage.GetComponent <CanvasGroup>().alpha = 1;
        }
        if (collision.gameObject.tag == "Grass")
        {
            //修改canmap
            Vector2 m = RandomMap.PostoMap(collision.transform.position);
            RandomMap.canMap[(int)m.x, (int)m.y] = true;
            Destroy(collision.gameObject);
            if (defence == true)
            {
                defence = false;
                HudunImage.GetComponent <CanvasGroup>().alpha = 0;
                return;
            }
            if (instance.snake.Count + 1 <= 2)
            {
                instance.Die();
                instance.Lengthdec();
                instance.Lengthdec();
            }
            Node.score -= 2;
        }
        if (collision.gameObject.tag == "SmartGrass")
        {
            Destroy(collision.gameObject);

            if (smartTime <= 0)
            {
                instance.GetComponent <SpriteRenderer>().sprite = instance.dizzySprite;
                smartTime = 6f;
                StartCoroutine(MoveWithGrass());
            }
            else
            {
                smartTime = 6f;
            }
        }
    }