Inheritance: MonoBehaviour
Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
            //Addition
            int number1, number2;

            Console.WriteLine("Addition");
            Console.WriteLine("Please enter first number:");
            number1 = int.Parse(Console.ReadLine());
            Console.WriteLine("Please enter second number:");
            number2 = int.Parse(Console.ReadLine());
            Console.WriteLine("Sum is " + (number1 + number2));
            //expandoobject
            dynamic user = new System.Dynamic.ExpandoObject();

            user.Name     = "It's Me";
            user.Age      = 666;
            user.Location = "Here";
            Console.WriteLine(user.Name + " " + user.Age + " " + user.Location);
            //var
            var camelCase = new {
                Name       = "Person",
                PascalCase = true
            };

            Console.WriteLine(camelCase.Name + " " + camelCase.PascalCase);
            //dynamic
            dynamic thingus = new
            {
                Item = "Henlo"
            };

            Console.WriteLine(thingus.Item);
            thingus = "different";
            Console.WriteLine(thingus + " " + thingus.Length);
            //lists
            List <string> listOfNames = new List <string>()
            {
                "John Doe",
                "Jane Doe",
                "Joe Doe",
                "Another Doe"
            };

            listOfNames.RemoveAll(name =>
            {
                if (name.StartsWith("J"))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });
            Console.WriteLine(listOfNames[0]);
            //dictionaries
            Dictionary <string, int> users = new Dictionary <string, int>()
            {
                { "John Doe", 42 },
                { "Jane Doe", 38 },
                { "Joe Doe", 12 },
                { "Jenna Doe", 12 }
            };

            foreach (KeyValuePair <string, int> what in users.OrderBy(what => what.Value))
            {
                Console.WriteLine(what.Key + " is " + what.Value + " years old");
            }
            //classes
            Car car;

            car = new Car("Red");
            Console.WriteLine(car.Describe());
            //inheritance
            Animal a = new Animal();

            a.Greet();
            Dog d = new Dog();

            d.Greet();
            //abstract classes
            Dog2 fla = new Dog2();

            Console.WriteLine(fla.Describe());
            //interfaces
            List <Dog3> dogs = new List <Dog3>();

            dogs.Add(new Dog3("Fido"));
            dogs.Add(new Dog3("Bob"));
            dogs.Add(new Dog3("Adam"));
            dogs.Sort();
            foreach (Dog3 dog in dogs)
            {
                Console.WriteLine(dog.Describe());
            }
            //const and readonly
            const int answerToLife = 42;
            SomeClass s            = new SomeClass();

            Console.WriteLine(s.later);
            //operators
            int?   i     = null;
            string value = null;

            Console.WriteLine(value ?? "No Value");
            double daysSinceMillenium = (DateTime.Now - new DateTime(2000, 1, 1)).TotalDays;

            Console.WriteLine($"Today is {DateTime.Now:d} and {daysSinceMillenium:N2} days have passed since the last millennium!");
            //enums
            Days day = (Days)5;

            Console.WriteLine(day);
            string[] values = Enum.GetNames(typeof(Days));
            foreach (string s1 in values)
            {
                Console.WriteLine(s1);
            }
            //structs
            Car2 car2;

            car2 = new Car2("Blue");
            Console.WriteLine(car2.Describe());
            Console.ReadLine();
        }
Esempio n. 2
0
 // Use this for initialization
 void Start()
 {
     Car1.GetComponent <Rigidbody>().isKinematic = false;
     Car2.GetComponent <Rigidbody>().isKinematic = false;
 }
        public static void AbstractExample()
        {
            var car = new Car2(10, 100, 234324);

            car.Move(2);
        }
Esempio n. 4
0
 // Start is called before the first frame update
 void Start()
 {
     _gameManager = GameObject.Find("GameManager").GetComponent <GameManager>();
     _c1          = GameObject.Find("Car1").GetComponent <Car1>();
     _c2          = GameObject.Find("Car2").GetComponent <Car2>();
 }
Esempio n. 5
0
 // Start is called before the first frame update
 void Start()
 {
     c1         = GameObject.Find("Car1").GetComponent <Car1>();
     c2         = GameObject.Find("Car2").GetComponent <Car2>();
     _uiManager = GameObject.Find("Canvas").GetComponent <UIManager>();
 }
Esempio n. 6
0
        // NAME              :-  MAIN METHOD
        // AUTHOR NAME       :-  SHIKHA MALIK
        // DECRIPTION        :-  MAIN METHOD
        // CREATED DATE      :-  16/07/2012
        static void Main(string[] args)
        {
            string strS; Vowel objVowel; SwitchVowel objSvowel; CaseCheck objCaseCheck; Reverse objReverse; PowerNum objPowerNum; WindowName objWindowName;                                                     //Declaration of variable
            char   chr = 'a'; int n, m; ArrayList arrLstN = new ArrayList(); List <object> arrLstlist = new List <object>();

            StructDate[]   objdt; ReverseSort objReverse1; SearchArray objSearchArray; ReviseArray objReviseArray; CopyArray objCopyArray; NotePadApplication objNotePadApplication;
            Franchisee     objFranchisee; Customer objCustomer; BubbleSort objBubbleSort; TransformArry objTransformArry; CastValue objCastValue; StringBldr objStringBldr;
            StructDate     objStructure; DateArray objDateArray; TextFile objTextFile; ReadTextFile objReadTextFile; ArrayList arrLstCarArmd = new ArrayList();
            List <object>  objListCar5 = new List <object>(); Driver objDriver; Car objCar; Car2 objCar2; Car3 objCar3; Car4 objCar4; ArmoredVehicle objArmoredVehicle;
            CarArmoredVcle objCarArmoredVcle; CarArmoredVcle1 objCarArmoredVcle1; Car5 objCar5; List <object> objArryLstD = new List <object>(); List <object> objArryLstD1 = new List <object>();

            try
            {
                System.Console.WriteLine(Constant.strEntrP1);
                System.Console.WriteLine(Constant.strEntrP2);
                System.Console.WriteLine(Constant.strEntrP3);
                System.Console.WriteLine(Constant.strEntrP4);
                System.Console.WriteLine(Constant.strEntrP5);
                System.Console.WriteLine(Constant.strEntrP6);
                System.Console.WriteLine(Constant.strEntrP7);
                System.Console.WriteLine(Constant.strEntrP8);
                System.Console.WriteLine(Constant.strEntrP9);
                System.Console.WriteLine(Constant.strEntrP10);
                System.Console.WriteLine(Constant.strEntrP11);
                System.Console.WriteLine(Constant.strEntrP12);
                System.Console.WriteLine(Constant.strEntrP13);
                System.Console.WriteLine(Constant.strEntrP14);
                System.Console.WriteLine(Constant.strEntrP15);
                System.Console.WriteLine(Constant.strEntrP16);
                System.Console.WriteLine(Constant.strEntrP17);
                System.Console.WriteLine(Constant.strEntrP18);
                System.Console.WriteLine(Constant.strEntrP19);
                System.Console.WriteLine(Constant.strEntrP20);
                System.Console.WriteLine(Constant.strEntrP21);
                System.Console.WriteLine(Constant.strEntrP22);
                System.Console.WriteLine(Constant.strEntrP23);
                System.Console.WriteLine(Constant.strEntrP24);
                System.Console.WriteLine(Constant.strEntrP25);
                System.Console.WriteLine(Constant.strEntrP26);
                System.Console.WriteLine(Constant.strEntrP27);
                System.Console.WriteLine(Constant.strEntrP28);
                System.Console.WriteLine(Constant.strEntrP29);
                System.Console.WriteLine(Constant.strEntrP30);
                System.Console.WriteLine(Constant.strEntrP31);
                System.Console.WriteLine(Constant.strEntrP32);
                System.Console.WriteLine(Constant.strEntrP33);
                System.Console.WriteLine(Constant.strEntrP34);
                System.Console.WriteLine(Constant.strEntrP35);
                System.Console.WriteLine(Constant.strSpace);
                System.Console.WriteLine(Constant.strStar);
                do
                {
                    System.Console.WriteLine(Constant.strEntrCh);                                    //Gather Information regarding choice

                    strS = System.Console.ReadLine();                                                //Read value of string

                    switch (strS)
                    {
                    case "2.1":                                                    //case use for 2.1 exercise that is chracter is vowel or not
                        objVowel = new Vowel();                                    //create object for class
                        objVowel.vowelc();
                        break;

                    case "2.2":                                                  //case use for 2.2 exercise that is chracter is vowel or not using swith case
                        objSvowel = new SwitchVowel();                           //create object for class
                        objSvowel.Switchvl();
                        break;

                    case "2.3":                                                    //case use for 2.3 exercise that is for Enter digit , char in both case and count their times.
                        objCaseCheck = new CaseCheck();                            //create object for class
                        objCaseCheck.CaseC();
                        break;

                    case "2.4":                                                  //case use for 2.4 exercise that is use for reverse array
                        objReverse = new Reverse();                              //create object for class
                        objReverse.Rev();
                        break;

                    case "2.5":                                          // case use for 2.5 exercise that is use for reverse array and sort array
                        objReverse1 = new ReverseSort();                 //create object for class
                        objReverse1.RevS();
                        break;

                    case "2.6":                                           // case use for 2.6 exercise that is use for search element from arry
                        objSearchArray = new SearchArray();               //create object for class
                        objSearchArray.Sarray();
                        break;

                    case "2.7":                                            // case use for 2.7 exercise that is use for serch element and print number of times its exists.
                        objReviseArray = new ReviseArray();                //create object for class
                        objReviseArray.Rarray();
                        break;

                    case "2.8":                                           // case use for 2.8 exercise that is use for copy array according to condition
                        objCopyArray = new CopyArray();                   //create object for class
                        objCopyArray.Carray();
                        break;

                    case "2.9":                                             // case use for 2.9 exercise that is use for calculate the power of entered number
                        objPowerNum = new PowerNum();                       //create object for class
                        objPowerNum.Pwrnum();
                        break;

                    case "2.10":                                               // case use for 2.10 exercise that is used for open notepad
                        objNotePadApplication = new NotePadApplication();      //create object for class
                        objNotePadApplication.Notepad();
                        break;

                    case "2.11":                                       // case use for 2.11 exercise that is used for display required system information
                        objWindowName = new WindowName();              //create object for class
                        objWindowName.WinName();
                        break;

                    case "4.7":                                                                // case use for 4.7 exercise that is for arraylist
                        Console.WriteLine(Constant.strEnumObjArry);                            //message for enter number of object of Customer class
                        n = int.Parse(Console.ReadLine());
                        for (int i = 1; i <= n; i++)                                           // loop for number of times of object of Customer class
                        {
                            objCustomer = new Customer();
                            Console.WriteLine(Constant.strEntrsalCt + "" + i);
                            objCustomer.Salutation = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrNmCt + "" + i);
                            objCustomer.Name = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrMatCt + "" + i);
                            objCustomer.Maritial_Status = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrGenCt + "" + i);
                            objCustomer.Gender = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrAddCt + "" + i);
                            objCustomer.Address = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrQualCt + "" + i);
                            objCustomer.Qualification = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrLanCt + "" + i);
                            objCustomer.Language = Console.ReadLine();
                            arrLstN.Add(objCustomer);                                                //add into arraylist
                        }

                        Console.WriteLine(Constant.strEntrObjFrch);     // message for enter number of object of Franchisee class
                        m = int.Parse(Console.ReadLine());

                        for (int i = 1; i <= m; i++)                                            //  loop for number of times of object of Franchisee class
                        {
                            objFranchisee = new Franchisee();
                            Console.WriteLine(Constant.strEntrFeesFrch + "" + i);
                            objFranchisee.Fees = int.Parse(Console.ReadLine());
                            arrLstN.Add(objFranchisee);                                                //add into arraylist
                        }
                        Console.ReadLine();
                        break;

                    case "4.8":                                                               // case use for 4.8 exercise that is for show arraylist
                        for (int i = 0; i < arrLstN.Count; i++)
                        {
                            Console.WriteLine(arrLstN[i].ToString());
                        }

                        break;

                    case "4.9":                                                                           // case use for 4.9 exercise that is for Typed Arraylist
                        Console.WriteLine(Constant.strEnumObjList);                                       //message for enter number of object of Customer class
                        n = int.Parse(Console.ReadLine());
                        for (int i = 1; i <= n; i++)                                                      // loop for number of times of object of Customer class
                        {
                            objCustomer = new Customer();
                            Console.WriteLine(Constant.strEntrsalCt + "" + i);
                            objCustomer.Salutation = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrNmCt + "" + i);
                            objCustomer.Name = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrMatCt + "" + i);
                            objCustomer.Maritial_Status = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrGenCt + "" + i);
                            objCustomer.Gender = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrAddCt + "" + i);
                            objCustomer.Address = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrQualCt + "" + i);
                            objCustomer.Qualification = Console.ReadLine();
                            Console.WriteLine(Constant.strEntrLanCt + "" + i);
                            objCustomer.Language = Console.ReadLine();
                            arrLstlist.Add(objCustomer);                                                                 //  add into List
                        }

                        Console.WriteLine(Constant.strEntrObjFrch);
                        m = int.Parse(Console.ReadLine());
                        for (int i = 1; i <= m; i++)
                        {
                            objFranchisee = new Franchisee();
                            Console.WriteLine(Constant.strEntrFeesFrch + "" + i);


                            objFranchisee.Fees = int.Parse(Console.ReadLine());

                            arrLstlist.Add(objFranchisee);                                                               //  add into List
                        }

                        Console.ReadLine();
                        break;

                    case "4.10":                                                                         // case use for 4.10 exercise that is for show arraylist
                        for (int i = 0; i < arrLstlist.Count; i++)
                        {
                            Console.WriteLine(arrLstlist[i].ToString());
                        }
                        break;

                    case "4.11":                                                      //case use for 4.11 exercise that is use for sorting array
                        objBubbleSort = new BubbleSort();                             //create object for class
                        objBubbleSort.BublSrt();
                        break;

                    case "4.12":                                                   //case use for 4.12 exercise that is used for transform matrix
                        objTransformArry = new TransformArry();                    //create object for class
                        objTransformArry.TrnsfrmArr();
                        break;

                    case "4.13":                                                               //case use for 4.13 exercise that is used for casting of double value
                        objCastValue = new CastValue();
                        objCastValue.CastFltMy();                                              //create object for class
                        break;

                    case "4.14":                                                             //case use for 4.14 exercise that is used for convert input amount into string
                        objStringBldr = new StringBldr();
                        Console.WriteLine(Constant.strEntrAmount);
                        int    intN = int.Parse(Console.ReadLine());
                        string strS2;
                        strS2 = objStringBldr.NumToWrds(intN);                                             //create object for class
                        Console.WriteLine(strS2);
                        break;

                    case "4.15":                                                            //case use for 4.15 exercise that is used for create StructDate
                        objStructure = new StructDate();
                        objStructure.dateArray();                                           //  //create object for class
                        break;

                    case "4.16":                                                        //Case use for 4.16 exercise that is used for sorting date

                        Console.WriteLine(Constant.strEnumDate);
                        int size = Convert.ToInt32(Console.ReadLine());
                        objdt = new StructDate[size];                                   //create object of structDate array
                        for (int i = 0; i < size; i++)
                        {
                            Console.WriteLine(Constant.strEntrdate + (i + 1));
                            Console.WriteLine(objdt[i].dateArray());
                        }
                        objDateArray = new DateArray();
                        objDateArray.dateArray(objdt);                                       //Pass by value
                        objDateArray.dateArray(ref objdt);                                   //Pass by Reference break
                        break;

                    case "4.17":                                               //Case use for 4.17 exercise that is used for Write lines on file
                        objTextFile = new TextFile();                          //create object for class
                        objTextFile.TextFileM();
                        break;

                    case "4.18":                                         //Case use for 4.18 exercise that is used for read file content
                        objReadTextFile = new ReadTextFile();            //create object for class
                        objReadTextFile.ReadText();
                        break;

                    case "7.1":                                                   //Case use for 7.1 exercise that is used Driver class
                        objDriver = new Driver();
                        objDriver.Drive();                                        //create object for class
                        break;

                    case "7.2":
                        objCar = new Car();                                      //Case use for 7.2 exercise that is used Car class
                        objCar.Drive();
                        break;

                    case "7.3":                                                    //Case use for 7.3 exercise that is used Car2 class
                        objCar2 = new Car2();
                        objCar2.Drive();                                           //create object for class
                        break;

                    case "7.4":                                                 //Case use for 7.4 exercise that is used Car3 class
                        objCar3 = new Car3();
                        objCar3.Drive();                                        //create object for class
                        break;

                    case "7.5":                                              //Case use for 7.5 exercise that is used Car4 class
                        objCar4 = new Car4();
                        objCar4.Destruct();                                  //create object for class
                        break;

                    case "7.6":                                                //Case use for 7.6 exercise that is used  ArmoredVehicle class
                        objArmoredVehicle = new ArmoredVehicle();
                        objArmoredVehicle.Destruct();                          //create object for class
                        break;

                    case "7.7":                                                         //Case use for 7.7 exercise that is used CarArmoredVcle class
                        objCarArmoredVcle = new CarArmoredVcle();
                        ArrayList objarr = objCarArmoredVcle.CarArmored();              //create object for class
                        foreach (object obj in objarr)
                        {
                            Console.WriteLine(obj);
                        }
                        break;

                    case "7.8":                                                        //Case use for 7.8 exercise that is used CCarArmoredVcle1 class
                        objCarArmoredVcle1 = new CarArmoredVcle1();
                        ArrayList objarr1 = objCarArmoredVcle1.CarArmored();           //create object for class
                        foreach (object obj in objarr1)
                        {
                            try { Console.WriteLine(obj); }

                            catch (VehicleNtDestydException v)
                            {
                                Console.WriteLine(v.Message);
                            }
                        }
                        break;

                    case "7.9":                                                  //Case use for 7.9 exercise that is used Arraylist, create dynamically object
                        Console.WriteLine(Constant.strEntrCarobject);
                        int intLst1 = int.Parse(Console.ReadLine());
                        for (int i = 0; i < intLst1; i++)                       //Create object in looping
                        {
                            Console.WriteLine(Constant.strEntrCarModel);
                            string strModelnm = Console.ReadLine();
                            objCar5 = new Car5(strModelnm);
                            objArryLstD1.Add(objCar5);                          //Add object intito Arraylist
                        }

                        for (int i = 0; i < objArryLstD1.Count; i++)            //looping for traverse list
                        {
                            Console.WriteLine(objArryLstD1[i].ToString());
                        }
                        break;
                    //objListCar5.Add(objCar5 = new Car5("IV-Tec"));
                    //objListCar5.Add(objCar5 = new Car5("City Honda"));
                    //foreach (object obj in objListCar5)
                    //{
                    //    Console.WriteLine(obj.ToString());
                    //}

                    //  break;
                    case "7.10":                                                  //Case use for 7.10 exercise that is used Arraylist, create dynamically object and make readonly property

                        Console.WriteLine(Constant.strEntrCarobject);
                        int intLst = int.Parse(Console.ReadLine());
                        for (int i = 0; i < intLst; i++)                              //Create object in looping
                        {
                            Console.WriteLine(Constant.strEntrCarModel);
                            string            strModelnm           = Console.ReadLine();
                            CarArmoredVclList objCarArmoredVclList = new CarArmoredVclList(strModelnm);
                            objArryLstD.Add(objCarArmoredVclList);                                     //Add object intito Arraylist
                        }

                        for (int i = 0; i < objArryLstD.Count; i++)                       //looping for traverse list
                        {
                            Console.WriteLine(objArryLstD[i].ToString());
                        }
                        break;

                    case "7.11":                                                   //Case use for 7.11 exercise that is used for fuel calculation

                        Console.WriteLine(Constant.strIniValCar);                  //Enter initial value for car
                        int  intK    = Convert.ToInt16(Console.ReadLine());
                        Car6 objCar6 = new Car6(intK);
                        Console.WriteLine(Constant.strIniValArmored);                //Enter initial value for Armored Vehicle
                        int           intC             = Convert.ToInt16(Console.ReadLine());
                        CarFuelCmsptn objCarFuelCmsptn = new CarFuelCmsptn(intC);
                        objCarFuelCmsptn.FuelEfficiency = 5;
                        objCar6.FuelEfficiency          = 14;
                        Console.WriteLine(Constant.strEntrKiloCar);                       //Enter number of Kilometer Driven by Car by user
                        try { objCar6.Drive(Convert.ToDouble(Console.ReadLine())); }
                        catch (NoFuelLeftException v) { Console.WriteLine(v); }
                        Console.WriteLine(Constant.strEntrKiloArmored);                      // Enter number of Kilometer Driven by ArmoredVehicle by user
                        try { objCar6.Drive(Convert.ToDouble(Console.ReadLine())); }
                        catch (NoFuelLeftException StrFuel) { Console.WriteLine(StrFuel); }
                        break;

                    case "7.12":                                                            //Case use for 7.11 exercise that is used for create hash table, add object in it.
                        HashTblCar objHashTblCar = new HashTblCar();
                        objHashTblCar.HashTblSort();                                        //create object for class
                        break;

                    default:
                        Console.WriteLine(Constant.strEntrNch);                 //enter no choice
                        break;
                    }

                    Console.WriteLine(Constant.strEntrCyn);      // Gather information that you want continue or not
                    chr = Char.Parse(Console.ReadLine());        //  Read value of character
                } while (chr == 'Y' || chr == 'y');


                if (chr == 'N' || chr == 'n')
                {
                    Console.WriteLine(Constant.strMsg);   // Display message if you press N
                    Console.ReadLine();
                }
            }

            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());                     // throw exception
                Console.Read();
            }
            finally
            {
                strS                  = null; objVowel = null; objSvowel = null; objCaseCheck = null;                          //REALLOCATE THE MEMORY
                objdt                 = null; objReverse = null; objPowerNum = null; objWindowName = null;
                objReverse1           = null;  objSearchArray = null; objReviseArray = null;  objCopyArray = null;
                objNotePadApplication = null; objDateArray = null;  objTextFile = null;
                objReadTextFile       = null; objDriver = null; objCar = null; objCar2 = null; objCar3 = null; objCar4 = null; objCar5 = null;
                objArmoredVehicle     = null; objCarArmoredVcle = null; objCarArmoredVcle1 = null;
            }
        }
Esempio n. 7
0
    //In CurrentPosiiton 0 represent center, -1 left and 1 right.
    public void LeftButton()
    {
        Debug.Log("Left button");
        //If at center move to left
        if (Car1.GetComponent <PlayerController> ().teleporting == false && Car1CurrentPosition - 1 != Car2CurrentPosition)
        {
            if (Car1CurrentPosition == 2)
            {
                //animate movemenet to -2.1 i.e left
                Car1.transform.DOMoveX(-2.45f, 0.5f);
                //set current position to -1 i.e. left.
                Car1CurrentPosition = 1;
                //If at right move to center
            }
            else if (Car1CurrentPosition == 3)
            {
                //animate movemenet to 0 i.e center
                Car1.transform.DOMoveX(-1.75f, 0.5f);
                //set current position to 0 i.e. center.
                Car1CurrentPosition = 2;
            }
            else if (Car1CurrentPosition == 4)
            {
                //animate movemenet to 0 i.e center
                Car1.transform.DOMoveX(-1.05f, 0.5f);
                //set current position to 0 i.e. center.
                Car1CurrentPosition = 3;
            }
            else if (Car1CurrentPosition == 6)
            {
                //animate movemenet to 0 i.e center
                Car1.transform.DOMoveX(0.35f, 0.5f);
                //set current position to 0 i.e. center.
                Car1CurrentPosition = 5;
            }
            else if (Car1CurrentPosition == 7)
            {
                //animate movemenet to 0 i.e center
                Car1.transform.DOMoveX(1.05f, 0.5f);
                //set current position to 0 i.e. center.
                Car1CurrentPosition = 6;
            }
            else if (Car1CurrentPosition == 8)
            {
                //animate movemenet to 0 i.e center
                Car1.transform.DOMoveX(1.75f, 0.5f);
                //set current position to 0 i.e. center.
                Car1CurrentPosition = 7;
            }
        }

        //Second car
        //If at center move to left
        if (Car2.GetComponent <PlayerController> ().teleporting == false && Car2CurrentPosition - 1 != Car1CurrentPosition)
        {
            if (Car2CurrentPosition == 2)
            {
                //animate movemenet to -2.1 i.e left
                Car2.transform.DOMoveX(-2.45f, 0.5f);
                //set current position to -1 i.e. left.
                Car2CurrentPosition = 1;
                //If at right move to center
            }
            else if (Car2CurrentPosition == 3)
            {
                //animate movemenet to 0 i.e center
                Car2.transform.DOMoveX(-1.75f, 0.5f);
                //set current position to 0 i.e. center.
                Car2CurrentPosition = 2;
            }
            else if (Car2CurrentPosition == 4)
            {
                //animate movemenet to 0 i.e center
                Car2.transform.DOMoveX(-1.05f, 0.5f);
                //set current position to 0 i.e. center.
                Car2CurrentPosition = 3;
            }
            else if (Car2CurrentPosition == 6)
            {
                //animate movemenet to 0 i.e center
                Car2.transform.DOMoveX(0.35f, 0.5f);
                //set current position to 0 i.e. center.
                Car2CurrentPosition = 5;
            }
            else if (Car2CurrentPosition == 7)
            {
                //animate movemenet to 0 i.e center
                Car2.transform.DOMoveX(1.05f, 0.5f);
                //set current position to 0 i.e. center.
                Car2CurrentPosition = 6;
            }
            else if (Car2CurrentPosition == 8)
            {
                //animate movemenet to 0 i.e center
                Car2.transform.DOMoveX(1.75f, 0.5f);
                //set current position to 0 i.e. center.
                Car2CurrentPosition = 7;
            }
        }
    }
Esempio n. 8
0
 public void Reset()
 {
     this.car = new Car2();
 }
Esempio n. 9
0
        static void Main(string[] args)
        {
            Character warrior        = new Character("Human"); //У каждого класса свое предназначение, Класс кошка не может создавать ракеты...
            string    charactierInfo = warrior.GetRace();

            warrior.Hit(35);
            Console.WriteLine($"Ваша раса: {charactierInfo}, Здоровье персонажа: {warrior.GetHealth()}, Броня: {warrior.armor}");

            Character archer    = new Character("Wood Elf", 60);
            int       armorInfo = archer.armor;

            Console.WriteLine($"Ваша раса: {archer.GetRace()}, Здоровье персонажа: {archer.GetHealth()}, Броня: {armorInfo}");


            Calculator calc   = new Calculator();
            double     result = calc.SqrtLength(ab: 8, bc: 12, alpha: 45); //Именованные аргументы Ctrl + .(точка). Выбираем add argument ->

            result = Math.Round(value: result, digits: 2);
            Console.WriteLine("Площадь равна: " + result);

            double avg = calc.Average(numbers: new int[] { 1, 2, 3, 4 }); //инициализация массива Average (именованные аргументы)

            Console.WriteLine("Среднее значение: " + avg);
            //С помощью params можно передавать значения массива через запятую
            double avg2 = calc.Average2(1, 2, 3, 4);   //инициализация массива Average.

            Console.WriteLine("Инициализация среднего значения: " + avg2);


            //  Calculator.TryParsed(); //С использованием статического метода, без использования экземпляра


            Calculator divider = new Calculator();

            if (divider.TryDevide(5, 2, out double result2))
            {
                Console.WriteLine($"Результат деления равен: {result2}");
            }
            else
            {
                Console.WriteLine("Fail не получилось поделить");
            }

            //Создадим экземпляр структуры
            PointVal a; //это экземпляр структуры, тоже самое, что и PointVal a = new PointWal();

            a.x = 5;
            a.y = 8;

            //Создадим еще одну структуру b
            PointVal b = a;

            b.x = 4;
            b.y = 6;

            a.LogValues();
            b.LogValues();


            Console.WriteLine("Данные после struct (структуры)");
            //Создадим Экземпляр для класса

            PointRef c = new PointRef();

            c.x = 5;
            c.y = 8;

            //Создадим еще одну структуру b
            PointRef d = c;

            d.x = 4;
            d.y = 6;

            c.LogValues();
            d.LogValues();

            List <int> list = new List <int>();

            AddNumbers(list);
            foreach (int value in list)
            {
                Console.WriteLine("Вывод List " + value);
            }

            Swap(8, 6);
            //      SwapAuto(); //Значения вводит пользователь
            //     SwapFromFull(); //С защитой от дурака

            //Bankomat наследование inheritence
            ModelA terminalA = new ModelA(252);

            terminalA.Connect();
            ModelB terminalB = new ModelB(758);

            terminalB.Connect();

            //Car наследование
            Car1 bmw = new Car1("Bmw", "Black", 2.6, 289.7);

            bmw.CarInfo();
            Car2 dodge = new Car2("Dodge", "Yellow", 6.0, 382.3);

            dodge.CarInfo();

            Console.WriteLine();

            //Полиформизм (1 метод для каждого класса осуществляет свою операцию папка Polymorphism)
            Rectangle rectangle = new Rectangle(width: 17.5, height: 22.3);

            rectangle.Area();
            rectangle.Perimeter();
            rectangle.Draw();

            Console.WriteLine();

            Triangle triangle = new Triangle(a: 5.2, b: 6.3, c: 7.5);

            triangle.Area();
            triangle.Perimeter();
            triangle.Draw();
            Console.WriteLine();
            Console.WriteLine();

            /*Так как мы переопределили все эти методы, вызывающий код может унифицированно работать со всеми этими типами/классами
             * используя базовый класс/абстрактный, записать экземпляр абстрактного класса можно в виде массива и передать туда наши
             * классы - наследники в этот массив*/
            Shapes[] shapes = new Shapes[2];
            shapes[0] = new Triangle(6.3, 8.2, 9.7);
            shapes[1] = new Rectangle(22.4, 18.7);
            //Пройдемся foreach, используя базовый(абстрактный класс)
            foreach (var shape in shapes)
            {
                shape.Area();
                shape.Draw();
                shape.Perimeter();
            }
            Console.WriteLine();
            Console.WriteLine();
            Do(triangle);

            MyStack <int> ms = new MyStack <int>(); //у нас 2 перегрузки массива (по умолчанию 4 элемента), либо выбрать размер какой необходим

            ms.Push(1);
            ms.Push(2);
            ms.Push(3);
            Console.WriteLine(ms.Peek()); //Выведем последний добавленный элемент
            ms.Pop();                     //удалим последний элемент
            Console.WriteLine(ms.Peek());
            ms.Push(3);
            ms.Push(4);
            ms.Push(5); //чтобы произошло расширение стека, чтобы убедиться, что ничего не падает
            Console.WriteLine(ms.Peek());

            //Вадим Шванов
            ShvanovCar shamovCar = new ShvanovCar();

            shamovCar.CarInfo();
            ShvanovCar shCar = new ShvanovCar("F1", 260);

            shCar.CarInfo();

            RandomNumbers();
        }
Esempio n. 10
0
    //This funciton is called when the activation button on the panel is pressed (changes the player status to active, non active or cpu)
    public void PanelManager()
    {
        if (m.playerID != 1) //Player 1 will have a slightly different behaviour
        {
            if (!CoinController.is_grabbed)
            {
                //A new player can be activated only if it's the one right next to the highest currently activated player. e.g. if only player 1 is active you can activate player 2 but not player 3
                if (l.num_players == m.playerID || l.num_players == m.playerID - 1)
                {
                    switch_case++;
                    switch (switch_case)
                    {
                    case 1:
                        //Makes it an active player
                        if (l.num_players == m.playerID - 1 && !m.is_this_active)
                        {
                            Token.sprite = Player_Token;
                            HandObject.SetActive(true);

                            playerCoin.SetActive(true);
                            cpuText.text = "";
                            t.text       = nameplayer;

                            Hand.sprite = hand_closed;
                            m.Hand.SetAsLastSibling();
                            if (m.playerID == 1)
                            {
                                m.GetComponent <Collider2D>().enabled = false;
                            }


                            if (l.num_players < m.playerID)
                            {
                                l.num_players++;
                            }

                            if (m.playerID == 1)
                            {
                                l.is_p1_active = true;
                            }
                            else if (m.playerID == 2)
                            {
                                l.is_p2_active = true;
                            }
                            else if (m.playerID == 3)
                            {
                                l.is_p3_active = true;
                            }
                            else if (m.playerID == 4)
                            {
                                l.is_p4_active = true;
                            }

                            m.is_this_active = true;
                            CPU_Controls     = 1;
                            is_CPU           = false;
                            carImage.sprite  = default_Empty;
                        }

                        break;

                    case 2:
                        //Makes it a CPU
                        if (l.num_players == m.playerID - 1 && !m.is_this_active)
                        {
                            playerCoin.SetActive(true);
                            m.is_this_active = true;
                            l.num_players++;

                            if (m.playerID == 1)
                            {
                                l.is_p1_active = true;
                            }
                            else if (m.playerID == 2)
                            {
                                l.is_p2_active = true;
                            }
                            else if (m.playerID == 3)
                            {
                                l.is_p3_active = true;
                            }
                            else if (m.playerID == 4)
                            {
                                l.is_p4_active = true;
                            }
                        }

                        if (m.is_this_active)
                        {
                            cpuText.text    = "";
                            t.text          = "CPU";
                            is_CPU          = true;
                            CPU_Controls    = 2;
                            carImage.sprite = default_Empty;
                            Controls        = 4;

                            HandObject.SetActive(false);
                            Token.sprite = CPU_Token;

                            l.num_CPU_Players++;
                            resetControlsCPU();
                            ControlManager();
                        }

                        break;

                    default:
                        //Deactivates it and resets all its variables
                        if (l.num_players == m.playerID && m.is_this_active)

                        {
                            print("deleting player");

                            playerCoin.SetActive(false);


                            if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.Joy1)
                            {
                                m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned;
                                l.is_joy1_taken     = false;
                            }

                            else if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.Joy2)
                            {
                                m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned;
                                l.is_joy2_taken     = false;
                            }

                            else if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.ArrowKeys)
                            {
                                m.ThisPlayerControl  = MoveSelector.ControlTypesHere.NotAssigned;
                                l.is_arrowKeys_taken = false;
                            }

                            else if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.WSDA)
                            {
                                m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned;
                                l.is_wsda_taken     = false;
                            }

                            if (m.playerID == 1)
                            {
                                l.is_p1_active = false;
                            }
                            else if (m.playerID == 2)
                            {
                                l.is_p2_active = false;
                            }
                            else if (m.playerID == 3)
                            {
                                l.is_p3_active = false;
                            }
                            else if (m.playerID == 4)
                            {
                                l.is_p4_active = false;
                            }

                            l.num_players--;
                            l.num_CPU_Players--;
                            m.is_this_active = false;
                            is_CPU           = false;
                            CoinController.is_car_selected = false;
                        }

                        switch_case = 0;
                        playerCoin.transform.position = m.playerPosition;
                        carImage.sprite = default_notActive;

                        if (Car1.ThisCarSelected == true && CoinController.CoinID == Car1.ID)
                        {
                            Car1.CheckPlayerActivation();
                        }
                        else if (Car2.ThisCarSelected == true && CoinController.CoinID == Car2.ID)
                        {
                            Car2.CheckPlayerActivation();
                        }
                        else if (Car3.ThisCarSelected == true && CoinController.CoinID == Car3.ID)
                        {
                            Car3.CheckPlayerActivation();
                        }
                        else if (Car4.ThisCarSelected == true && CoinController.CoinID == Car4.ID)
                        {
                            Car4.CheckPlayerActivation();
                        }

                        CPU_Controls = 0;
                        t.text       = "N/A";
                        cpuText.text = "";

                        if (m.playerID == 1)
                        {
                            buttonController.SetOverlay(false);
                            controlController.SetOverlay(false);
                        }

                        Controls = 4;
                        ControlManager();

                        break;
                    }
                }
                //If this is a middle player (e.g. player 2 when 3 players are active) only switches between CPU and active status. Player cannot be disabled
                else if (m.is_this_active)
                {
                    CPU_Controls++;

                    switch (CPU_Controls)
                    {
                    case 1:

                        is_CPU = false;
                        resetControlsCPU();
                        Controls = 4;
                        ControlManager();
                        Hand.sprite  = hand_closed;
                        cpuText.text = "";
                        t.text       = nameplayer;
                        switch_case  = 1;
                        Token.sprite = Player_Token;
                        HandObject.SetActive(true);
                        CPU_Controls = 1;
                        l.num_CPU_Players--;

                        break;

                    case 2:
                        cpuText.text = "";
                        t.text       = "CPU";
                        is_CPU       = true;
                        CPU_Controls = 0;
                        switch_case  = 2;
                        resetControlsCPU();
                        Controls = 4;
                        ControlManager();

                        l.num_CPU_Players++;
                        HandObject.SetActive(false);
                        Token.sprite = CPU_Token;

                        m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned;
                        break;

                    default:
                        switch_case  = 0;
                        CPU_Controls = 0;
                        Controls     = 4;
                        is_CPU       = false;
                        break;
                    }
                }
            }
        }

        //Player 1 can also not be deactivated as it controls other players' statuses and activation
        else
        {
            CPU_Controls++;

            switch (CPU_Controls)
            {
            case 1:
                cpuText.text = "";
                t.text       = nameplayer;
                is_CPU       = false;
                switch_case  = 1;
                Token.sprite = Player_Token;
                break;

            case 2:
                cpuText.text = "";
                t.text       = "CPU";
                is_CPU       = true;
                CPU_Controls = 0;
                Token.sprite = CPU_Token;
                switch_case  = 2;
                break;

            default:
                switch_case  = 0;
                CPU_Controls = 0;
                is_CPU       = false;
                break;
            }
        }
    }