Example #1
0
        // Create a DrawingVisual that contains a rectangle.
//        MyVisualHost mvh = new MyVisualHost();

        protected override void OnInitialized(EventArgs e)
        {
            //base.OnInitialized(e);
            Arena.instance = this;

            NACellColor[0] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 0f, 1f);
            NACellColor[1] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 1f, 0f);
            NACellColor[2] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 1f, 1f);
            NACellColor[3] = System.Windows.Media.Color.FromScRgb(.1f, 1f, 0f, 0f);
            // NACellColor[4] = System.Windows.Media.Color.FromScRgb(1f, 1f, 0f, 1f);
            //  NACellColor[5] = System.Windows.Media.Color.FromScRgb(1f, 1f, 1f, 0f);
            //  NACellColor[6] = System.Windows.Media.Color.FromScRgb(1f, 1f, 1f, 1f);


            //          mvh.IsHitTestVisible = false;
            //        mvh.SetValue(Canvas.ZIndexProperty, 99);
            //      mvh.SetValue(System.Windows.Media.RenderOptions.EdgeModeProperty, System.Windows.Media.EdgeMode.Aliased);
            //    this.Children.Add(mvh);

            //this

            this.Loaded += new RoutedEventHandler(Arena_Loaded);



            //Debug.Content = Arena.instance.Children[0].GetType().ToString();
            bool AltRowToggle = false;
            bool AltColToggle = false;
            int  xx           = 0;
            int  yy           = 0;

            NACells[0] = new List <EmptyCell>();
            NACells[1] = new List <EmptyCell>();
            NACells[2] = new List <EmptyCell>();
            NACells[3] = new List <EmptyCell>();

            for (double y = -36.6; y < 707; y += 36.6)
            {
                yy          += 1;
                xx           = 0;
                AltRowToggle = !AltRowToggle;
                for (double x = -43.3; x < 930.95; x += 43.3)
                {
                    AltColToggle = !AltColToggle;
                    double mx = x;
                    if (!AltRowToggle)
                    {
                        mx += 21.65;
                    }
                    xx += 1;

                    //UIElement b;
                    EmptyCell b = new EmptyCell();

                    int qq = 0;
                    if (AltColToggle)
                    {
                        qq += 1;
                    }
                    if (AltRowToggle)
                    {
                        qq += 2;
                    }

                    b.Body.Fill = new System.Windows.Media.SolidColorBrush(NACellColor[qq]);
                    NACells[qq].Add(b);

                    b.CenterPoint = new Point(mx + 21.65, y + 25);
                    //Height="50" Width="43.3"

                    if (mx < 0 || mx >= 866 || y < 0 || y >= 707 - 36.6)//- 43.3
                    {
                        b.Occupant = new Block();
                        b.Occupied = true;
                    }
                    else
                    {
                        // b = new EmptyCell();
                        Cells.Add(new Point(xx, yy), b as EmptyCell);
                        Arena.instance.PathInvaliation.Enqueue(b);
                    }



                    b.SetValue(Canvas.TopProperty, y);
                    b.SetValue(Canvas.LeftProperty, mx);
                    Arena.instance.Children.Add(b);
                    if (b.Occupant as UIElement != null)
                    {
                        UIElement bo = b.Occupant as UIElement;
                        bo.SetValue(Canvas.TopProperty, y);
                        bo.SetValue(Canvas.LeftProperty, mx);

                        Arena.instance.Children.Add(b.Occupant as UIElement);
                    }
                    PathInvaliation.Enqueue(b);
                }
            }



            foreach (Point P in Cells.Keys)
            {
                //if (Cells[P].Occupied == false)
                {
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y)]);
                    }
                    catch
                    { }

                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y)]);
                    }
                    catch
                    { }
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X, P.Y - 1)]);
                    }
                    catch
                    { }
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X, P.Y + 1)]);
                    }
                    catch
                    { }

                    if ((P.Y / 2) == Math.Floor(P.Y / 2))
                    {
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y - 1)]);
                        }
                        catch
                        { }
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y + 1)]);
                        }
                        catch
                        { }
                    }
                    else
                    {
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y - 1)]);
                        }
                        catch
                        { }
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y + 1)]);
                        }
                        catch
                        { }
                    }
                }

                //Arena.instance.MouseMove += new System.Windows.Input.MouseEventHandler(instance_MouseMove);
            }


            Begin = Cells[new Point(2, 2)];
            End   = Cells[new Point(21, 20)];


            CreepSpawn c = new CreepSpawn();// Tower((TowerType)Enum.Parse(TT.GetType(), Towers.SelectedItem.ToString()));

            TheSpawner = c;
            c.SetValue(Canvas.TopProperty, End.GetValue(Canvas.TopProperty));
            c.SetValue(Canvas.LeftProperty, End.GetValue(Canvas.LeftProperty));

            Begin.Occupant = c as IArenaObject;
            //c.Opacity = .5;
            Arena.instance.Children.Add(c);

            CreepTarget d = new CreepTarget();// Tower((TowerType)Enum.Parse(TT.GetType(), Towers.SelectedItem.ToString()));

            d.SetValue(Canvas.TopProperty, Begin.GetValue(Canvas.TopProperty));
            d.SetValue(Canvas.LeftProperty, Begin.GetValue(Canvas.LeftProperty));

            End.Occupant = d as IArenaObject;
            //d.Opacity = .5;
            Arena.instance.Children.Add(d);

            /*
             * System.Windows.Shapes.Line L = new System.Windows.Shapes.Line();
             * L.X1 = 0;
             * L.Y1 = 0;
             *
             * L.X2 = Begin.TranslatePoint(new Point(.5, .5), Arena.instance).X;
             * L.Y2 = 500;
             *
             * L.Stroke = System.Windows.Media.Brushes.Salmon;
             * L.StrokeThickness = 5;
             * L.Fill = System.Windows.Media.Brushes.PowderBlue;
             * L.Opacity = 1;
             *
             * Arena.instance.Children.Add(L);
             */


            Arena.instance.MouseLeave += new System.Windows.Input.MouseEventHandler(instance_MouseLeave);
            Arena.instance.MouseDown  += new System.Windows.Input.MouseButtonEventHandler(instance_MouseDown);

            Arena.instance.FindPathCells(Begin, End);

            // this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(Hooks_DispatcherInactive);

            //System.Windows.Media.CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);

            DT = new System.Windows.Threading.DispatcherTimer(System.Windows.Threading.DispatcherPriority.Background);



            DT.Tick += new EventHandler(DT_Tick);

            DT.Interval = TimeSpan.FromSeconds(.01);
            DT.Start();
        }
Example #2
0
        // Create a DrawingVisual that contains a rectangle.
//        MyVisualHost mvh = new MyVisualHost();
        
        protected override void OnInitialized(EventArgs e)
        {
            //base.OnInitialized(e);
            Arena.instance = this;

            NACellColor[0] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 0f, 1f);
            NACellColor[1] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 1f, 0f);
            NACellColor[2] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 1f, 1f);
            NACellColor[3] = System.Windows.Media.Color.FromScRgb(.1f, 1f, 0f, 0f);
           // NACellColor[4] = System.Windows.Media.Color.FromScRgb(1f, 1f, 0f, 1f);
          //  NACellColor[5] = System.Windows.Media.Color.FromScRgb(1f, 1f, 1f, 0f);
          //  NACellColor[6] = System.Windows.Media.Color.FromScRgb(1f, 1f, 1f, 1f);

            
  //          mvh.IsHitTestVisible = false;
    //        mvh.SetValue(Canvas.ZIndexProperty, 99);
      //      mvh.SetValue(System.Windows.Media.RenderOptions.EdgeModeProperty, System.Windows.Media.EdgeMode.Aliased);
        //    this.Children.Add(mvh);

            //this

            this.Loaded += new RoutedEventHandler(Arena_Loaded);

       


            //Debug.Content = Arena.instance.Children[0].GetType().ToString();
            bool AltRowToggle = false;
            bool AltColToggle = false;
            int xx = 0;
            int yy = 0;

            NACells[0] = new List<EmptyCell>();
            NACells[1] = new List<EmptyCell>();
            NACells[2] = new List<EmptyCell>();
            NACells[3] = new List<EmptyCell>();

            for (double y = -36.6; y < 707; y += 36.6)
            {
                yy += 1;
                xx = 0;
                AltRowToggle = !AltRowToggle;
                for (double x = -43.3; x < 930.95; x += 43.3)
                {
                    AltColToggle = !AltColToggle;
                    double mx = x;
                    if (!AltRowToggle)
                    {
                        mx += 21.65;
                    }
                    xx += 1;

                    //UIElement b;
                    EmptyCell b = new EmptyCell();

                    int qq = 0;
                    if (AltColToggle) qq += 1;
                    if (AltRowToggle) qq += 2;
                    
                    b.Body.Fill = new System.Windows.Media.SolidColorBrush(NACellColor[qq]);
                    NACells[qq].Add(b);
                    
                    b.CenterPoint = new Point(mx+21.65,y+25);
                    //Height="50" Width="43.3"

                    if (mx < 0 || mx >= 866 || y < 0 || y >= 707 - 36.6)//- 43.3 
                    {
                        b.Occupant = new Block();
                        b.Occupied = true;
                    }
                    else
                    {
                        // b = new EmptyCell();
                        Cells.Add(new Point(xx, yy), b as EmptyCell);
                        Arena.instance.PathInvaliation.Enqueue(b);
                    }



                    b.SetValue(Canvas.TopProperty, y);
                    b.SetValue(Canvas.LeftProperty, mx);
                    Arena.instance.Children.Add(b);
                    if (b.Occupant as UIElement != null)
                    {
                        UIElement bo = b.Occupant as UIElement;
                        bo.SetValue(Canvas.TopProperty, y);
                        bo.SetValue(Canvas.LeftProperty, mx);

                        Arena.instance.Children.Add(b.Occupant as UIElement);
                    }
                    PathInvaliation.Enqueue(b);
                }


            }



            foreach (Point P in Cells.Keys)
            {
                //if (Cells[P].Occupied == false)
                {
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y)]);
                    }
                    catch
                    { }

                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y)]);
                    }
                    catch
                    { }
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X, P.Y - 1)]);
                    }
                    catch
                    { }
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X, P.Y + 1)]);
                    }
                    catch
                    { }

                    if ((P.Y / 2) == Math.Floor(P.Y / 2))
                    {
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y - 1)]);
                        }
                        catch
                        { }
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y + 1)]);
                        }
                        catch
                        { }

                    }
                    else
                    {
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y - 1)]);
                        }
                        catch
                        { }
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y + 1)]);
                        }
                        catch
                        { }

                    }
                }

                //Arena.instance.MouseMove += new System.Windows.Input.MouseEventHandler(instance_MouseMove);

                
            }


            Begin = Cells[new Point(2, 2)];
            End = Cells[new Point(21, 20)];


            CreepSpawn c = new CreepSpawn();// Tower((TowerType)Enum.Parse(TT.GetType(), Towers.SelectedItem.ToString()));

            TheSpawner = c;
            c.SetValue(Canvas.TopProperty, End.GetValue(Canvas.TopProperty));
            c.SetValue(Canvas.LeftProperty, End.GetValue(Canvas.LeftProperty));

            Begin.Occupant = c as IArenaObject;
            //c.Opacity = .5;
            Arena.instance.Children.Add(c);

            CreepTarget d = new CreepTarget();// Tower((TowerType)Enum.Parse(TT.GetType(), Towers.SelectedItem.ToString()));

            d.SetValue(Canvas.TopProperty, Begin.GetValue(Canvas.TopProperty));
            d.SetValue(Canvas.LeftProperty, Begin.GetValue(Canvas.LeftProperty));

            End.Occupant = d as IArenaObject;
            //d.Opacity = .5;
            Arena.instance.Children.Add(d);

            /*
            System.Windows.Shapes.Line L = new System.Windows.Shapes.Line();
            L.X1 = 0;
            L.Y1 = 0;

            L.X2 = Begin.TranslatePoint(new Point(.5, .5), Arena.instance).X;
            L.Y2 = 500;

            L.Stroke = System.Windows.Media.Brushes.Salmon;
            L.StrokeThickness = 5;
            L.Fill = System.Windows.Media.Brushes.PowderBlue;
            L.Opacity = 1;

            Arena.instance.Children.Add(L);
            */


            Arena.instance.MouseLeave += new System.Windows.Input.MouseEventHandler(instance_MouseLeave);
            Arena.instance.MouseDown += new System.Windows.Input.MouseButtonEventHandler(instance_MouseDown);

            Arena.instance.FindPathCells(Begin, End);

           // this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(Hooks_DispatcherInactive);

            //System.Windows.Media.CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);

            DT = new System.Windows.Threading.DispatcherTimer(System.Windows.Threading.DispatcherPriority.Background);

            


            DT.Tick += new EventHandler(DT_Tick);
            
            DT.Interval = TimeSpan.FromSeconds(.01);
            DT.Start();
            

        }