예제 #1
0
        public static void Iterator()
        {
            // Build a collection of jelly beans
            JellyBeanCollection collection = new JellyBeanCollection();

            collection[0] = new JellyBean("Cherry");
            collection[1] = new JellyBean("Bubble Gum");
            collection[2] = new JellyBean("Root Beer");
            collection[3] = new JellyBean("French Vanilla");
            collection[4] = new JellyBean("Licorice");
            collection[5] = new JellyBean("Buttered Popcorn");
            collection[6] = new JellyBean("Juicy Pear");
            collection[7] = new JellyBean("Cinnamon");
            collection[8] = new JellyBean("Coconut");

            // Create iterator
            JellyBeanIterator iterator = collection.CreateIterator();

            Console.WriteLine("Gimme all the jelly beans!");

            for (JellyBean item = iterator.First(); !iterator.IsDone; item = iterator.Next())
            {
                Console.WriteLine(item.Flavor);
            }
        }
예제 #2
0
        public void Iterator_pattern_test()
        {
            JellyBeanCollection collection = new JellyBeanCollection();

            collection[0] = new JellyBean("Cherry");
            collection[1] = new JellyBean("Bubble Gum");
            collection[2] = new JellyBean("Root Beer");
            collection[3] = new JellyBean("French Vanilla");
            collection[4] = new JellyBean("Licorice");
            collection[5] = new JellyBean("Buttered Popcorn");
            collection[6] = new JellyBean("Juicy Pear");
            collection[7] = new JellyBean("Cinnamon");
            collection[8] = new JellyBean("Coconut");

            //Create Interator
            JellyBeanIterator iterator = collection.CreateIterator();

            JellyBean firstJellyBean = iterator.First();

            Assert.AreEqual("Cherry", firstJellyBean.Flavor);

            JellyBean lastJellyBean = iterator.Last();

            Assert.AreEqual("Coconut", lastJellyBean.Flavor);
        }
예제 #3
0
 public async Task <IActionResult> CreateJelly(JellyBean jellyBean)
 {
     if (ModelState.IsValid)
     {
         _context.Add(jellyBean);
         await _context.SaveChangesAsync();
     }
     return(RedirectToAction(nameof(JellyBean)));
 }
예제 #4
0
    public void PickedUpJellyBean(JellyBean bean)
    {
        switch (bean.GetBeanType())
        {
        case JellyBeanType.Health:
            ChangeHealth(1);
            UpdateBars();
            break;

        case JellyBeanType.MoveSpeed:
            if (!m_UsingSpeedBoostAbility)
            {
                if (m_speedBarProgress < m_speedBarMax)
                {
                    m_speedBarProgress += 1;
                }
                UpdateBars();
            }
            break;
        }
        m_game.SpawnBean(bean.GetComponent <PoolItem>());
    }