Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.58 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System.IO;
  6. using System.Linq;
  7.  
  8. public class Main_Controller : MonoBehaviour
  9. {
  10.     //Toggles
  11.     [Header("TOGGLES")]
  12.     public Toggle _ObjectToggle;
  13.     public Toggle _QualityObjectToggle;
  14.     public Toggle _QualityPlaceToggle;
  15.     public Toggle _PlaceToggle;
  16.     public Toggle _ZoneToggle;
  17.  
  18.     public Toggle _DesignToggle;
  19.  
  20.  
  21.     //Container for objects
  22.     public List<string> _Objects;
  23.     public List<string> _Qualities;
  24.     public List<string> _Places;
  25.     public List<string> _PlacesQualities;
  26.     public List<string> _Design;
  27.     public List<string> _Zones;
  28.  
  29.     //Display the Objects
  30.     public Text _ObjectBox;    
  31.  
  32.     protected StreamReader _ObjectReader = null;
  33.     protected StreamReader _QualityReader = null;
  34.     protected StreamReader _PlacesQualityReader = null;
  35.     protected StreamReader _PlaceReader = null;
  36.     protected StreamReader _DesignReader = null;
  37.     protected StreamReader _ZoneReader = null;
  38.  
  39.  
  40.     private int _ObjectsCount;
  41.     private int _QualityCount;
  42.     private int _PlaceCount;
  43.     private int _DesignCount;
  44.     private int _ZoneCount;
  45.     private int _placesQualityCount;
  46.  
  47.     // Start is called before the first frame update
  48.     void Start()
  49.     {
  50.         _ObjectReader = new StreamReader("Assets/TextSource/Objects.txt");
  51.         _ObjectsCount = File.ReadAllLines(@"Assets/TextSource/Objects.txt").Length;
  52.  
  53.         _QualityReader = new StreamReader("Assets/TextSource/Qualities.txt");
  54.         _QualityCount = File.ReadAllLines(@"Assets/TextSource/Qualities.txt").Length;
  55.  
  56.         _PlaceReader = new StreamReader("Assets/TextSource/Places.txt");
  57.         _PlaceCount = File.ReadAllLines(@"Assets/TextSource/Places.txt").Length;
  58.  
  59.         _DesignReader = new StreamReader("Assets/TextSource/Design.txt");
  60.         _DesignCount = File.ReadAllLines(@"Assets/TextSource/Design.txt").Length;
  61.  
  62.         _ZoneReader = new StreamReader("Assets/TextSource/Zones.txt");
  63.         _ZoneCount = File.ReadAllLines(@"Assets/TextSource/Zones.txt").Length;
  64.  
  65.         _PlacesQualityReader = new StreamReader("Assets/TextSource/PlaceQualities.txt");
  66.         _placesQualityCount = File.ReadAllLines(@"Assets/TextSource/PlaceQualities.txt").Length;
  67.  
  68.         for (int i = 0; i < _ObjectsCount; i++)
  69.         {
  70.             _Objects.Add(_ObjectReader.ReadLine());
  71.         }
  72.  
  73.         for (int i = 0; i < _QualityCount; i++)
  74.         {
  75.             _Qualities.Add(_QualityReader.ReadLine());
  76.         }
  77.  
  78.         for (int i = 0; i < _PlaceCount; i++)
  79.         {
  80.             _Places.Add(_PlaceReader.ReadLine());
  81.         }
  82.  
  83.         for (int i = 0; i < _DesignCount; i++)
  84.         {
  85.             _Design.Add(_DesignReader.ReadLine());
  86.         }
  87.  
  88.         for (int i = 0; i < _ZoneCount; i++)
  89.         {
  90.             _Zones.Add(_ZoneReader.ReadLine());
  91.         }
  92.         for (int i = 0; i < _placesQualityCount; i++)
  93.         {
  94.             _PlacesQualities.Add(_PlacesQualityReader.ReadLine());
  95.         }
  96.  
  97.     }
  98.  
  99.     // Update is called once per frame
  100.     void Update()
  101.     {
  102.       if(Input.GetKeyDown(KeyCode.Escape))
  103.         {
  104.             QuitApplication();
  105.         }
  106.     }
  107.  
  108.     public void Generate()
  109.     {
  110.         _ObjectBox.text = "";
  111.  
  112.         //Adds a quality to object
  113.  
  114.  
  115.         //adds object
  116.         if (_ObjectToggle.isOn)
  117.         {
  118.  
  119.             string text;
  120.  
  121.             if (_QualityObjectToggle.isOn)
  122.             {
  123.  
  124.                 text = _Qualities[Random.Range(0, _QualityCount - 1)];
  125.                 if (StartWithVowel(text))
  126.                 {
  127.                     _ObjectBox.text += "An ";
  128.  
  129.                 }
  130.                 else
  131.                 {
  132.                     _ObjectBox.text += "A ";
  133.  
  134.                 }
  135.                 _ObjectBox.text += text;
  136.  
  137.                 _ObjectBox.text += " ";
  138.                 _ObjectBox.text += _Objects[Random.Range(0, _ObjectsCount - 1)];
  139.             }
  140.             else
  141.             {
  142.  
  143.                 text = _Objects[Random.Range(0, _QualityCount - 1)];
  144.  
  145.                 if (StartWithVowel(text))
  146.                 {
  147.                     _ObjectBox.text += "An ";
  148.  
  149.                 }
  150.                 else
  151.                 {
  152.                     _ObjectBox.text += "A ";
  153.  
  154.                 }
  155.                 _ObjectBox.text += text;
  156.  
  157.             }
  158.  
  159.         }
  160.         if (_ObjectToggle.isOn && _PlaceToggle.isOn)
  161.         {
  162.             _ObjectBox.text += " found in ";
  163.  
  164.         }
  165.      
  166.  
  167.         //adds place
  168.         if (_PlaceToggle.isOn)
  169.         {
  170.  
  171.             string text;
  172.  
  173.             if (_QualityPlaceToggle.isOn)
  174.             {
  175.  
  176.                 text = _PlacesQualities[Random.Range(0, _placesQualityCount - 1)];
  177.  
  178.                 if (StartWithVowel(text))
  179.                 {
  180.                     _ObjectBox.text += "An ";
  181.  
  182.                 }
  183.                 else
  184.                 {
  185.                     _ObjectBox.text += "A ";
  186.  
  187.                 }
  188.                 _ObjectBox.text += text;
  189.  
  190.                 _ObjectBox.text += " ";
  191.                 _ObjectBox.text += _Places[Random.Range(0, _PlaceCount - 1)];
  192.             }
  193.             else
  194.             {
  195.  
  196.                 text = _Places[Random.Range(0, _PlaceCount - 1)];
  197.  
  198.                 if (StartWithVowel(text))
  199.                 {
  200.                     _ObjectBox.text += "An ";
  201.  
  202.                 }
  203.                 else
  204.                 {
  205.                     _ObjectBox.text += "A ";
  206.  
  207.                 }
  208.                 _ObjectBox.text += text;
  209.  
  210.             }
  211.  
  212.             if(_ZoneToggle.isOn)
  213.             {
  214.                 _ObjectBox.text += " located ";
  215.                 _ObjectBox.text += _Zones[Random.Range(0, _ZoneCount - 1)];
  216.  
  217.             }
  218.  
  219.         }
  220.  
  221.  
  222.         if (_DesignToggle.isOn)
  223.         {
  224.             string text;
  225.             _ObjectBox.text += ".\n Inspired by ";
  226.  
  227.             text = _Design[Random.Range(0, _DesignCount - 1)];
  228.  
  229.             if (StartWithVowel(text))
  230.             {
  231.                 _ObjectBox.text += "an ";
  232.  
  233.             }
  234.             else
  235.             {
  236.                 _ObjectBox.text += "a ";
  237.  
  238.             }
  239.             _ObjectBox.text += text;
  240.  
  241.         }
  242.  
  243.     }
  244.  
  245.  
  246.  
  247.  
  248.  
  249.     private bool StartWithVowel(string word)
  250.     {
  251.         char[] initial;
  252.         initial = word.ToCharArray();
  253.         if (initial[0] == 'A' || initial[0] == 'E' || initial[0] == 'I' || initial[0] == 'O' || initial[0] == 'U')
  254.         {
  255.  
  256.             return true;
  257.         }
  258.         else return false;
  259.     }
  260.  
  261.  
  262.     public void QuitApplication()
  263.     {
  264.         Application.Quit();
  265.     }
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement