Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class StrategyManager : MonoBehaviour
- {
- public enum Terrain { Forest, Dungeon, Town}
- public enum Difficulty {Easy = 3, Medium = 4, Hard = 5 }
- public List<Level> levelList = new List<Level>();
- private LevelFactory factory = new LevelFactory();
- private static System.Random rnd = new System.Random();
- public class LevelFactory // создает уровни
- {
- Terrain GetRandomTerrain() // возвращаю рандомное имя террэйна
- {
- var arr = Enum.GetValues(typeof(Terrain));
- Terrain terrain = (Terrain)arr.GetValue(rnd.Next(arr.Length));
- Debug.Log(terrain.ToString());
- return terrain;
- }
- public Level Create(Difficulty difficulty)
- {
- Level lvl;
- switch (GetRandomTerrain()) // по рандомному имени террэйна, создает объект нужного уровня, возвращает его как тип родителя.
- {
- case Terrain.Forest:
- lvl = new L_Forest(difficulty);
- break;
- case Terrain.Dungeon:
- lvl = new L_Dungeon(difficulty);
- break;
- case Terrain.Town:
- lvl = new L_Town(difficulty);
- break;
- default:
- Debug.Log("Can't find terrain");
- lvl = null;
- break;
- }
- return (Level)lvl;
- }
- }
- // Класс - родитель для уровней.
- //Тут будут базовые методы для генерации, одинаковые для всех уровней,
- //которые будут использовать переменные(коэффициенты) различных наследников.
- //Такое возможно вообще?
- public class Level {
- protected int enemyCount;
- protected string terrainName;
- protected List<Unit> enemiesInCurrentTerrain;
- public Level(Difficulty difficulty)
- {
- enemyCount = (int)difficulty;
- }
- public void Print() // выводит инфу по созданному террэйну
- {
- Debug.Log(enemyCount + terrainName);
- }
- void SetEnemiesList() // создает список вражин
- {
- for (int i = 0; i < enemyCount; i++)
- {
- }
- }
- }
- // классы террэйнов
- public class L_Forest : Level
- {
- public L_Forest(Difficulty difficulty) : base(difficulty)
- {
- terrainName = "Forest";
- }
- }
- public class L_Dungeon : Level
- {
- public L_Dungeon(Difficulty difficulty) : base(difficulty)
- {
- terrainName = "Dungeon";
- }
- }
- public class L_Town : Level
- {
- public L_Town(Difficulty difficulty) : base(difficulty)
- {
- terrainName = "Town";
- }
- }
- void Start () {
- GetLevels();
- }
- //Создает три уровня сложности, с разным террэйном.
- public void GetLevels()
- {
- levelList.Add(factory.Create(Difficulty.Easy));
- levelList.Add(factory.Create(Difficulty.Medium));
- levelList.Add(factory.Create(Difficulty.Hard));
- foreach (Level lvl in levelList)
- {
- lvl.Print();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement