예제 #1
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        MapGeneration map = target as MapGeneration;

        map.GenerateMap();

        if (GUILayout.Button("Generate Map"))
        {
            map.GenerateMap();
        }
    }
예제 #2
0
    public override void OnInspectorGUI()
    {
        MapGeneration map = target as MapGeneration;

        if (DrawDefaultInspector())
        {
            map.GenerateMap();
        }

        if (GUILayout.Button("Generate Map"))
        {
            map.GenerateMap();
        }
    }
예제 #3
0
        public void update_neighbours()
        {
            //ARRANGE
            GameObject    hexGO         = new GameObject();
            GameObject    gameObject    = new GameObject();
            MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>();

            mapGeneration.HexagonPrefab = hexGO;
            mapGeneration.MapRadius     = 10;

            //generate map
            mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();
            mapGeneration.GenerateMap();
            mapGeneration.UpdateHexNeighbours();
            mapGeneration.ConnectContentsToHex();

            //get random hex
            Vector3Int coords = new Vector3Int(-3, 2, 1);
            IHexagon   hex    = (IHexagon)mapGeneration.HexDict[coords];

            //manually calculate its neighbours
            List <Vector3Int> directions = mapGeneration.GetDirections();
            List <IHexagon>   neighbours = new List <IHexagon>();

            foreach (Vector3Int direction in directions)
            {
                neighbours.Add(mapGeneration.HexDict[coords + direction]);
            }

            //ASSERT
            Assert.AreEqual(neighbours, hex.MyHexMap.Neighbours);
        }
예제 #4
0
        public void hexes_in_range()
        {
            GameObject    gameObject    = new GameObject();
            MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>();

            mapGeneration.HexagonPrefab = new GameObject();
            mapGeneration.MapRadius     = 10;

            mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();
            mapGeneration.GenerateMap();
            mapGeneration.UpdateHexNeighbours();
            mapGeneration.ConnectContentsToHex();

            IHexagon startHex = mapGeneration.HexDict[new Vector3Int(0, 0, 0)];

            MapPathfinding     mapPathfinding = new MapPathfinding();
            HashSet <IHexagon> hexesInRange   = mapPathfinding.GetHexesInRange(startHex, 1);

            HashSet <IHexagon> neighboursAndStart = startHex.MyHexMap.Neighbours;

            neighboursAndStart.Add(startHex);
            foreach (IHexagon neighbour in startHex.MyHexMap.Neighbours)
            {
                Assert.IsTrue(hexesInRange.Contains(neighbour));
            }
            foreach (IHexagon hex in hexesInRange)
            {
                Assert.IsTrue(neighboursAndStart.Contains(hex));
            }
        }
예제 #5
0
        public void pathfinding()
        {
            GameObject    gameObject    = new GameObject();
            MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>();

            mapGeneration.HexagonPrefab = new GameObject();
            mapGeneration.MapRadius     = 10;

            mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();
            mapGeneration.GenerateMap();
            mapGeneration.UpdateHexNeighbours();
            mapGeneration.ConnectContentsToHex();

            IHexagon start_hex = mapGeneration.HexDict[new Vector3Int(0, 0, 0)];
            IHexagon end_hex   = mapGeneration.HexDict[new Vector3Int(0, -4, 4)];

            MapPathfinding mapPathfinding = new MapPathfinding();
            MapPath        path           = mapPathfinding.GeneratePath(start_hex, end_hex);

            MapPath arbitrary_path = new MapPath();

            for (int i = 4; i >= 0; i--)
            {
                arbitrary_path.PathStack.Push(mapGeneration.HexDict[new Vector3Int(0, -i, i)]);
            }
            arbitrary_path.cost = 4;

            Assert.AreEqual(arbitrary_path.PathStack, path.PathStack);
            Assert.AreEqual(arbitrary_path.cost, path.cost);
        }
    public override void OnInspectorGUI()
    {
        MapGeneration mapGen = (MapGeneration)target;

        if (DrawDefaultInspector())
        {
            if (mapGen.autoUpdate)
            {
                mapGen.GenerateMap();
            }
        }

        if (GUILayout.Button("Generate"))
        {
            mapGen.GenerateMap();
        }
    }
예제 #7
0
    public override void OnInspectorGUI()
    {
        MapGeneration generationMaps = (MapGeneration)target;

        DrawDefaultInspector();

        if (GUILayout.Button("Generate") || generationMaps.GenerationAllTime)
        {
            GenerateMapAllTime = true;
            generationMaps.GenerateMap();
        }
        else
        {
            GenerateMapAllTime = false;
        }
    }
예제 #8
0
    // Use this for initialization
    void Start()
    {
        manager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManagerScript>();

        mapGenerator = new MapGeneration();

        playerShip = manager.GetPlayer().Ship.ShipModel;

        if (manager.GetLevel() == 1)
        {
            print("loading 1");
            playerShip.transform.position = new Vector3(-7.9f, 0f, -17f);
        }

        // Call to set up the generation of the island objects
        islands = mapGenerator.GenerateMap(manager.GetLevel());
        SetIslands();
    }
예제 #9
0
        public void initial_generation()
        {
            //ARRANGE
            GameObject    hexGO           = new GameObject();
            GameObject    gameObject      = new GameObject();
            MapGeneration myMapGeneration = gameObject.AddComponent <MapGeneration>();

            myMapGeneration.HexagonPrefab = hexGO;
            myMapGeneration.MapRadius     = 10;


            myMapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();

            //ACT
            myMapGeneration.GenerateMap();

            //ASSERT
            Assert.AreEqual(331, myMapGeneration.HexDict.Count);
        }
예제 #10
0
        public void find_straight_distance()
        {
            GameObject    gameObject    = new GameObject();
            MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>();

            mapGeneration.HexagonPrefab = new GameObject();
            mapGeneration.MapRadius     = 10;

            mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();
            mapGeneration.GenerateMap();
            mapGeneration.UpdateHexNeighbours();

            IHexagon start_hex = mapGeneration.HexDict[new Vector3Int(0, 0, 0)];
            IHexagon end_hex   = mapGeneration.HexDict[new Vector3Int(0, -4, 4)];


            int distance = 4;

            Assert.AreEqual(distance, HexMath.FindDistance(start_hex, end_hex));
        }
예제 #11
0
        public void hex_content_links_to_hex()
        {
            GameObject    gameObject    = new GameObject();
            MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>();

            GameObject character = new GameObject();

            character.transform.position = new Vector3(5, 0, 3);
            character.AddComponent <IContentMarker>();
            ObjectHexContent moveableCharacter = character.AddComponent <ObjectHexContent>();

            mapGeneration.MapRadius     = 10;
            mapGeneration.HexagonPrefab = new GameObject();
            mapGeneration.HexDict       = new Dictionary <Vector3Int, IHexagon>();
            mapGeneration.GenerateMap();
            mapGeneration.UpdateHexNeighbours();
            mapGeneration.ConnectContentsToHex();

            Assert.AreEqual(mapGeneration.HexDict[new Vector3Int(7, 0, -7)], moveableCharacter.Location);
        }