Algoritmlar tillar va dasturlash


Download 75.3 Kb.
Sana11.05.2023
Hajmi75.3 Kb.
#1452779
Bog'liq
amaliy topshiriq


OʻZBEKISTON RESPUBLIKASI OLIY VA O‘RTA MAXSUS
TA’LIM VAZIRLIGI
MIRZO ULUG‘BEK NOMIDAGI MILLIY UNIVERSITETININIG
JIZZAX FILIALI



AMALIY MATEMATIKA FAKULTETI


«KOMPYUTER ILMLARI VA DASTURLASHTIRISH» kafedrasi

ALGORITMLAR TILLAR VA DASTURLASH ”


FANIDAN
Amaliy topshiriq
Bajardi: “ATT” yoʻnalishi 3-kurs 961-21- guruh
talabasi : Achilova Tumaris
Tekshirdi: Shirinboyev R
Jizzax-2023
Amaliy topshiriq
Svetofor tasvirini hosil qiling. Hosil qilingan svetoforning ishlashini (o’chib yonishini) ta’minlang.
Topshiriqni quyidagi tartibda bajaramiz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace Wpf_от_09._10._2017_Traffic_Light_c_sharp_
{
public partial class MainWindow : Window
{
private DispatcherTimer dispatcherTimer; // для таймера
bool flag_Start_Stop = true; // флаг для старт_стопа
private int x_seconds_external = 40; // для переключения цвета автомобильный светофор
private int x_seconds_internal; // для переключения цвета пешеходный светофор
DoubleAnimation da = new DoubleAnimation();
public MainWindow()
{
InitializeComponent();
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = TimeSpan.FromSeconds(1); // new TimeSpan(0, 0, 0, 0, 0);
lbl_Automobile_Red_Second.Visibility = Visibility.Hidden;
lbl_Automobile_Orange_Second.Visibility = Visibility.Hidden;
lbl_Automobile_Green_Second.Visibility = Visibility.Hidden;
lbl_Pedestrian_Red_Second.Visibility = Visibility.Hidden;
lbl_Pedestrian_Green_Second.Visibility = Visibility.Hidden;
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
lbl_Automobile_Red_Second.Content = String.Format("{0:00}", x_seconds_external);
lbl_Automobile_Red_Second.Visibility = Visibility.Visible;
x_seconds_external--;
lbl_Pedestrian_Green_Second.Visibility = Visibility.Visible;
lbl_Pedestrian_Green_Second.Content = String.Format("{0:00}", x_seconds_external);
x_seconds_internal = x_seconds_external;
Automobile_Red.Fill = Brushes.Red;
Pedestrian_Green.Fill = Brushes.Green;
if(x_seconds_external < 35)
{
da.From = Convert.ToDouble(Brushes.Red);
da.To = Convert.ToDouble(Brushes.White);
da.Duration = TimeSpan.FromSeconds(5);
Automobile_Red.Fill.BeginAnimation(Ellipse.FillProperty, da);
}
//переключаем цвета для автомобильного светофора
if (x_seconds_external < 30)
{
Automobile_Red.Fill = Brushes.White;
Automobile_Orange.Fill = Brushes.Orange;
lbl_Automobile_Red_Second.Visibility = Visibility.Hidden;
lbl_Automobile_Orange_Second.Visibility = Visibility.Visible;
lbl_Automobile_Orange_Second.Content = lbl_Automobile_Red_Second.Content;
// переключаем цвета для пешеходного светофора
if (x_seconds_internal < 22)
{
Pedestrian_Green.Fill = Brushes.White;
Pedestrian_Red.Fill = Brushes.Red;
lbl_Pedestrian_Green_Second.Visibility = Visibility.Hidden;
lbl_Pedestrian_Red_Second.Visibility = Visibility.Visible;
lbl_Pedestrian_Red_Second.Content = lbl_Pedestrian_Green_Second.Content;
//переключаем цвета для автомобильного светофора
if (x_seconds_external < 20)
{
Automobile_Orange.Fill = Brushes.White;
Automobile_Green.Fill = Brushes.Green;
lbl_Automobile_Orange_Second.Visibility = Visibility.Hidden;
lbl_Automobile_Green_Second.Visibility = Visibility.Visible;
lbl_Automobile_Green_Second.Content = lbl_Automobile_Orange_Second.Content;

T Achilova, [Чт 20.04.23 8:36]


//переключаем цвета для автомобильного светофора
if (x_seconds_external < 0)
{
Automobile_Green.Fill = Brushes.White;
Automobile_Red.Fill = Brushes.Red;
x_seconds_external = 40;
lbl_Automobile_Red_Second.Visibility = Visibility.Visible;
lbl_Automobile_Green_Second.Visibility = Visibility.Hidden;
// переключаем цвета для пешеходного светофора
if (x_seconds_internal > -2)
{
Pedestrian_Red.Fill = Brushes.White;
Pedestrian_Green.Fill = Brushes.Green;
lbl_Pedestrian_Red_Second.Visibility = Visibility.Hidden;
}
}
}
}
}
}
private void btn_Start_Stop_Click(object sender, RoutedEventArgs e)
{
if (flag_Start_Stop == true)
{
dispatcherTimer.Start();
flag_Start_Stop = false;
btn_Start_Stop.Content = "STOP";
btn_Start_Stop.Background = System.Windows.Media.Brushes.Red;
}
else if (flag_Start_Stop == false)
{
dispatcherTimer.Stop();
flag_Start_Stop = true;
btn_Start_Stop.Content = "START";
btn_Start_Stop.Background = System.Windows.Media.Brushes.GreenYellow;
}
}
}
}
Download 75.3 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling