Esempio n. 1
0
        public Form1()
        {
            InitializeComponent();
            WaterContainer container = new WaterContainer(volume: 2000);
            Heater         heater    = new Heater(power: 1500, efficioncy: 0.85f);
            PowerButton    button    = new PowerButton();

            Teapot = new Teapot(container, heater, button);
            Teapot.AddWater(new Water(500, 20));
            DoubleBuffered = true;

            // Костыль
            ThreadStart start = new ThreadStart(() =>
            {
                Thread.Sleep(1000);
                while (ActiveForm != null)
                {
                    float timedelta = (float)(DateTime.Now - time).TotalSeconds;
                    if (timedelta > 0.03f)
                    {
                        time = DateTime.Now;
                        Teapot.Update(timedelta);
                        try
                        {
                            Form1.ActiveForm.Invoke(new Action(() => Refresh()));
                        }
                        catch
                        {
                            Thread.CurrentThread.Abort();
                        }
                    }
                }
            });
            Thread thread = new Thread(start);

            thread.Start();
        }
Esempio n. 2
0
 public Teapot(WaterContainer waterContainer, Heater heater, PowerButton powerButton)
 {
     WaterContainer = waterContainer ?? throw new ArgumentNullException(nameof(waterContainer));
     Heater         = heater ?? throw new ArgumentNullException(nameof(heater));
     PowerButton    = powerButton ?? throw new ArgumentNullException(nameof(powerButton));
 }