Untitled
unknown
plain_text
9 months ago
3.8 kB
6
Indexable
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace CoffeeMachine
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
coffeeSlider.ValueChanged += CoffeeSlider_ValueChanged;
milkSlider.ValueChanged += MilkSlider_ValueChanged;
}
private void CoffeeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
UpdateCoffeePrice();
UpdateTotalPrice();
UpdateProgressBarColor();
}
private void MilkSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
UpdateMilkPrice();
UpdateTotalPrice();
UpdateProgressBarColor();
}
private void UpdateCoffeePrice()
{
double coffeeAmount = coffeeSlider.Value;
int coffeePrice = (int)(coffeeAmount * 200);
}
private void UpdateMilkPrice()
{
double milkAmount = milkSlider.Value;
int milkPrice = (int)(milkAmount * 100);
}
private void UpdateTotalPrice()
{
double coffeeAmount = coffeeSlider.Value;
double milkAmount = milkSlider.Value;
int totalPriceValue = (int)((coffeeAmount * 200) + (milkAmount * 100));
totalPrice.Text = $"{totalPriceValue} Ft";
// Progressbar magasság beállítása
progressBar.Height = Math.Min(50 * (coffeeAmount + milkAmount), 50);
}
private void UpdateProgressBarColor()
{
double coffeeAmount = coffeeSlider.Value;
double milkAmount = milkSlider.Value;
progressBar.Fill = new SolidColorBrush(GetCoffeeColor(coffeeAmount, milkAmount));
}
private void addToOrdersButton_Click(object sender, RoutedEventArgs e)
{
double coffeeAmount = coffeeSlider.Value;
double milkAmount = milkSlider.Value;
int totalPrice = (int)((coffeeAmount * 200) + (milkAmount * 100));
Color orderColor = GetCoffeeColor(coffeeAmount, milkAmount);
ordersList.Items.Add(new CoffeeOrder(totalPrice, orderColor));
coffeeSlider.Value = 0;
milkSlider.Value = 0;
UpdateCoffeePrice();
UpdateMilkPrice();
UpdateTotalPrice();
UpdateProgressBarColor();
}
private Color GetCoffeeColor(double coffeeAmount, double milkAmount)
{
if (coffeeAmount == 0 && milkAmount == 0)
{
return Colors.Gray;
}
else if (coffeeAmount == 0)
{
return Colors.White;
}
else if (milkAmount == 0)
{
return Colors.Black;
}
else if (coffeeAmount > milkAmount)
{
return Color.FromRgb(80, 50, 20);
}
else if (coffeeAmount < milkAmount)
{
return Color.FromRgb(230, 230, 200);
}
else
{
return Color.FromRgb(120, 90, 50);
}
}
}
public class CoffeeOrder
{
public int Price { get; set; }
public Color Color { get; set; }
public CoffeeOrder(int price, Color color)
{
Price = price;
Color = color;
}
}
}Editor is loading...
Leave a Comment