Exemple #1
0
        static void Main(string[] args)
        {
            PetStruct dog = new PetStruct();

            dog.Type   = PetType.Dog;
            dog.Legs   = 4;
            dog.HasFur = true;
            Console.WriteLine("A " + dog.Type + " has " + dog.Legs + " legs");

            PetClass duck = new PetClass();

            duck.Type   = PetType.Duck;
            duck.Legs   = 2;
            duck.HasFur = false;
            Console.WriteLine("A " + duck.Type + " has " + duck.Legs + " legs");

            //MultiplyLegs(dog, duck);
            //Console.WriteLine("A " + dog.Type + " has " + dog.Legs);
            //Console.WriteLine("A " + duck.Type + " has " + duck.Legs);

            PetStruct copiedDog  = dog;
            PetClass  copiedDuck = duck;

            copiedDog.Legs  = copiedDog.Legs * 2;
            copiedDuck.Legs = copiedDuck.Legs * 2;

            Console.WriteLine("A " + dog.Type + " has " + dog.Legs);
            Console.WriteLine("A " + duck.Type + " has " + duck.Legs);

            Console.WriteLine("A " + copiedDog.Type + " has " + copiedDog.Legs);
            Console.WriteLine("A " + copiedDuck.Type + " has " + copiedDuck.Legs);

            Console.ReadLine();
        }
Exemple #2
0
    public PetClass GetPet(int id)
    {
        ConnectToDB("SimpleGame.db");

        PetClass pet = new PetClass();

        pet.id = id;

        dataReader =
            ExecuteQuery("SELECT Name, Attack, Defense, Speed FROM Pet WHERE ID = " + id + ";");
        while (dataReader.HasRows)
        {
            if (dataReader.Read())
            {
                pet.name  = dataReader.GetString(0);
                pet.atk   = dataReader.GetInt32(1);
                pet.def   = dataReader.GetInt32(2);
                pet.speed = dataReader.GetInt32(3);
            }
        }

        CloseConnection();

        return(pet);
    }
Exemple #3
0
        public void Test_Name()
        {
            PetClass dog = new PetClass();

            dog.Name = "Bob";
            Assert.Equal("Bob", dog.Name);
        }
        static void Main(string[] args)
        {
            // how we initialize Struct
            PetStruct dog;

            dog.legs   = 4;
            dog.name   = "Cuko";
            dog.type   = PetType.Dog;
            dog.hasFur = true;

            // to pass a struct into method parameeter we ne do to initialize it like an object
            // PetStruct dog = new PetStruct();

            Console.WriteLine(dog.legs + " " + dog.type);

            // for class we need to create an object
            PetClass duck = new PetClass();

            duck.legs   = 2;
            duck.name   = "Daffy duck";
            duck.type   = PetType.Duck;
            duck.hasFur = false;

            Console.ReadLine();
        }
Exemple #5
0
        static void MultiplyLegs(PetStruct petStruct, PetClass petClass)
        {
            petStruct.Legs = petStruct.Legs * 2;
            petClass.Legs  = petClass.Legs * 2;

            Console.WriteLine("Internal method) A " + petStruct.Type + " has " + petStruct.Legs);
            Console.WriteLine("Internal method) A " + petClass.Type + " has " + petClass.Legs);
        }
Exemple #6
0
        //Method to change attribute in the given intance

        static void MultipliedLeg(PetStruct dogLeg, PetClass duckLeg)
        {
            dogLeg.legs  = dogLeg.legs * 2;
            duckLeg.legs = duckLeg.legs * 2;

            Console.WriteLine("Internal Method- {0}", dogLeg.legs);
            Console.WriteLine("Internal Method- {0}", duckLeg.legs);
        }
Exemple #7
0
        public void Test_Hunger_Levels_Increase()
        {
            //ARRANGE
            PetClass pet = new PetClass();

            //ACT
            pet.Feed();
            //ASSERT
            Assert.Equal(5, pet.Hunger);
        }
Exemple #8
0
        public void Test_health()
        {
            //ARRANGE
            PetClass dog = new PetClass();

            //ACT
            dog.PetMaintenance();
            //ASSERT
            Assert.Equal(5, dog.Health);
        }
Exemple #9
0
        public void Test_Entertain_LEVEL()
        {
            //ARRANGE
            PetClass dog = new PetClass();

            //ACT
            dog.Play();
            // ASSERT
            Assert.Equal(5, dog.Entertain);
        }
Exemple #10
0
        public void Test_constructor() //After create constructor testing if Name holds  value
        {
            //ARRANGE
            PetClass pet = new PetClass("Bob", 12, "Lion");
            //ACT
            string testname = pet.Name;

            //ASSERT
            Assert.Equal("Bob", testname);
        }
Exemple #11
0
        public void Test_hunger_level_AFTER_VISIT_TO_DR() //Visit to doctor should decreases hunger by 10
        {
            //ARRANGE
            PetClass mypet = new PetClass();

            //ACT
            mypet.PetMaintenance();
            mypet.Feed();
            //ASSERT
            Assert.Equal(10, mypet.Feed());
        }
Exemple #12
0
    public void SavePet(PetClass pet)
    {
        ConnectToDB("SimpleGame.db");

        dbCommand             = dbConnection.CreateCommand();
        dbCommand.CommandText =
            "UPDATE Pet SET Name = '" + pet.name + "', Attack = " + pet.atk + ", Defense = " + pet.def + ", Speed = " + pet.speed + " WHERE ID = " + pet.id;
        dbCommand.ExecuteNonQuery();

        CloseConnection();
    }
Exemple #13
0
    public void CreatePet(PetClass pet)
    {
        ConnectToDB("SimpleGame.db");

        dbCommand             = dbConnection.CreateCommand();
        dbCommand.CommandText =
            "INSERT INTO Pet (ID, Name, Attack, Defense, Speed) VALUES (" + pet.id + ", '" + pet.name + "', " + pet.atk + ", " + pet.def + ", " + pet.speed + ")";
        dbCommand.ExecuteNonQuery();

        CloseConnection();
    }
Exemple #14
0
        private void LoadBtn_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                String filename = openFileDialog1.FileName;

                using (Stream input = File.OpenRead(filename))
                {
                    PetA = (PetClass)binaryFormatter.Deserialize(input);
                }
            }
        }
        public static void SwitchChoice()

        {
            var petStats = new PetClass();

            Console.WriteLine(" Name your Pet");
            petStats.Name = Console.ReadLine();
            while (petStats.Sleep >= 1 ^ petStats.Food >= 1 ^ petStats.Play >= 1)
            {
                Console.WriteLine(" 1 for Stats, 2 for Feed,  for Sleep, 4 to Play");
                var choice = Console.ReadLine();
                var info   = $" Name: {petStats.Name}, Hunger: {petStats.Food}, Tiredness: {petStats.Sleep}, Boredom: {petStats.Play}";

                switch (choice)
                {
                case "1":
                    Console.WriteLine(info);

                    break;

                case "2":
                    petStats.Food++;
                    petStats.Sleep--;
                    Console.WriteLine(petStats.Food);
                    Console.WriteLine(info);

                    break;

                case "3":
                    petStats.Sleep++;
                    Console.WriteLine(petStats.Sleep);
                    Console.WriteLine(info);

                    break;

                case "4":
                    petStats.Play++;
                    Console.WriteLine(petStats.Play);
                    Console.WriteLine(info);

                    break;

                default:
                    Console.WriteLine(" Something went wrong!");
                    break;
                }
            }
            GameOverClass.GameOver();
        }
Exemple #16
0
    // Start is called before the first frame update
    void Start()
    {
        skillNameText.GetComponent <Renderer>().enabled = false;

        object_hero    = GameObject.Find("Hero");
        object_pet     = GameObject.Find("Pet");
        object_servant = GameObject.Find("Servant");
        object_enemy1  = GameObject.Find("Enemy1");
        object_enemy2  = GameObject.Find("Enemy2");
        object_enemy3  = GameObject.Find("Enemy3");
        object_enemy4  = GameObject.Find("Enemy4");
        object_enemy5  = GameObject.Find("Enemy5");
        object_enemy6  = GameObject.Find("Enemy6");

        hero    = object_hero.transform.GetComponent <HeroManager>();
        pet     = object_pet.transform.GetComponent <HeroManager>();
        servant = object_servant.transform.GetComponent <HeroManager>();
        enemy1  = object_enemy1.transform.GetComponent <HeroManager>();
        enemy2  = object_enemy2.transform.GetComponent <HeroManager>();
        enemy3  = object_enemy3.transform.GetComponent <HeroManager>();
        enemy4  = object_enemy4.transform.GetComponent <HeroManager>();
        enemy5  = object_enemy5.transform.GetComponent <HeroManager>();
        enemy6  = object_enemy6.transform.GetComponent <HeroManager>();

        object_heroTeam  = new List <GameObject>();
        object_enemyTeam = new List <GameObject>();
        heroTeam         = new List <HeroManager>();
        enemyTeam        = new List <HeroManager>();

        object_heroTeam.Add(object_pet);
        object_heroTeam.Add(object_hero);
        object_heroTeam.Add(object_servant);

        object_enemyTeam.Add(object_enemy1);
        object_enemyTeam.Add(object_enemy2);
        object_enemyTeam.Add(object_enemy3);
        object_enemyTeam.Add(object_enemy4);
        object_enemyTeam.Add(object_enemy5);
        object_enemyTeam.Add(object_enemy6);

        heroTeam.Add(pet);
        heroTeam.Add(hero);
        heroTeam.Add(servant);

        enemyTeam.Add(enemy1);
        enemyTeam.Add(enemy2);
        enemyTeam.Add(enemy3);
        enemyTeam.Add(enemy4);
        enemyTeam.Add(enemy5);
        enemyTeam.Add(enemy6);

        DBManager dbm = new DBManager();

        HeroClass hc = new HeroClass();

        hc      = dbm.GetHero(gameID);
        theHero = hc;

        hero.atk       = hc.atk;
        hero.def       = hc.def;
        hero.speed     = hc.speed;
        hero.health    = hc.life;
        hero.shownName = hc.name;

        PetClass pc = new PetClass();

        pc = dbm.GetPet(gameID);

        pet.atk       = pc.atk;
        pet.def       = pc.def;
        pet.speed     = pc.speed;
        pet.shownName = pc.name;

        ServantClass sc = new ServantClass();

        sc = dbm.GetServant(gameID);

        servant.atk       = sc.atk;
        servant.def       = sc.def;
        servant.speed     = sc.speed;
        servant.shownName = sc.name;

        List <EnemyClass> enemyList = dbm.GetAllEnemy();

        for (int i = 0; i < enemyTeam.Count; i++)
        {
            EnemyClass ec = enemyList[Random.Range(1, enemyList.Count)];
            enemyTeam[i].atk       = ec.atk;
            enemyTeam[i].def       = ec.def;
            enemyTeam[i].speed     = ec.speed;
            enemyTeam[i].shownName = ec.name;
            enemyTeam[i].health    = ec.life;
        }

        pet.isLive     = false;
        servant.isLive = false;
        object_pet.SetActive(false);
        object_servant.SetActive(false);


        foreach (HeroManager heros in heroTeam)
        {
            float time = 200.0f / heros.speed;
            Invoke("AttackTimer_" + heros.name, time);
        }
        //Invoke("AttackTimer_Hero", 0.9f);

        foreach (HeroManager enemys in enemyTeam)
        {
            float time = 200.0f / enemys.speed;
            Invoke("AttackTimer_" + enemys.name, time);
        }

        skillList = dbm.GetAllSkill();
    }
Exemple #17
0
        static void Main(string[] args)
        {
            PetStruct dog = new PetStruct();

            dog.type   = PetType.dog;
            dog.hasFur = true;
            dog.name   = "Anthony";
            dog.legs   = 4;

            PetClass duck = new PetClass();

            duck.type   = PetType.duck;
            duck.hasFur = true;
            duck.name   = "Donald";
            duck.legs   = 2;

            Console.WriteLine("the dog name {0} has {1} and is {2} type", dog.name, dog.legs, dog.type);
            Console.WriteLine("the duck name {0} has {1} and is {2} type", duck.name, duck.legs, duck.type);
            MultipliedLeg(dog, duck);
            Console.WriteLine("the dog name {0} has {1} and is {2} type", dog.name, dog.legs, dog.type);
            Console.WriteLine("the duck name {0} has {1} and is {2} type", duck.name, duck.legs, duck.type);

            //initialize without pre-populated array.
            int[]    intArray    = new int[5];
            string[] stringArray = new string[3];

            //initalize prepopulated array.
            int[]    populatedIntArray    = new int[] { 1, 2, 3, 4, 5 };
            string[] populatedStringArray = new string[] { "Binh", "Hai, 'Anthony" };

            //asign value can be done for both unpopulated and prepopulated array
            intArray[0] = 2;
            Console.WriteLine(intArray[0]);

            populatedStringArray[1] = "Bento";
            Console.WriteLine(populatedStringArray[1]);

            //********MULTIDIMENTIONAL ARRAY***********
            int[,] multiInt          = new int[3, 5];
            int[,] multiPopulatedInt = { { 1, 2, 3 }, { 3, 4, 5 }, { 6, 7, 8 } };

            int val1 = multiPopulatedInt[0, 0]; //val is 1
            int val2 = multiPopulatedInt[1, 2]; //val is 5
            int val3 = multiPopulatedInt[2, 1]; //val is 7

            Console.WriteLine(val1);
            Console.WriteLine(val2);
            Console.WriteLine(val3);


            //*********LIST************
            //initilize List, not length asigned needed
            List <string> listOfStrings = new List <string>();

            //add or remove item to the list
            listOfStrings.Add("First Item");
            listOfStrings.Add("Second Item");
            listOfStrings.Add("Third Item");
            listOfStrings.Insert(1, "inserted Item"); //insert by index will push the value down instead of overide it

            listOfStrings.Remove("First Item");       //remove particular Item
            listOfStrings.RemoveAt(0);                //remove index

            Console.WriteLine(listOfStrings.Count);
            Console.WriteLine(listOfStrings[1]);

            //***********DICTIONARY****************
            Dictionary <string, string> selectedActor = new Dictionary <string, string>();

            selectedActor.Add("name", "Jame Bond");
            selectedActor.Add("nationality", "England");
            selectedActor.Add("job", "MI6-SPY");
            selectedActor.Add("status", "Single");

            Console.WriteLine(selectedActor["name"]);
            Console.WriteLine(selectedActor["nationality"]);
            Console.WriteLine(selectedActor["job"]);
            Console.WriteLine(selectedActor["status"]);


            //************LINQ********************
            List <PetClass> petList = new List <PetClass>();

            petList.Add(new PetClass {
                name = "Anthony", type = PetType.dog, legs = 4, hasFur = true
            });
            petList.Add(new PetClass {
                name = "Dante", type = PetType.duck, legs = 2, hasFur = false
            });

            //List<PetClass> selectedPet = (from p in petList
            //                            where p.legs == 4
            //                          select p).ToList();
            List <PetClass> selectedPet = petList.Where(p => p.legs == 4).ToList();

            //PetClass selectedPet1 = (from p in petList
            //                          where p.hasFur == false
            //                        select p).FirstOrDefault();
            PetClass selectedPet1 = petList.Where(p => p.hasFur == false).FirstOrDefault();


            Console.WriteLine("result of the selectedPet is " + selectedPet[0].type + " and the name is " + selectedPet[0].name);
            Console.WriteLine("result of the selectedPet is " + selectedPet1.type + " and the name is " + selectedPet1.name);
        }