Exemplo n.º 1
0
        private void addFlapjacks_Click(object sender, EventArgs e)
        {
            if (breakfastLine.Count == 0)
            {
                return;
            }
            Flapjack food;

            if (crispy.Checked)
            {
                food = Flapjack.Crispy;
            }
            else if (soggy.Checked)
            {
                food = Flapjack.Soggy;
            }
            else if (browned.Checked)
            {
                food = Flapjack.Browned;
            }
            else
            {
                food = Flapjack.Banana;
            }

            Lumberjack currentLumberjack = breakfastLine.Peek();

            currentLumberjack.TakeFlapjacks(food, (int)howMany.Value);

            RedrawList();
        }
        private void RedrawList()
        {
            int queueNumber = 1;

            line.Items.Clear();
            foreach (Lumberjack lumberjack in breakfastLine)
            {
                line.Items.Add(queueNumber + ". " + lumberjack.Name);
                queueNumber++;
            }

            if (breakfastLine.Count == 0)
            {
                spFeedALumberjack.IsEnabled = false;
                nextLumberjack.IsEnabled    = false;
                nextInLine.Content          = "";
            }
            else
            {
                spFeedALumberjack.IsEnabled = true;
                nextLumberjack.IsEnabled    = true;
                Lumberjack currentLumberjack = breakfastLine.Peek();
                nextInLine.Content = currentLumberjack.Name + " has " + currentLumberjack.FlapjackCount + " flapjacks.";
            }
        }
        static void Main(string[] args)
        {
            Random             random      = new Random();
            Queue <Lumberjack> lumberjacks = new Queue <Lumberjack>();

            string name;

            Console.Write("First lumberjack's name: ");
            while ((name = Console.ReadLine()) != "")
            {
                Console.Write("Number of flapjacks: ");
                if (int.TryParse(Console.ReadLine(), out int number))
                {
                    Lumberjack lumberjack = new Lumberjack(name);
                    for (int i = 0; i < number; i++)
                    {
                        lumberjack.TakeFlapjack((Flapjack)random.Next(0, 4));
                    }
                    lumberjacks.Enqueue(lumberjack);
                }
                Console.Write("Next lumberjack's name (blank to end): ");
            }

            while (lumberjacks.Count > 0)
            {
                Lumberjack next = lumberjacks.Dequeue();
                next.EatFlapjacks();
            }
        }
Exemplo n.º 4
0
        private void nextLumberjack_Click(object sender, EventArgs e)
        {
            if (breakfastLine.Count == 0)
            {
                return;
            }
            Lumberjack nextLumberjack = breakfastLine.Dequeue();

            nextLumberjack.EatFlapjacks();
            nextInLine.Text = "";
            RedrawList();
        }
        private void addFlapjacks_Click(object sender, RoutedEventArgs e)
        {
            if (breakfastLine.Count == 0)
            {
                return;
            }
            Flapjack food      = Flapjack.None;
            string   selection = flapJackOrder.SelectionBoxItem.ToString();

            if (selection == "Crispy")
            {
                food = Flapjack.Crispy;
            }
            else if (selection == "Checked")
            {
                food = Flapjack.Soggy;
            }
            else if (selection == "Browned")
            {
                food = Flapjack.Browned;
            }
            else if (selection == "Banana")
            {
                food = Flapjack.Banana;
            }

            if (food != Flapjack.None)
            {
                Lumberjack currentLumberjack = breakfastLine.Peek();
                int        howManyNumber;
                if (int.TryParse(howMany.Text, out howManyNumber))
                {
                    currentLumberjack.TakeFlapjacks(food, howManyNumber);
                }

                RedrawList();
            }
        }