Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.78 KB | None | 0 0
  1. using System.Collections;
  2. using System;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6.  
  7. public class StrategyManager : MonoBehaviour
  8. {
  9.     public enum Terrain { Forest, Dungeon, Town}
  10.     public enum Difficulty {Easy = 3, Medium = 4, Hard = 5 }
  11.     public List<Level> levelList = new List<Level>();
  12.     private LevelFactory factory = new LevelFactory();
  13.     private static System.Random rnd = new System.Random();
  14.  
  15.  
  16.     public class LevelFactory  // создает уровни
  17.     {  
  18.         Terrain GetRandomTerrain() // возвращаю рандомное имя террэйна
  19.         {        
  20.             var arr = Enum.GetValues(typeof(Terrain));
  21.             Terrain terrain = (Terrain)arr.GetValue(rnd.Next(arr.Length));
  22.             Debug.Log(terrain.ToString());
  23.             return terrain;    
  24.         }
  25.         public Level Create(Difficulty difficulty)  
  26.         {
  27.             Level lvl;
  28.             switch (GetRandomTerrain())  // по рандомному имени террэйна, создает объект нужного уровня, возвращает его как тип родителя.
  29.             {
  30.                 case Terrain.Forest:
  31.                     lvl = new L_Forest(difficulty);
  32.                     break;
  33.                 case Terrain.Dungeon:
  34.                     lvl = new L_Dungeon(difficulty);
  35.                     break;
  36.                 case Terrain.Town:
  37.                     lvl = new L_Town(difficulty);
  38.                     break;
  39.                 default:
  40.                     Debug.Log("Can't find terrain");
  41.                     lvl = null;
  42.                     break;
  43.             }
  44.  
  45.             return (Level)lvl;
  46.         }
  47.  
  48.     }
  49.     // Класс - родитель для уровней.
  50.     //Тут будут базовые методы для генерации, одинаковые для всех уровней,
  51.     //которые будут использовать переменные(коэффициенты) различных наследников.
  52.     //Такое возможно вообще?
  53.     public class Level {
  54.         protected int enemyCount;
  55.         protected string terrainName;
  56.         protected List<Unit> enemiesInCurrentTerrain;
  57.         public Level(Difficulty difficulty)
  58.         {
  59.            
  60.             enemyCount = (int)difficulty;
  61.            
  62.  
  63.         }
  64.         public void Print() // выводит инфу по созданному террэйну
  65.         {
  66.             Debug.Log(enemyCount + terrainName);
  67.         }
  68.        
  69.  
  70.         void SetEnemiesList() // создает список вражин
  71.         {
  72.             for (int i = 0; i < enemyCount; i++)
  73.             {
  74.  
  75.             }
  76.         }
  77.        
  78.     }
  79.     // классы террэйнов
  80.     public class L_Forest : Level
  81.     {
  82.        
  83.         public L_Forest(Difficulty difficulty) : base(difficulty)
  84.         {
  85.             terrainName = "Forest";
  86.            
  87.         }
  88.     }
  89.     public class L_Dungeon : Level
  90.     {
  91.         public L_Dungeon(Difficulty difficulty) : base(difficulty)
  92.         {
  93.             terrainName = "Dungeon";
  94.         }
  95.     }
  96.     public class L_Town : Level
  97.     {
  98.         public L_Town(Difficulty difficulty) : base(difficulty)
  99.         {
  100.             terrainName = "Town";
  101.         }
  102.     }
  103.  
  104.    
  105.     void Start () {
  106.        
  107.         GetLevels();
  108.     }
  109.  
  110.     //Создает три уровня сложности, с разным террэйном.
  111.     public void GetLevels()
  112.     {
  113.         levelList.Add(factory.Create(Difficulty.Easy));
  114.         levelList.Add(factory.Create(Difficulty.Medium));
  115.         levelList.Add(factory.Create(Difficulty.Hard));
  116.         foreach (Level lvl in levelList)
  117.         {
  118.             lvl.Print();
  119.         }
  120.     }
  121.  
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement