Exemple #1
0
        private void CreateInitializationList(object sender, RoutedEventArgs e)
        {
            //Validate Inputs
            if (!IsValidInputs())
            {
                return;
            }

            //Reset
            InitializationList.Clear();
            InitializationPanel.Children.Clear();

            //Add vertical Line for start day
            Grid verticalLine = ShapeService.GetVerticalLineWithNumber(0);

            InitializationPanel.Children.Add(verticalLine);

            //Set DefaultType
            DefaultType = DefaultHouseTypeIsActive.IsChecked == true
                ? HouseType.Аctive
                : HouseType.Inactive;

            //Set DefaultUrlPicture
            DefaultUrlPicture = DefaultType == HouseType.Аctive
                ? UrlPicture.ACTIVE_HOUSE
                : UrlPicture.INACTIVE_HOUSE;

            //Set NumberOfElements
            NumberOfElements = int.Parse(NumberOfHouses.Text);

            for (int i = 0; i < NumberOfElements; i++)
            {
                InitializationList.Add(new House
                {
                    Number     = i + 1,
                    UrlPicture = DefaultUrlPicture,
                    HouseType  = DefaultType,
                });

                StackPanel wrapper = new StackPanel();

                Grid    horizontalLine = ShapeService.GetHorizontalLineWithNumber(i + 1);
                Image   image          = ShapeService.GetImage();
                Binding binding        = new Binding();
                binding.Source = InitializationList;
                binding.Path   = new PropertyPath($"[{i}].UrlPicture");
                image.SetBinding(Image.SourceProperty, binding);
                Button button = ShapeService.GetButton();
                button.Click           += ReverseImage;
                button.CommandParameter = i;

                wrapper.Children.Add(horizontalLine);
                wrapper.Children.Add(image);
                wrapper.Children.Add(button);

                InitializationPanel.Children.Add(wrapper);
            }
        }
Exemple #2
0
        private void Play(object sender, RoutedEventArgs e)
        {
            //Check if Play operation is possible
            if (InitializationList.Count == 0)
            {
                return;
            }

            //Reset
            PlaygroundCanvas.Children.Clear();

            //Add vertical Line for start day
            Grid verticalLine = ShapeService.GetVerticalLineWithNumber(0);

            Canvas.SetTop(verticalLine, 20);
            PlaygroundCanvas.Children.Add(verticalLine);

            List <Image> racerList = new List <Image>();

            //Create start day
            for (int i = 0; i < NumberOfElements; i++)
            {
                Grid horizontalLine = ShapeService.GetHorizontalLineWithNumber(i + 1);
                Canvas.SetLeft(horizontalLine, 20 + (i * 100));

                Image image = ShapeService.GetImage();
                image.Source = new BitmapImage(new Uri(UrlPicture.ACTIVE_HOUSE, UriKind.Relative));
                Canvas.SetLeft(image, 20 + (i * 100));
                Canvas.SetTop(image, 20);

                racerList.Add(image);

                PlaygroundCanvas.Children.Add(horizontalLine);
                PlaygroundCanvas.Children.Add(image);
            }

            PlaygroundCanvas.Width  = 20 + (InitializationList.Count * 100);
            PlaygroundCanvas.Height = 110;

            //Refresh View
            Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
            Thread.Sleep(500);

            //Set NumberOfDasy
            NumberOfDasy = int.Parse(NumberOfDays.Text);

            List <HouseType> currentStatus = GetCurrentRowStatus();
            List <HouseType> nextStatus    = GetNextRowStatus(currentStatus);

            int currentRow = 1;

            for (int day = 1; day <= NumberOfDasy; day++)
            {
                List <int> moveIndexes = new List <int>();

                bool isNeedVerticalLineForNextDay  = false;
                bool isAddedVerticalLineForNextDay = false;

                for (int i = 0; i < nextStatus.Count; i++)
                {
                    if (nextStatus[i] == HouseType.Аctive)
                    {
                        moveIndexes.Add(i);
                    }
                }

                for (int step = 1; step <= 90; step++)
                {
                    foreach (var index in moveIndexes)
                    {
                        var    currentElement  = racerList[index];
                        double currentPosition = Canvas.GetTop(currentElement);
                        Canvas.SetTop(currentElement, currentPosition + 1);

                        if (currentPosition + 90 > PlaygroundCanvas.Height)
                        {
                            PlaygroundCanvas.Height += 1;

                            isNeedVerticalLineForNextDay = true;
                        }
                    }

                    //Create vertical line for next day
                    if (isNeedVerticalLineForNextDay && !isAddedVerticalLineForNextDay)
                    {
                        Grid currentDay = ShapeService.GetVerticalLineWithNumber(currentRow);
                        Canvas.SetTop(currentDay, 20 + (currentRow * 90));
                        PlaygroundCanvas.Children.Add(currentDay);

                        currentRow++;

                        isAddedVerticalLineForNextDay = true;
                    }

                    PlaygroundScrollViewer.ScrollToBottom();
                    Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);

                    Thread.Sleep(10);
                }

                nextStatus = GetNextRowStatus(nextStatus);
            }
        }