IEnumerator CreaVivienda() { int[] createdPos = new int[2] { _row, _column }; // soundControl.clip = createBuildingSound; // soundControl.Play(); _ciudadanosDisponibles -= _buildings[3].PersonalRequerido; Vector3 myPosition = selected.transform.position; _presupuesto -= _buildings[3].CostoConstruccion; PresupuestoT.text = _presupuesto.ToString(); yield return(StartCoroutine(ConstruyeTimer(_buildings[3].TiempoConstruccion))); GameObject building = Instantiate(_buildings[3]._instance, new Vector3(myPosition.x, myPosition.y + 0.5f, myPosition.z), Quaternion.identity) as GameObject; _ciudadanosDisponibles += _buildings[3].PersonalRequerido; numeroViviendas += 1; timeLerped = 0.0f; StartCoroutine(ConterSpeed("poblacion", habitantes.Count, habitantes.Count + 20)); for (int i = 0; i < 20; i++) { HumanClass habitante = new HumanClass(); habitante.CM = this; habitantes.Add(habitante); } _ciudadanosDisponibles += 20; PoblacionT.text = _poblacion.ToString(); creations.Add(new BuildingsCreated() { PosX = createdPos[0], PosY = createdPos[1], _instance = building, BuildType = 3 }); }
static void Main(string[] args) { HumanClass Ben = new HumanClass("Ben"); Console.WriteLine($"{Ben.Name} is losing his mind"); Buffet firstBuffet = new Buffet(); Console.WriteLine($"{Ben.Name} got a {firstBuffet.Serve().Name}"); Ninja carol = new Ninja("Carol"); Console.WriteLine($"{carol.Name} is a ninja!"); carol.Eat(firstBuffet.Serve()); carol.Eat(firstBuffet.Serve()); carol.Eat(firstBuffet.Serve()); carol.Eat(firstBuffet.Serve()); Wizard ben = new Wizard("Ben", 17, 19); Ninja wale = new Ninja("Wale", 17, 19, 150); Samurai lola = new Samurai("Lola", 17, 19, 80); ben.DisplayStats(); wale.DisplayStats(); lola.DisplayStats(); // ben.Attack(wale); wale.Attack(ben); ben.DisplayStats(); lola.Attack(wale); ben.Heal(wale); lola.Meditate(); wale.Steal(ben); }
// public void SetNextDisaster() // { // _link.CallDisaster (); // } void LoadIfExists() { DataStorage _ds = GameObject.FindObjectOfType <DataStorage> (); if (_ds != null) { // if (!_ds._usingEvents) { // Debug.Log ("No invocar eventos"); // _link.CancelAllNotification(); // } else // { // Debug.Log ("Invocar Eventos"); // _link.CallDisaster (); // } if (_ds._dataStored != null) { StatsData sd = _ds._dataStored; BuildingsCreated[] bc = sd._totalBuildings; _poblacion = sd.aldeanosTotal; _presupuesto = sd.dinero; _comida = sd.comida; _ciudadanosSinComida = sd.aldeanosHambrientos; // _ciudadanosEnfermos = sd.aldeanosEnfermos; Hambrientos.text = _ciudadanosSinComida.ToString(); // EnfermosT.text = _ciudadanosEnfermos.ToString ();; for (int i = 0; i < _poblacion; i++) { HumanClass habitante = new HumanClass(); habitante.CM = this; habitantes.Add(habitante); } // for (int i = 0; i < _ciudadanosEnfermos; i++) // { // habitantes [i].TieneSalud = false; // } for (int x = 0; x < bc.Count(); x++) { GameObject parent = MatrixPro [bc [x].PosX].ObjectRow [bc [x].PosY]; Vector3 myPosition = parent.transform.position; GameObject building = Instantiate(_buildings [bc [x].BuildType]._instance, new Vector3(myPosition.x, myPosition.y + 0.5f, myPosition.z), Quaternion.identity) as GameObject; AreaMatrix [bc [x].PosX, bc [x].PosY] = true; switch (bc [x].BuildType) { case 0: // numeroHospitales++; break; case 1: numeroGranjas++; break; case 2: break; case 3: numeroViviendas++; break; case 4: numeroBancos++; break; case 5: numeroBancos++; break; } if (bc [x].BuildType != 3) { ChargeScript cs = building.GetComponent <ChargeScript> (); cs.parentTransform = TimerArea.transform; cs.CM = this; } } } else { _poblacion = 100; _presupuesto = 1000; _comida = 1000; Hambrientos.text = "0"; // EnfermosT.text = "0"; for (int i = 0; i < _poblacion; i++) { HumanClass habitante = new HumanClass(); habitante.CM = this; habitantes.Add(habitante); } } Destroy(_ds.gameObject); } else { _poblacion = 100; _presupuesto = 1000; _comida = 1000; Hambrientos.text = "0"; // EnfermosT.text = "0"; for (int i = 0; i < _poblacion; i++) { HumanClass habitante = new HumanClass(); habitante.CM = this; habitantes.Add(habitante); } } }
public void AddTask(Task newTask, HumanClass humanClass) { tasks.Add(newTask); BindTaskToWorker(humanClass, newTask); Debug.Log("Task " + newTask.GetTaskType() + " added"); }
public void BindTaskToWorker(HumanClass freeWorker, Task task) { freeWorker.SetCurentTask(task); task.humanClass = freeWorker; }
static void Main(string[] args) { //1) Написати метод з використанням масивів мінімум 3 типів, та використання їх методів // тут три масива різних типів + два метода з перезавантаженнями - по пунтку 2 MethodsOfArray(); //2) Написати 5 методів та їх перевантажені методи мінімум по 1(перевантаженому); //два метода з перезавантаженнями (FillArray) i (WriteArray) викликались в першому пункті MethodsOfArray //для тварин - метод з перезавантаженням AnimalActivity (третій метод з перезавантаженням) Animal cat1 = new Animal("Murka", AnimalType.Cat); Animal cat2 = new Animal("Pushinka", AnimalType.Cat); AnimalActivity(cat1, 3, true, true); AnimalActivity(cat2, 5, false, true); Animal dog1 = new Animal("Tuzik", AnimalType.Dog); AnimalActivity(dog1, 10, true, true); Animal horse1 = new Animal("NightMare", AnimalType.Hourse); AnimalActivity(horse1, 10, true, true); Animal ameba1 = new Animal(); AnimalActivity(ameba1, 1, false, false); //четвертий метод - боротьба з коронавірусом WarWithCoronavirus(12300); WarWithCoronavirus(999999); WarWithCoronavirus(60_000_000, 10); WarWithCoronavirus(60_000_000, 100); //пятий метод - оцінка по документації проекта ProjectDocumentation("This is project NNN"); //Header ProjectDocumentation("This is project RRR", "some comment /n some comment /n some comment /n some comment"); //Header,Comments ProjectDocumentation("This is project GGG", "some comment /n some comment ", "So u can see this is seriuos big project"); //Header,Comments, Results //3) Написати метод з використанням трьох Nullable змінних, та використанням можливлстей які він пропонує; string Name1 = "Person1"; bool? gender1 = null; int? childrenQuantity1 = null; decimal?Fee1 = null; if (RegistrationForm(Name1, gender1, childrenQuantity1, Fee1) == false) { Console.WriteLine("Can not register {0}! Check required properties!", Name1); } string Name2 = "Person2"; bool? gender2 = true; int? childrenQuantity2 = null; decimal?Fee2 = null; if (RegistrationForm(Name2, gender2, childrenQuantity2, Fee2) == false) { Console.WriteLine("Can not register {0}! Check required properties!", Name2); } string Name3 = "Person3"; bool? gender3 = false; int? childrenQuantity3 = 1; decimal?Fee3 = null; if (RegistrationForm(Name3, gender3, childrenQuantity3, Fee3) == false) { Console.WriteLine("Can not register {0}! Check required properties!", Name3); } string Name4 = "Person4"; bool? gender4 = true; int? childrenQuantity4 = 2; decimal?Fee4 = null; if (RegistrationForm(Name4, gender4, childrenQuantity4, Fee4) == false) { Console.WriteLine("Can not register {0}! Check required properties!", Name4); } string Name5 = "Person5"; bool? gender5 = false; int? childrenQuantity5 = 5; decimal?Fee5 = 100m; if (RegistrationForm(Name5, gender5, childrenQuantity5, Fee5) == false) { Console.WriteLine("Can not register {0}! Check required properties!", Name5); } //4) Написати два методи з використанням опціональних параметрів та два з використанням named$ //опціональний 1 + він же і з іменованим параметром SendPlane("Boeing"); SendPlane("An", "Jacky Chan", "China"); SendPlane(pilot: "Ivan Sirko", countryDestination: "Turkey"); //опціональний 2 + named PlayOrchestra(nameOfPerformance: "Lakme", authorName: "Leo Delib", cityOfOrchestra: "Paris"); PlayOrchestra(); //5) Написати по два методи з використанням out, ref, params; ParamsVoid1("Snow White", "Dwarf1", "Dwarf #2", "Dwarf-that-is-smaller-than-other"); ParamsVoid1("Prince", "Dwarf1", "Dwarf-who-is-the-oldest-one"); ParamsVoid2(10, 9, 8, 7, 6, 5, 4); ParamsVoid2(1, 2, 3); ParamsVoid2(0, 1); int z; OutVoid1(2, 6, out z); int t; OutVoid2(7, 4, out t); int coints = 0; RefVoid1(ref coints); bool registered = true; RefVoid2(ref registered); RefVoid2(ref registered); //6) Написати структуру Human(поля: ПІП, вік, стать); HumanStruct human1; human1.NameSurname = "Petro Petrovych"; human1.Age = 50; human1.Sex = "Male"; Console.WriteLine("name {0} age {1} sex {2}", human1.NameSurname, human1.Age, human1.Sex); //7) Написати клас аналогічний структурі вище в ньому стать має представлятись як перерахування; HumanClass human2 = new HumanClass(); Console.WriteLine("name {0} age {1} sex {2}", human2.NameSurname, human2.Age, human2.Sex); HumanClass human3 = new HumanClass(); human1.NameSurname = "Petro Petrovych"; human1.Age = 50; human1.Sex = "Male"; Console.WriteLine("name {0} age {1} sex {2}", human3.NameSurname, human3.Age, human3.Sex); //8) Написати клас Істота(Being) де як вище тільки придумати як відобразити що стать може бути не визначена; Being creature1 = new Being(); Console.WriteLine("name {0} age {1} sex {2}", creature1.NameSurname, creature1.Age, creature1.Sex); Being dog = new Being("Bai", 6, SexType.Male); Console.WriteLine("name {0} age {1} sex {2}", dog.NameSurname, dog.Age, dog.Sex); Being Angel = new Being() { Age = 3, Sex = SexType.Female, NameSurname = "Yaroslava Voitovych" }; Console.WriteLine("name {0} age {1} sex {2}", Angel.NameSurname, Angel.Age, Angel.Sex); //9) Замість використання цих трох типів(останніх) використати кортежі написати три методи по одному на кожен тип }
static void ChangeClass(ref HumanClass hs) { hs.age = 80; hs = new HumanClass(); hs.age = 25; }
public HumanStruct(string name)//---must be initilazed all params { this.name = name; this.age = 10; humanClass = null; }
static void Main(string[] args) { // checked //{ // short a = short.Parse(Console.ReadLine()); // //a += 1000; // //Console.WriteLine(a); // short a1 = short.Parse(Console.ReadLine()); // a = checked((byte)(a + a1)); // Console.WriteLine(a); //} //checked //{ // byte b = 255; // b += 2; // Console.WriteLine(b); //} //Foo(20, 12, 25, 23, 2.3, "hgfhgfhg"); //Foo2(2,3,5); //Foo2(113,2,3,5,6); HumanStruct hStr = new HumanStruct(); hStr.Init(); // HumanStruct hStr2;//---no default values for params HumanStruct hStr2 = new HumanStruct(); hStr2.Init(); Console.WriteLine($"name { hStr.name } age { hStr.age }"); //Console.WriteLine($"name { hStr2.name } age { hStr2.age }"); Change(ref hStr); Console.WriteLine($"name { hStr.name } age { hStr.age }"); Console.WriteLine("-------------------------------------"); HumanClass hc = new HumanClass(); hc.name = "Vasja"; Console.WriteLine($"name { hc.name } age { hc.age }"); ChangeClass(ref hc); Console.WriteLine($"name { hc.name } age { hc.age }"); Console.WriteLine("-------------------------------------"); hStr2 = hStr; //---its two different objects hStr.age = 13; hStr.humanClass.age = 100; Console.WriteLine($"name { hStr.name } age { hStr.age } humanClassAge {hStr.humanClass.age} hashCode {hStr.GetHashCode()}"); Console.WriteLine($"name { hStr2.name } age { hStr2.age } humanClassAge {hStr.humanClass.age} hashCode {hStr2.GetHashCode()}"); Console.WriteLine("-------------------------------------"); HumanClass hc2 = hc;//----its only one object and two references hc.age = 13; Console.WriteLine($"name { hc.name } age { hc.age } hashCode {hc.GetHashCode()}"); Console.WriteLine($"name { hc2.name } age { hc2.age } hashCode {hc2.GetHashCode()}"); DateTime zeroTime = new DateTime(1, 1, 1); DateTime dt = new DateTime(1986, 12, 10); TimeSpan t = dt - DateTime.Now; int years = (zeroTime + t).Year - 1; Thread.Sleep(200); }
//public HumanStruct()//---can't do this for struct //{ // this.name = "khkj"; // this.age = 10; //} public void Init() { humanClass = new HumanClass(); humanClass.age = 99; }
// Use this for initialization void Start() { // Conditionals /* * // Normal if statement * if (myNumber == 2) * { * Debug.Log("Your number is equal to 2."); * } * else * { * Debug.Log("Your number is not equal to 2."); * } * * // Short if statement * if (questionTime) * { * Debug.Log("Question time is true"); * } * else * { * Debug.Log("Question time is false"); * } * * // Variable name is equal to either 1 or 0 based on the value of questionTime * myVariableQuestionTime = (questionTime == true) ? 1 : 0; * Debug.Log("The value of myVariableQuestionTime is: " + myVariableQuestionTime); * * // Question concatenation * if (myNumber == 2 && questionTime == false) * { * Debug.Log("Your number is 2 and QT is false"); * } * * // Question or statement * if (myNumber == 2 || questionTime == false) * { * Debug.Log("It may be that your number is 2 or it may be that QT is false"); * } * * // Loops * * // For loop statement (start value, how this ends, incrementation) * for (int i = 0; i < fruits.Length; i = i + 1) * { * Debug.Log("Fruit at position " + i + "is " + fruits[i]); * } * * // Add 10 even numbers from 0 to 20 * for (int i = 0; i < 20; i = i + 2) * { * evenNumbers.Add(i); * evenNumbersSmart[i / 2] = i; * } * * // Print the list * for (int i = 0; i < evenNumbers.Count; i++) // i = i + 1, i++ * { * Debug.Log("Number is: " + evenNumbers[i]); * } * * // Add 100 numbers to list and print the numbers that are divisible by 5 * List<int> myOneHundredNumbers = new List<int>(); * for (int i = 0; i <= 100; i++) * { * myOneHundredNumbers.Add(i); * } * * // The smart way * for (int i = 0; i < myOneHundredNumbers.Count; i = i + 5) * { * Debug.Log("Numbers divisible by 5: " + myOneHundredNumbers[i]); * } * * // The less smart way * for (int i = 0; i <= 100; i++) * { * if (i % 5 == 0) * { * Debug.Log("Numbers divisible by 5: " + myOneHundredNumbers[i]); * } * } * * // While loop * List<int> oddNumbers = new List<int>(); * int counter = 1; * while (counter < 100) * { * oddNumbers.Add(counter); * counter = counter + 2; * } * for (int i = 0; i < oddNumbers.Count; i++) * { * Debug.Log("Odd number : " + oddNumbers[i]); * } */ // Create the tutors HumanClass Octavian = new HumanClass(31, 1.7f, true, "Octavian", "Gheorghiu"); HumanClass Tyson = new HumanClass(34, 1.8f, true, "Tyson", "Hosmer"); HumanClass Dave = new HumanClass(33, 1.75f, true, "Dave", "Reeves"); rc3Tutors.Add(Octavian); rc3Tutors.Add(Tyson); rc3Tutors.Add(Dave); }