Example #1
0
 public void Add(Panda panda)
 {
     using (var ctx = new PandaContext(_dbHelper)) {
         ctx.Pandas.Add(panda);
         ctx.SaveChanges();
     }
 }
Example #2
0
    public static void Main()
    {
        Panda p  = new Panda("Peter"); // Create a Panda instance and call the constructor
        Panda p2 = new Panda("Piper", 2);

        Console.WriteLine("See source code for Constructor examples");
    }
Example #3
0
        public void ShouldReturnHealthInAnimalLevel()
        {
            Panda panda  = new Panda();
            var   result = panda.Health();

            Assert.Equal(100, result);
        }
Example #4
0
        public void TwoEqualsPandasTest()
        {
            var panda = new Panda("Ivo", "*****@*****.**", GenderType.Male);
            var otherPanda = new Panda("Ivo", "*****@*****.**", GenderType.Male);

            Assert.AreEqual(panda, otherPanda);
        }
Example #5
0
        public void ShouldReturnEatInHerbivorelevel()
        {
            Panda panda  = new Panda();
            var   result = panda.Eat();

            Assert.Equal("I eat vegetable", result);
        }
Example #6
0
    //method: Start
    //purpose: constructor
    void Start()
    {
        spriteRenderer       = GetComponent <SpriteRenderer>();
        boxCollider          = GetComponent <BoxCollider2D>();
        anim                 = gameObject.GetComponent <Animator>();
        rb2d                 = gameObject.GetComponent <Rigidbody2D>();
        firingDirection      = new Vector2(-1, 0);
        health               = maxHealth;
        fireCooldown         = maxFireCooldown;
        facingRight          = false;
        normalColor          = new Color(1f, 1f, 1f, 1f);
        hurtColor            = new Color(0.5f, 1f, 1f, 1f);//i tried making this public and setting it in the inspector panel, but it didn't work
        rightAimingDirection = new Vector3(0, 0, 0);
        leftAimingDirection  = new Vector3(0, 0, Vector2.Angle(Vector2.left, Vector2.right));
        hurtFlashTime        = 0;
        pursuitTime          = 0;
        state                = 0;
        moveOrIdleTime       = 0.0f;

        score = GameObject.Find("Panda").GetComponent <Score>();

        gun = (GameObject)Instantiate(Resources.Load("Gun"), new Vector2(1, 1), new Quaternion());
        gun.transform.parent = this.transform;

        panda = GameObject.Find("Panda").GetComponent <Panda>();
    }
        static void Main(string[] args)
        {
            PandaSocialNetwork pandaSocialNetwork = new PandaSocialNetwork();
            Panda panda1 = new Panda("A", "*****@*****.**", GenderType.Male);
            Panda panda2 = new Panda("B", "*****@*****.**", GenderType.Female);
            Panda panda3 = new Panda("C", "*****@*****.**", GenderType.Male);
            Panda panda4 = new Panda("D", "*****@*****.**", GenderType.Female);
            Panda panda5 = new Panda("E", "*****@*****.**", GenderType.Male);
            Panda panda6 = new Panda("F", "*****@*****.**", GenderType.Female);
            pandaSocialNetwork.AddPanda(panda1);
            pandaSocialNetwork.AddPanda(panda2);
            pandaSocialNetwork.AddPanda(panda3);
            pandaSocialNetwork.AddPanda(panda4);
            pandaSocialNetwork.AddPanda(panda5);
            pandaSocialNetwork.AddPanda(panda6);
            pandaSocialNetwork.MakeFriends(panda1, panda2);
            pandaSocialNetwork.MakeFriends(panda1, panda3);
            pandaSocialNetwork.MakeFriends(panda2, panda4);
            pandaSocialNetwork.MakeFriends(panda2, panda6);
            pandaSocialNetwork.MakeFriends(panda3, panda5);
            pandaSocialNetwork.MakeFriends(panda3, panda4);
            pandaSocialNetwork.MakeFriends(panda4, panda6);
            pandaSocialNetwork.MakeFriends(panda5, panda6);
            Console.WriteLine(pandaSocialNetwork.Connectionlevel(panda1, panda6));
            Console.WriteLine(pandaSocialNetwork.HowManyGenderInNetwork(2, panda1, GenderType.Male));


        }
Example #8
0
        public void MakeFriends(Panda panda1, Panda panda2)
        {
            if (ListOfPandasInTheNetwork.ContainsKey(panda1) && ListOfPandasInTheNetwork.ContainsKey(panda2) == false)
            {
                AddPanda(panda2);
            }
            else if (ListOfPandasInTheNetwork.ContainsKey(panda1) == false && ListOfPandasInTheNetwork.ContainsKey(panda2))
            {
                AddPanda(panda1);
            }
            else if (ListOfPandasInTheNetwork.ContainsKey(panda1) == false && ListOfPandasInTheNetwork.ContainsKey(panda2) == false)
            {
                AddPanda(panda1);
                AddPanda(panda2);
            }

            if (ListOfPandasInTheNetwork[panda1].Contains(panda2) == false)
            {
                ListOfPandasInTheNetwork[panda1].Add(panda2);
            }
            else
            {
                throw new PandasAlreadyFriendsException("The two users are already friends!");
            }

            if (ListOfPandasInTheNetwork[panda2].Contains(panda1) == false)
            {
                ListOfPandasInTheNetwork[panda2].Add(panda1);
            }
            else
            {
                throw new PandasAlreadyFriendsException("The two users are already friends!");
            }
        }
        public int Connectionlevel(Panda panda1, Panda panda2)
        {
            var inQueue = new Queue<PandaWithLevel>();
            var visited = new List<int>();

            inQueue.Enqueue(new PandaWithLevel { Level = 0, Panda = panda1.GetHashCode() });
            while (inQueue.Count > 0)
            {
                var currPandaWithLevel = inQueue.Dequeue();

                if (currPandaWithLevel.Panda == panda2.GetHashCode())
                {
                    return currPandaWithLevel.Level;
                }
                if (!visited.Contains(currPandaWithLevel.Panda))
                {
                    visited.Add(currPandaWithLevel.Panda);
                }

                var currPanda = _pandaUsers.FirstOrDefault(p => p.GetHashCode() == currPandaWithLevel.Panda.GetHashCode());

                if (currPanda != null && currPanda.Friends != null && currPanda.Friends.Count > 0)
                {
                    foreach (var friend in currPanda.Friends)
                    {
                        if (!visited.Contains(friend.GetHashCode()))
                        {
                            inQueue.Enqueue(new PandaWithLevel { Level = currPandaWithLevel.Level + 1, Panda = friend.GetHashCode() });
                        }
                    }
                }
            }
            return -1;
        }
        private int BFS ( PandaNode start , Panda p , int counter , Dictionary<PandaNode , bool> visited )
        {
            if(start.Friends.Contains(Accounts[p]))
            {
                return counter;
            }
            else
            {
                counter++;
                foreach(var item in start.Friends)
                {
                    if(visited.Keys.Contains(item))
                    {
                    }
                    else
                    {
                        visited.Add(item , false);
                    }
                    if(!visited[item])
                    {

                    }
                    else
                    {
                        visited[item] = true;
                        BFS(item , p , counter , visited);
                        visited[item] = false;
                    }
                }
            }
            return -1;
=======
        // I.method
        public Animal createAnimal(int animalCode)
        {
            Animal newAnimal = null;

            switch (animalCode)
            {
            case 0:
                newAnimal = new OrangUtan();
                break;

            case 1:
                newAnimal = new Tiger();
                break;

            case 2:
                newAnimal = new Panda();
                break;

            case 3:
                newAnimal = new Elephant();
                break;
            }

            return(newAnimal);
        }
        public void MakeFriends(Panda panda1, Panda panda2)
        {
            if (!HasPanda(panda1))
            {
                AddPanda(panda1);
            }
            else
            if (!HasPanda(panda2))
            {
                AddPanda(panda2);
            }

            if(panda1.Friends.Contains(panda2) && panda2.Friends.Contains(panda1))
            {
                throw new PandaAlreadyFriendsException();
            }
            if (!panda1.Friends.Contains(panda2))
            {
                panda1.Friends.Add(panda2);
            }
            else if (!panda2.Friends.Contains(panda1))
            {
                panda2.Friends.Add(panda1);
            }
        }
 public void Marry(Panda partner)
 {
     Mate         = partner;
     partner.Mate = this;
     //The this reference refers to the instance itself.
     //The this reference is valid only within nonstatic members of a class or struct
 }
Example #14
0
    public void Start()
    {
        Screen.SetResolution(600, 550, false);
        EventHandler.ResetGame += hideGameOver;
        EventHandler.GameOver  += GameOver;
        gameScore = 0;

        Lion henk = Instantiate(lion, animalCollector.transform).GetComponent <Lion>();

        henk.name = "henk";
        Hippo elsa = Instantiate(hippo, animalCollector.transform).GetComponent <Hippo>();

        elsa.name = "elsa";
        Pig dora = Instantiate(pig, animalCollector.transform).GetComponent <Pig>();

        dora.name = "dora";
        Tiger wally = Instantiate(tiger, animalCollector.transform).GetComponent <Tiger>();

        wally.name = "wally";
        Zebra marty = Instantiate(zebra, animalCollector.transform).GetComponent <Zebra>();

        marty.name = "marty";
        Zebra mario = Instantiate(zebra, animalCollector.transform).GetComponent <Zebra>();

        mario.name = "mario";
        Dog lena = Instantiate(dog, animalCollector.transform).GetComponent <Dog>();

        lena.name = "lena";
        Panda wilco = Instantiate(panda, animalCollector.transform).GetComponent <Panda>();

        wilco.name = "wilco";

        StartCoroutine(foodSpawner());
        StartCoroutine(giveScore());
    }
        public void WhatUpPanda()
        {
            Panda  testPanda = new Panda();
            string result    = testPanda.PandasUpTo();
            string expected  = "Panda's up to eating bamboo.";

            Assert.Equal(expected, result);
        }
Example #16
0
    //method: Start
    //purpose: constructor
    private void Start()
    {
        Panda panda = GetComponent <Panda>();

        maxHp = panda.GetMaxHealth();
        curHp = maxHp;
        UpdateHealthBar();
    }
Example #17
0
 public IActionResult Create(Panda p)
 {
     if (ModelState.IsValid)
     {
         context.Create(p);
     }
     return(Redirect("/"));
 }
Example #18
0
        private void btn_panda_Click(object sender, EventArgs e)
        {
            Graphics    ghs    = this.CreateGraphics();
            IDrawAnimal animal = new Panda();

            animal.ShowAnimal(ghs, 210, 405);
            ghs.Dispose();
        }
Example #19
0
 /// <summary>
 /// Creates an array of objects that represent each class that inherits from Bear
 /// </summary>
 /// <returns>Array of classes that inherit from Bear</returns>
 public static Bear[] CreateBears()
 {
     Bear[] bears = new Bear[3];
     bears[0] = new Panda();
     bears[1] = new Grizzly();
     bears[2] = new PolarBear();
     return(bears);
 }
 public bool AreFriends(Panda panda1, Panda panda2)
 {
     if (panda1.Friends.Contains(panda2) && panda2.Friends.Contains(panda1))
     {
         return true;
     }
     return false;
 }
Example #21
0
    //method: Start
    //purpose: constructor
    private void Start()
    {
        Panda panda = GetComponent <Panda>();

        maxFart = panda.GetMaxFartEnergy();
        curFart = panda.GetFartEnergy();
        UpdateFartGauge();
    }
 public void AddPanda(Panda panda)
 {
     if (_pandaUsers.Contains(panda))
     {
         throw new PandaAlreadyExistException();
     }
     _pandaUsers.Add(panda);
 }
 public bool HasPanda(Panda panda)
 {
     if (_pandaUsers.Contains(panda))
     {
         return true;
     }
     return false;
 }
Example #24
0
        static void Main(string[] args)
        {
            Robot Bot           = new Robot("Bender");
            Human Person        = new Human("Kate");
            Panda BlackAndWhite = new Panda("Joe Bear");

            List <ICritters> AllCritters = new List <ICritters> {
                Bot, Person, BlackAndWhite
            };

            foreach (ICritters c in AllCritters)
            {
                c.DisplayName();
                Console.Write($"{c.Name} says ");
                c.DisplayGreeting();
                Console.WriteLine($"{c.Name} is Asleep? {c.IsASleep()}");
                Console.WriteLine();
            }

            List <Organic> Organics = new List <Organic> {
                BlackAndWhite, Person
            };

            foreach (Organic o in Organics)
            {
                o.Eat("Tacos");
            }

            Console.WriteLine();
            if (Bot.IsTerminator)
            {
                Console.WriteLine($"{Bot.Name} is a terminator");
            }

            Bot.ShutDown();
            Person.GoToSleep();
            BlackAndWhite.GoToSleep();

            foreach (ICritters c in AllCritters)
            {
                Console.WriteLine($"{c.Name} is Asleep? {c.IsASleep()}");
                Console.WriteLine();
            }

            Console.WriteLine();

            Bot.StartUp();
            Person.WakeUp();
            BlackAndWhite.WakeUp();

            foreach (ICritters c in AllCritters)
            {
                Console.WriteLine($"{c.Name} is Asleep? {c.IsASleep()}");
                Console.WriteLine();
            }

            Console.ReadLine();
        }
Example #25
0
    static void Main()                       //Обьявление метода
    {
        Panda p1 = new Panda("Pan Dee");     //Присвоение значения Pan Dee экземпляру p1 класса Panda
        Panda p2 = new Panda("Pan Dah");     //Присвоение значения Pan Dah экземпляру p2 класса Panda

        Console.WriteLine(p1.Name);          //Вывод на экран значение Name экземпляра p1 класса Panda   Результат: Pan Dee
        Console.WriteLine(p2.Name);          //Вывод на экран значение Name экземпляра p2 класса Panda   Результат: Pan Dah
        Console.WriteLine(Panda.Population); //Вывод на экран значение статического поля Population      Результат: 2
    }                                        //Конец метода
Example #26
0
        public bool HasPanda(Panda panda)
        {
            if (container.ContainsKey(panda))
            {
                return(true);
            }

            return(false);
        }
Example #27
0
        public bool AreFriends(Panda panda1, Panda panda2)
        {
            if (container[panda1].Contains(panda2))
            {
                return(true);
            }

            return(false);
        }
 public int ConnectionLevel ( Panda p1 , Panda p2 )
 {
     Dictionary<PandaNode , bool> visited= new Dictionary<PandaNode, bool>();
     if(Accounts.Keys.Contains(p1) && Accounts.Keys.Contains(p2))
     {
         return BFS(Accounts[p1] , p2 , 0 , visited);
     }
     return -1;
 }
Example #29
0
    static void Main(string[] args)
    {
        var p1 = new Panda("p1");
        var p2 = new Panda("p2");

        Console.WriteLine(p1.name);
        Console.WriteLine(p2.name);
        Console.WriteLine(Panda.population);
    }
Example #30
0
        public bool AreConnected(Panda panda1, Panda panda2)
        {
            if (ConnectionLevel(panda1, panda2) > 0)
            {
                return(true);
            }

            return(false);
        }
    static void Main()
    {
        Panda p1 = new Panda("Pan Dee");
        Panda p2 = new Panda("Pan Dah");

        Console.WriteLine(p1.Name);
        Console.WriteLine(p2.Name);

        Console.WriteLine(Panda.Population);
    }
Example #32
0
    static void Main()
    {
        Panda p1 = new Panda("Pan Dee");
        Panda p2 = new Panda("Pan Dah");

        Console.WriteLine(p1.name);
        Console.WriteLine(p2.name);

        Console.WriteLine("There are " + Panda.Population + " pandas!");
    }
Example #33
0
    static void Example4_InstanceVersusStaticMembers()
    {
        Panda p1 = new Panda("Pan Dee");
        Panda p2 = new Panda("Pan Dah");

        Console.WriteLine(p1.Name);
        Console.WriteLine(p2.Name);

        Console.WriteLine(Panda.Population);
    }
        public void ContrastInstanceStaticMembers()
        {
            Panda P1 = new Panda("Pan Dee");
            Panda P2 = new Panda("Pan Dah");

            Console.WriteLine(P1.Name);
            Console.WriteLine(P2.Name);

            Assert.AreEqual(2, Panda.Population);
        }
        public bool PandaPanda()
        {
            Panda  testPanda = new Panda();
            string result    = testPanda.PandasEat();
            string expected  = "Panda's sit on their butts and eat bamboo all day!";

            Assert.Equal(expected, result);

            return(true);
        }
        public List<Panda> FriendsOf(Panda panda)
        {
            List<Panda> result = new List<Panda>();

            if (HasPanda(panda))
            {
                result = panda.Friends;
            }

            return result;
        }
Example #37
0
        public void GetFoodNeededForPanda_TestPanda_CorrectSum(int ageOfPanda, double expectedFoodNeeded)
        {
            var testPanda = new Panda()
            {
                Age = ageOfPanda
            };

            var actualFoodNeeded = testPanda.Feed();

            Assert.Equal(expectedFoodNeeded, actualFoodNeeded);
        }
 private bool HasPanda(Panda isSocial)
 {
     if (PandaList.Contains(isSocial))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #39
0
 public int ConnectionLevel(Panda panda1, Panda panda2)
 {
     if (AreFriends(panda1, panda2))
     {
         return(1);
     }
     else
     {
         return(FindConnectionLevel(panda1, panda2));
     }
 }
Example #40
0
 public List <Panda> FriendsOf(Panda panda)
 {
     if (!container.ContainsKey(panda))
     {
         return(null);
     }
     else
     {
         return(container[panda]);
     }
 }
Example #41
0
 public bool HasPanda(Panda panda)
 {
     if (ListOfPandasInTheNetwork.ContainsKey(panda))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #42
0
        //public enum GenderType
        //{
        //    Male,
        //    Female
        //}


        public void AddPanda(Panda panda)
        {
            if (!ListOfPandasInTheNetwork.ContainsKey(panda))
            {
                ListOfPandasInTheNetwork.Add(panda, new List<Panda>());
            }
            else
            {
                throw new PandaAlreadyThereException("The user " + panda.pandaName + "is already register in our socialnetwork");
            }
        }
Example #43
0
 public bool AreFriends(Panda panda1, Panda panda2)
 {
     if (ListOfPandasInTheNetwork[panda1].Contains(panda2))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #44
0
 public void AddPanda(Panda panda)
 {
     if (container.ContainsKey(panda))
     {
         throw new PandaAlreadyThereException();
     }
     else
     {
         container.Add(panda, new List <Panda>());
     }
 }
Example #45
0
        static void Main(string[] args)
        {
            Zoo     zoo        = new Zoo();
            iAnimal milacha    = new Panda();
            iAnimal someGrizly = new Bear();
            iAnimal rocket     = new Racoon();

            zoo.AddToZooparck(milacha);
            zoo.AddToZooparck(someGrizly);
            zoo.AddToZooparck(rocket);
        }
Example #46
0
        public void TestInitialize()
        {
            provider = new PandaSocialNetworkStorageProvider();

            // Make some network and save to file:

            var network = new PandaSocialNetwork();

            ivo = new Panda("Ivo", "*****@*****.**", GenderType.Male);

            network.AddPanda(ivo);

            provider.Save(network, "MyTestNetwork");
        }
 public bool AreConnected(Panda panda1, Panda panda2)
 {
     return Connectionlevel(panda1, panda2) > 0 ? true : false;
 }
 public void NullParameters()
 {
     var panda = new Panda("as", null, Gender.Male);
 }
 static void Main(string[] args)
 {
     PandaSocialNetwork socialNetwork = new PandaSocialNetwork();
     Console.WriteLine("WELCOME TO THE PANDAS SOCIAL NETWORK!");
     StringBuilder helper = new StringBuilder();
     helper.Append("-------- HELP MENU --------").AppendLine()
           .Append("To display the HELP MENU again please type - help").AppendLine()
           .Append("To add new panda use - addpanda <name> <email> <male/female>").AppendLine()
           .Append("To make two pandas Friends use - makefriends <panda1><panda1's email> <panda2><panda2's email>").AppendLine()
           .Append("To view the Friends of a panda use - friendsof <panda><panda's email>").AppendLine()
           .Append("To see the connection level between two pandas use - connectionlevel <panda1> <panda2>").AppendLine()
           .Append("To see if two pandas are connected use - areconnected <panda1> <panda2>").AppendLine()
           .Append("To see how many pandas of certain gender are in the network use - HowManyGenderInNetwork <level> <panda> <gender>").AppendLine()
           .Append("-------- HAVE FUN --------");
     Console.WriteLine(helper.ToString());
     while (true)
     {
         string wholeCommand = Console.ReadLine();
         string[] command = wholeCommand.ToLower().Split(' ');
         switch (command[0])
         {
             case "help":
                 Console.WriteLine(helper.ToString());
                 break;
             case "addpanda":
                 try
                 {
                     GenderType gender;
                     if (command[3] == "male")
                     {
                         gender = GenderType.Male; ;
                     }
                     else
                     {
                         gender = GenderType.Female;
                     }
                     var panda = new Panda(command[1], command[2], gender);
                     socialNetwork.AddPanda(panda);
                 }
                 catch (PandaAlreadyExistException exception)
                 {
                     Console.WriteLine(exception.Message);
                 }
                 break;
             case "makefriends":
                 try
                 {
                     var friendPanda1 = new Panda();
                     var friendPanda2 = new Panda();
                     foreach (var user in socialNetwork._pandaUsers)
                     {
                         if (user.Name == command[1] && user.Email == command[2])
                         {
                             friendPanda1 = user;
                         }
                         if (user.Name == command[3] && user.Email == command[4])
                         {
                             friendPanda2 = user;
                         }
                     }
                     socialNetwork.MakeFriends(friendPanda1, friendPanda2);
                 }
                 catch (PandaAlreadyFriendsException exception)
                 {
                     Console.WriteLine(exception.Message);
                     continue;    
                 }
                 break;
             case "friendsof":
                 var friendsOfPanda = new Panda();
                 foreach (var user in socialNetwork._pandaUsers)
                 {
                     if (user.Name == command[1] && user.Email == command[2])
                     {
                         friendsOfPanda = user;
                         break;
                     }
                 }
                 foreach (var friend in socialNetwork.FriendsOf(friendsOfPanda))
                 {
                     Console.WriteLine(friend.Name);
                 }
                 break;
             case "connectionlevel":
                 //Console.WriteLine(socialNetwork.Connectionlevel(command[1], command[2]));
                 break;
             case "areconnected":
                 //Console.WriteLine(socialNetwork.AreConnected(command[1], command[2]));
                 break;
             case "howmanygenderinnetwork":
                 //Console.WriteLine(socialNetwork.HowManyGenderInNetwork(int.Parse(command[1]), command[2], command[3]));
                 break;
             case "exit":
                 Environment.Exit(0);
                 break;
             default:
                 Console.WriteLine("ERROR: Invalid command! Type \"help\" to see list with functions.");
                 break;
         }
     }
 }
        static bool CheckFriendConnectionDFSRecursive(Panda current, string target, HashSet<Panda> visited)
        {
            Console.WriteLine("Currently at " + current.Name);
            visited.Add(current);

            foreach(Panda friend in current.Friends)
            {
                if(!visited.Contains(friend))
                {
                    if (friend.Name == target)
                    {
                        return true;
                    }

                    Console.WriteLine("Checking friend " + friend.Name);

                    visited.Add(friend);
                    if(CheckFriendConnectionDFSRecursive(friend, target, visited))
                    {
                        return true;
                    }

                    Console.WriteLine("Finished checking friend " + friend.Name);
                }
            }

            return false;
        }
Example #51
0
        public int ConnectionLevel(Panda panda1, Panda panda2)
        {
            if (!HasPanda(panda1) || !HasPanda(panda2))
            {
                return -1;
            }


            var visited = new List<Panda>();
            var queue = new Queue<ConnectionLevelNode>();


            queue.Enqueue(new ConnectionLevelNode()
            {
                Node = panda1,
                Level = 0
            });

            while (queue.Count > 0)
            {
                var pandaContainer = queue.Dequeue();
                visited.Add(pandaContainer.Node);

                if (ListOfPandasInTheNetwork[pandaContainer.Node].Contains(panda2))
                {
                    return pandaContainer.Level + 1;
                }

                foreach (var neighbour in ListOfPandasInTheNetwork[pandaContainer.Node])
                {
                    if (!visited.Contains(neighbour))
                    {

                        queue.Enqueue(new ConnectionLevelNode()
                        {
                            Node = neighbour,
                            Level = pandaContainer.Level + 1
                        });
                    }
                }
            }

            return -1;
        }
Example #52
0
        public bool AreConnected(Panda panda1,Panda panda2)
        {
            var visited = new List<Panda>();
            var queue = new Queue<Panda>();

            queue.Enqueue(panda1);
            while (queue.Count > 0)
            {
                var pandaContainer = queue.Dequeue();
                visited.Add(pandaContainer);

                if (ListOfPandasInTheNetwork[pandaContainer].Contains(panda2))
                {
                    return true;
                }
                foreach (var neighbour in ListOfPandasInTheNetwork[pandaContainer])
                {
                    if (!visited.Contains(neighbour))
                    {
                        queue.Enqueue(neighbour);
                    }
                }
            }
            return false;                         
        }
Example #53
0
        public int HowManyGenderInNetwork(int level, Panda panda, Panda.GenderType genderType)
        {
            var visited = new List<Panda>();
            var queue = new Queue<ConnectionLevelNode>();
            int genderResult = 0;

            queue.Enqueue(new ConnectionLevelNode()
            {
                Node = panda,
                Level = 0
            });

            while (queue.Count > 0)
            {
                var pandaContainer = queue.Dequeue();
                visited.Add(pandaContainer.Node);

                if (pandaContainer.Level <= level)
                {
                    if (pandaContainer.Node.pandaGender == genderType)
                    {
                        genderResult = genderResult + 1;
                    }
                }
                else
                {
                    break;
                }
                foreach (var neighbour in ListOfPandasInTheNetwork[pandaContainer.Node])
                {
                    if (!visited.Contains(neighbour))
                    {
                        queue.Enqueue(new ConnectionLevelNode()
                        {
                            Node = neighbour,
                            Level = pandaContainer.Level + 1
                        });
                    }
                }
            }
            return genderResult;

        }
Example #54
0
        public List<string> FriendsOf(Panda panda)
        {
            List<string> friendsHolder = new List<string>();

            if (ListOfPandasInTheNetwork.ContainsKey(panda))
            {
                foreach (var item in ListOfPandasInTheNetwork[panda])
                {
                    friendsHolder.Add(item.ToString());
                }
                return friendsHolder;
            }
            else
            {
                return null;
            }
        }
        public int HowManyGenderInNetwork(int level, Panda panda, GenderType gender)
        {
            var inQueue = new Queue<PandaWithLevel>();
            var visited = new List<int>();
            var genderCounter = 0;

            inQueue.Enqueue(new PandaWithLevel { Level = 0, Panda = panda.GetHashCode() });
            foreach (var friend in panda.Friends)
            {
                inQueue.Enqueue(new PandaWithLevel { Level = 1, Panda = friend.GetHashCode() });
            }
            while (inQueue.Count > 0)
            {
                var currPandaWithLevel = inQueue.Dequeue();
                var currPanda = _pandaUsers.FirstOrDefault(p => p.GetHashCode() == currPandaWithLevel.Panda.GetHashCode());
                if (!visited.Contains(currPanda.GetHashCode()) && currPanda.gender == gender)
                {
                    visited.Add(currPandaWithLevel.Panda);
                    genderCounter++;
                }
                if (currPandaWithLevel.Level < level)
                {
                    foreach (var friend in currPanda.Friends)
                    {
                        if (!visited.Contains(friend.GetHashCode()))
                        {
                            inQueue.Enqueue(new PandaWithLevel { Level = currPandaWithLevel.Level + 1, Panda = friend.GetHashCode() });
                        }
                    }
                }
            }
            return genderCounter;
        }
 private MakeFriends(Panda panda1, Panda panda2)
 {
     
 }
        public PandaSocialNetwork(Panda newPanda)
        {
            if (PandaList.Contains(newPanda))
	        {
		        throw new Exception("Panda already there!");
	        }
            else
	        {
                PandaList.Add(newPanda);
	        }          
>>>>>>> origin/master
        }
Example #58
0
 public void CreatePandaWithInvalidEmailTest()
 {
     var panda = new Panda("Ivo", "ivopandamail", GenderType.Male);
 }