Пример #1
0
        private void generate(object sender, RoutedEventArgs e)
        {
            Generator.Map result = MapCreator.Create(Convert.ToInt32(seed.Text), Convert.ToInt32(size.Text), Convert.ToDouble(water.Text), Convert.ToDouble(mountain.Text), Convert.ToInt32(iter.Text), Convert.ToInt32(riverCount.Text));
            Collection = result;
            switch (view)
            {
            case 0: Show(Collection.map);
                break;

            case 1: Show(Collection.digitalized);
                break;
            }
        }
        public void TestPraerieMapCreation()
        {
            int waterSourcesCount = 6;
            int floraCount = 25;

            MapCreator mapCreator = new MapCreator(waterSourcesCount, floraCount);
            PraerieMapBuilder praerieMapBuilder = new PraerieMapBuilder();

            mapCreator.Create(praerieMapBuilder);

            Map praerieMap = praerieMapBuilder.Map;

            string expectedGroundDescription = "grass";
            string praerieMapGrounDescription = praerieMap.Ground.Description;
            Assert.AreEqual(expectedGroundDescription, praerieMapGrounDescription, "Praerie map ground description is not the expected=");

            int praerieMapWaterSourcesCount = praerieMap.WaterSources.Count;
            Assert.AreEqual(waterSourcesCount, praerieMapWaterSourcesCount, "Praerie map water sources count i not the expected");

            int praerieMapFloraCount = praerieMap.FloraColection.Count;
            Assert.AreEqual(floraCount, praerieMapFloraCount, "Praerie map flora count is not the expected");
        }
        public void TestDesertMapCreation()
        {
            int waterSourcesCount = 5;
            int floraCount = 20;

            MapCreator mapCreator = new MapCreator(waterSourcesCount, floraCount);
            DesertMapBuilder desertMapBuilder = new DesertMapBuilder();

            mapCreator.Create(desertMapBuilder);

            Map desertMap = desertMapBuilder.Map;

            string expectedGroundDescription = "sand";
            string desertMapGrounDescription = desertMap.Ground.Description;
            Assert.AreEqual(expectedGroundDescription, desertMapGrounDescription, "Desert map ground description is not the expected=");

            int desertMapWaterSourcesCount = desertMap.WaterSources.Count;
            Assert.AreEqual(waterSourcesCount, desertMapWaterSourcesCount, "Desert map water sources count i not the expected");

            int desertMapFloraCount = desertMap.FloraColection.Count;
            Assert.AreEqual(floraCount, desertMapFloraCount, "Desert map flora count is not the expected");
        }
Пример #4
0
    void OnGUI()
    {
        if (creator == null)
        {
            GameObject creatorObj = GameObject.Find("Map Creator");
            if (creatorObj == null)
            {
                Debug.LogError("Could not find a map creator in the current scene, close board editor or change to editor scene");
                return;
            }

            creator = creatorObj.GetComponent <MapCreator> ();
            type    = SlotType.Normal;
        }

        if (square == null)
        {
            square = Resources.Load("square") as Texture2D;
        }
        if (red == null)
        {
            red = Resources.Load("red") as Texture2D;
        }
        if (green == null)
        {
            green = Resources.Load("green") as Texture2D;
        }
        if (black == null)
        {
            black = Resources.Load("black") as Texture2D;
        }

        for (int i = 0; i < (int)MapSize.Count; i++)
        {
            if (GUILayout.Button("Create New " + (MapSize)i))
            {
                creator.size = (MapSize)i;
                creator.BuildPreview(null);
            }
        }

        EditorGUILayout.BeginHorizontal();
        creator.id = EditorGUILayout.TextField("ID: ", creator.id);
        if (GUILayout.Button("Load Map"))
        {
            Map map = Resources.Load("Maps/" + creator.id) as Map;
            if (map != null)
            {
                creator.size       = map.size;
                creator.difficulty = map.difficulty;
                creator.frame      = map.frame;
                currentFrame       = (Texture2D)Resources.Load("Frames/" + map.frame);
            }

            creator.BuildPreview(map);
        }
        EditorGUILayout.EndHorizontal();

        creator.difficulty = EditorGUILayout.IntField("Difficulty: ", creator.difficulty);
        creator.title      = EditorGUILayout.TextField("Title: ", creator.title);

        currentFrame = (Texture2D)EditorGUILayout.ObjectField("Frame", currentFrame, typeof(Texture2D), allowSceneObjects: true);
        if (currentFrame != null)
        {
            creator.frame = currentFrame.name;
        }

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Save Map to " + creator.id + ".asset"))
        {
            Map map = creator.Create();

            if (!string.IsNullOrEmpty(creator.id))
            {
                Map existing = AssetDatabase.LoadAssetAtPath <Map>("Assets/Resources/Maps/" + creator.id + ".asset");
                if (existing != null)
                {
                    existing.UpdateDetails(map);
                }
                else
                {
                    AssetDatabase.CreateAsset(map, "Assets/Resources/Maps/" + creator.id + ".asset");
                }
                AssetDatabase.SaveAssets();
            }
        }

        if (GUILayout.Button("Discard Current Changes"))
        {
            creator.ClosePreview();
        }
        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Reverse"))
        {
            foreach (SlotPreview preview in creator.slots)
            {
                if (preview.slotType == SlotType.Normal)
                {
                    preview.slotType    = SlotType.Blank;
                    preview.cover.color = Color.black - new Color(0f, 0f, 0f, 0.5f);
                }
                else if (preview.slotType == SlotType.Blank)
                {
                    preview.slotType    = SlotType.Normal;
                    preview.cover.color = Color.white - new Color(0f, 0f, 0f, 0.5f);
                }
            }
        }
        if (GUILayout.Button("Fixed Broken Refrences"))
        {
            FixEditor();
        }

        GUILayout.Space(30f);

        string tool = "";

        switch (type)
        {
        case SlotType.Normal:
            tool = "Normal Brush";
            break;

        case SlotType.Safe:
            tool = "Safe Brush";
            break;

        case SlotType.Bomb:
            tool = "Bomb Brush";
            break;

        case SlotType.Blank:
            tool = "Eraser Brush";
            break;
        }
        GUILayout.Label("Currently using " + (isSmallBrush ? "1x1 " : "9x9 ") + tool);

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Brush Tool"))
        {
            type = SlotType.Normal;
        }
        if (GUILayout.Button("Safe Tool"))
        {
            type = SlotType.Safe;
        }
        if (GUILayout.Button("Mine Tool"))
        {
            type = SlotType.Bomb;
        }
        if (GUILayout.Button("Eraser Tool"))
        {
            type = SlotType.Blank;
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Small Brush"))
        {
            isSmallBrush = true;
        }
        if (GUILayout.Button("9x9 Brush"))
        {
            isSmallBrush = false;
        }
        EditorGUILayout.EndHorizontal();

        currentTex = (Sprite)EditorGUILayout.ObjectField("Sprite", currentTex, typeof(Sprite), allowSceneObjects: true);


        GUIStyle style = new GUIStyle(GUI.skin.label);

        style.padding = new RectOffset(0, 0, 0, 0);
        style.margin  = new RectOffset(0, 0, 0, 0);

        if (creator.slots != null && creator.slots.Length == creator.xSize * creator.ySize)
        {
            EditorGUILayout.BeginHorizontal();
            for (int i = 0; i < creator.xSize; i++)
            {
                EditorGUILayout.BeginVertical();
                for (int j = 0; j < creator.ySize; j++)
                {
                    int       index = i + j * creator.xSize;
                    Texture2D tex   = square;
                    if (creator.slots[index].slotType == SlotType.Safe)
                    {
                        tex = green;
                    }
                    else if (creator.slots[index].slotType == SlotType.Bomb)
                    {
                        tex = red;
                    }
                    else if (creator.slots[index].slotType == SlotType.Blank)
                    {
                        tex = black;
                    }
                    if (GUILayout.Button(tex, style, GUILayout.Width(20f), GUILayout.Height(20f)))
                    {
                        creator.slots [index].slotType = type;
                        if (currentTex != null)
                        {
                            creator.slots [index].cover.sprite = currentTex;
                        }
                        creator.slots [index].safeIcon.SetActive(false);
                        creator.slots [index].bombIcon.SetActive(false);
                        switch (type)
                        {
                        case SlotType.Normal:
                            creator.slots [index].cover.color = Color.white - new Color(0f, 0f, 0f, 0.5f);
                            break;

                        case SlotType.Safe:
                            creator.slots [index].cover.color = Color.white - new Color(0f, 0f, 0f, 0.5f);
                            creator.slots [index].safeIcon.SetActive(true);
                            break;

                        case SlotType.Bomb:
                            creator.slots [index].cover.color = Color.white - new Color(0f, 0f, 0f, 0.5f);
                            creator.slots [index].bombIcon.SetActive(true);
                            break;

                        case SlotType.Blank:
                            creator.slots [index].cover.color = Color.black - new Color(0f, 0f, 0f, 0.5f);
                            break;
                        }
                    }
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.BeginHorizontal();
        }
    }