Пример #1
0
 private void set_group(object sender, RoutedEventArgs e)
 {
     if (IsInteger(this.group_text_block.Text.Trim()) && IsInteger(this.delay_text_block.Text.Trim()) && IsInteger(this.bomb_text_block.Text.Trim()) && group_state != 0)
     {
         int   group_ = int.Parse(this.group_text_block.Text.Trim());
         int   delay_ = int.Parse(this.delay_text_block.Text.Trim());
         int   bomb_  = int.Parse(this.bomb_text_block.Text.Trim());
         Point p      = new Point(0, 0);
         ele   sample = new ele(p, 0);
         //sample.se
         sample.set_st(group_state - 1);
         sample.change_delay(delay_);
         sample.change_duration(bomb_);
         sample.change_group_id(group_);
         foreach (ele cir in ele_list)
         {
             cir.synchronize_ele(sample);
             cir.change_group_id(sample.group_id);
         }
         this.group_panel.Visibility       = Visibility.Collapsed;
         this.group_state                  = 0;
         this.plain_state_icon.Foreground  = new SolidColorBrush(Colors.Green);
         this.bomb_state_icon.Foreground   = new SolidColorBrush(Colors.Green);
         this.rocket_state_icon.Foreground = new SolidColorBrush(Colors.Green);
         this.ele_list.Clear();
     }
 }
Пример #2
0
        // you need to take care of index when you sort by frequency. in tie with frequency, element comes first whose index is first

        //sort by value
        //count the frequency
        //sort by frequency

        public int[] sortbyFreq(int[] array)
        {
            Dictionary <int, ele> num_freqDict = new Dictionary <int, ele>();

            for (int i = 0; i < array.Length; i++)
            {
                if (num_freqDict.ContainsKey(array[i]))
                {
                    num_freqDict[array[i]].frequency++;
                }
                else
                {
                    num_freqDict.Add(array[i], new ele {
                        val = array[i], index = i, frequency = 1
                    });
                }
            }

            ele[] elements = new ele[num_freqDict.Count];
            int   count    = 0;

            foreach (var kp in num_freqDict)
            {
                elements[count] = kp.Value;
                count++;
            }

            ele[] res = FunSortElementsByFreq(elements, 0, elements.Length - 1);

            return(res.Select(e => e.val).ToArray());
        }
Пример #3
0
 private void show_prop(object sender, MouseEventArgs e)
 {
     if (this.allow_show_property)
     {
         ele c = (ele)sender;
         curele_in_panel = (ele)sender;
         access_panel(c);
     }
 }
Пример #4
0
        private ele[] Merge(ele[] left, ele[] right)
        {
            ele[] res = new ele[left.Length + right.Length];

            int i = 0, j = 0, k = 0;

            while (i < left.Length && j < right.Length)
            {
                if (left[i].frequency == right[j].frequency)
                {
                    if (left[i].index < right[i].index)
                    {
                        res[k] = left[i];
                        k++;
                        i++;
                    }
                    else
                    {
                        res[k] = right[j];
                        k++;
                        j++;
                    }
                }
                else if (left[i].frequency < right[j].frequency)
                {
                    res[k] = left[i];
                    k++;
                    i++;
                }
                else
                {
                    res[k] = right[j];
                    k++;
                    j++;
                }
            }

            while (i < left.Length)
            {
                res[k] = left[i];
                i++;
                k++;
            }

            while (j < right.Length)
            {
                res[k] = right[j];
                j++;
                k++;
            }

            return(res);
        }
Пример #5
0
 public void access_panel(ele cir)
 {
     this.delay_time.Text           = cir.delay.ToString();
     this.group_id.Text             = cir.group_id.ToString();
     this.xlabel.Text               = cir.x_label.ToString();
     this.ylabel.Text               = cir.y_label.ToString();
     this.bomb_state.IsChecked      = cir.state > 0 ? true : false;
     this.bomb_duration.Text        = cir.duration.ToString();
     this.property_panel.Visibility = Visibility.Visible;
     this.index_in_panel.Text       = cir.index_label.Text;
     ut.P_index           = "3";
     this.curele_in_panel = cir;
 }
Пример #6
0
        private void _refresh(object sender, RoutedEventArgs e)
        {
            foreach (var c in LogicalTreeHelper.GetChildren(this.ShapeCanvas))
            {
                if (c is ele)
                {
                    //this.test_label.Text = "refresh";
                    ele circle_ = c as ele;
                    circle_.refresh();

                    Canvas.SetLeft(circle_, circle_.cache_point.X);
                    Canvas.SetTop(circle_, circle_.cache_point.Y);
                }
            }
        }
Пример #7
0
 private void recountdown(object sender, RoutedEventArgs e)
 {
     this.cd               = 0;
     this.countd           = start_time;
     this.timer_label.Text = string.Format("{0:D2}:{1:D2}", countd / 60, countd % 60);
     this.timer.Stop();
     foreach (var c in LogicalTreeHelper.GetChildren(this.ShapeCanvas))
     {
         if (c is ele)
         {
             ele circle_ = c as ele;
             circle_.change_color(Colors.Black);
         }
     }
     reset_count_down();
 }
Пример #8
0
 private void show_prop_prior(object sender, MouseEventArgs e)
 {
     if (this.allow_show_property)
     {
         ele c = (ele)sender;
         curele_in_panel = (ele)sender;
         access_panel(c);
         c.border.Stroke          = new SolidColorBrush(Colors.GhostWhite);
         this.allow_show_property = false;
     }
     else
     {
         ele c = (ele)sender;
         this.allow_show_property = true;
         c.border.Stroke          = new SolidColorBrush(Colors.Transparent);
     }
 }
Пример #9
0
 private void ele_copes(object sender, MouseButtonEventArgs e)
 {
     if (cty.Bomb_s)
     {
         ele c = (ele)sender;
         c.set_bam_s();
         show_prop(sender, e);
     }
     else if (cty.Bomb_a)
     {
         ele c = (ele)sender;
         c.set_bam_a();
         show_prop(sender, e);
     }
     else if (cty.Move)
     {
         isDragging = true;
         ele c = (ele)sender;
         c.CaptureMouse();
         show_prop(sender, e);
     }
 }
Пример #10
0
        private void create_hole(MouseButtonEventArgs e)
        {
            Point p = Mouse.GetPosition(this.ShapeCanvas);

            this.holes_num++;
            this.holes_index++;
            ele c = new ele(p, holes_index)
            {
                Width = 40, Height = 40
            };

            c.MouseLeftButtonDown  += new MouseButtonEventHandler(ele_copes);
            c.MouseLeftButtonUp    += new MouseButtonEventHandler(ele_copes_ad);
            c.MouseMove            += new MouseEventHandler(ele_move);
            c.MouseLeave           += new MouseEventHandler(ele_border_hide);
            c.MouseEnter           += new MouseEventHandler(ele_border_show);
            c.MouseEnter           += new MouseEventHandler(show_prop);
            c.MouseRightButtonDown += new MouseButtonEventHandler(show_prop_prior);
            ShapeCanvas.Children.Add(c);
            Canvas.SetLeft(c, e.GetPosition(this.ShapeCanvas).X - 20);
            Canvas.SetTop(c, e.GetPosition(this.ShapeCanvas).Y - 20);
            Canvas.SetZIndex(c, 5);
        }
Пример #11
0
        private void rect_up(object sender, MouseButtonEventArgs e)
        {
            if (cty.Gp || cty.Gm || cty.Gx)
            {
                //this.allow_show_property = false;
                //if (cty.Gp) selection = this.selection_p;
                //if (cty.Gm) selection = this.selection_m;
                //if (cty.Gx) selection = this.selection_x;
                // Release the mouse capture and stop tracking it.
                mouseDown = false;

                // Hide the drag selection box.
                selection.Visibility = Visibility.Collapsed;

                Point mouseUpPos = e.GetPosition(this.ShapeCanvas);
                //this.test_label.Text = mouseDownPos.X + "  down  " + mouseDownPos.Y + "  " + mouseUpPos.X + "  " + mouseUpPos.Y;
                if (cty.Gp)
                {
                    List <ele> templist = new List <ele>();
                    foreach (var c in LogicalTreeHelper.GetChildren(this.ShapeCanvas))
                    {
                        if (c is ele)
                        {
                            ele   cir    = c as ele;
                            Point center = new Point(cir.x_label, cir.y_label);
                            if (is_in_rect(mouseDownPos, mouseUpPos, center))
                            {
                                cir.group_signed();
                                templist.Add(cir);
                            }
                        }
                    }
                    ele_list = ele_list.Union(templist).ToList <ele>();
                }
                else if (cty.Gm)
                {
                    List <ele> templist = new List <ele>();
                    foreach (var c in LogicalTreeHelper.GetChildren(this.ShapeCanvas))
                    {
                        if (c is ele)
                        {
                            ele   cir    = c as ele;
                            Point center = new Point(cir.x_label, cir.y_label);
                            if (is_in_rect(mouseDownPos, mouseUpPos, center))
                            {
                                cir.not_grouped();
                                templist.Add(cir);
                            }
                        }
                    }
                    ele_list = ele_list.Except(templist).ToList <ele>();
                }
                else
                {
                    List <ele> templist = new List <ele>();
                    foreach (var c in LogicalTreeHelper.GetChildren(this.ShapeCanvas))
                    {
                        if (c is ele)
                        {
                            ele   cir    = c as ele;
                            Point center = new Point(cir.x_label, cir.y_label);
                            if (!is_in_rect(mouseDownPos, mouseUpPos, center))
                            {
                                cir.not_grouped();
                                templist.Add(cir);
                            }
                        }
                    }
                    ele_list = ele_list.Except(templist).ToList <ele>();
                }
                //this.test_label.Text = ele_list.Count.ToString();
                // TODO:
                //
                // The mouse has been released, check to see if any of the items
                // in the other canvas are contained within mouseDownPos and
                // mouseUpPos, for any that are, select them!
                //
                this.group_panel.Visibility = Visibility.Visible;
                this.ele_sum.Text           = ele_list.Count().ToString();
            }
        }
Пример #12
0
        private void timer_Tick(object sender, EventArgs e)
        {
            this.cd++;
            this.countd--;
            if (countd > 0)
            {
                this.timer_label.Text = string.Format("{0:D2}:{1:D2}", countd / 60, countd % 60);
            }
            else
            {
                this.timer_label.Text = "开始爆破";
            }
            int temp_cutd = cd - this.start_time;

            if (temp_cutd == 0)
            {
                foreach (var c in LogicalTreeHelper.GetChildren(this.ShapeCanvas))
                {
                    if (c is ele)
                    {
                        ele circle_ = c as ele;
                        if (circle_.state > 0)
                        {
                            (c as ele).change_color(Colors.Yellow);
                        }
                    }
                }
            }

            else if (temp_cutd > 0)
            {
                foreach (var c in LogicalTreeHelper.GetChildren(this.ShapeCanvas))
                {
                    if (c is ele)
                    {
                        ele circle_ = c as ele;
                        if (temp_cutd - circle_.delay == 0)
                        {
                            if (circle_.state > 0)
                            {
                                circle_.change_color(Colors.Red);
                            }
                        }
                        if (temp_cutd - circle_.delay - circle_.duration == 0)
                        {
                            //对于当起爆时间小于默认的例子,会出现不归零情况,bug
                            remains++;
                            if (circle_.state > 0)
                            {
                                circle_.change_color(Colors.Black);
                            }
                        }
                        //(c as ele).change_color(Colors.Yellow);
                    }
                }
                if (remains == this.holes_num)
                {
                    ut.Kind_type = "Play";
                    //this.test_label.Text = "chnaged";
                    this.timer.Stop();
                    this.cd               = 0;
                    this.countd           = this.start_time;
                    this.remains          = 0;
                    this.timer_label.Text = "爆破完毕";
                    foreach (var c in LogicalTreeHelper.GetChildren(this.ShapeCanvas))
                    {
                        if (c is ele)
                        {
                            ele circle_ = c as ele;
                            circle_.origined();
                        }
                    }
                }
            }
        }