当前位置: 首页>>代码示例>>C#>>正文


C# IEngine.PostSetWall方法代码示例

本文整理汇总了C#中IEngine.PostSetWall方法的典型用法代码示例。如果您正苦于以下问题:C# IEngine.PostSetWall方法的具体用法?C# IEngine.PostSetWall怎么用?C# IEngine.PostSetWall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEngine的用法示例。


在下文中一共展示了IEngine.PostSetWall方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

        public void Create(IEngine engine)
        {
            if (engine == null) return;

            Engine = engine;
            Field = Engine.Field;
            Engine.PlayerSetWall += OnSetWall;
            Engine.PlayerMove += UpdatePos;
            Engine.PlayerChanged += UpdatePos;

            grid.Children.Clear();
            grid.ColumnDefinitions.Clear();
            grid.RowDefinitions.Clear();

            int n = Field.Dimension;
            int m = Field.Dimension;
            for (int j = 0; j < m - 1; ++j)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
                grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(16, GridUnitType.Pixel) });
            }
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
            for (int i = 0; i < n - 1; ++i)
            {
                grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
                grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(16, GridUnitType.Pixel) });
            }
            grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });

            for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
            {
                Rectangle r = new Rectangle() { Fill = ((i + j) % 2 == 0) ? Brushes.LightSkyBlue : Brushes.LightSlateGray, Margin = new Thickness(-8) };
                grid.Children.Add(SetSell(r, i, j));
            #if DEBUG
                grid.Children.Add(SetSell(new Label() { Content = (i * n + j).ToString() }, i, j));
            #endif
            }

            for (int i = 0; i < n - 1; ++i)
                for (int j = 0; j < m - 1; ++j)
                {
                    int i0 = i;
                    int j0 = j;
                    Rectangle r = new Rectangle() { Fill = Brushes.Black, Margin = new Thickness(-1) };
                    r.MouseLeftButtonDown += (s, e) => Engine.PostSetWall(i0, j0, WallStyle.Horizontal);
                    r.MouseRightButtonDown += (s, e) => Engine.PostSetWall(i0, j0, WallStyle.Vertical);
                    Grid.SetRow(r, 1 + 2 * i);
                    Grid.SetColumn(r, 1 + 2 * j);
                    grid.Children.Add(r);
                }

            player1 = new Ellipse() { Fill = Brushes.IndianRed, Stroke = Brushes.Black };
            grid.Children.Add(SetSell(player1, Field.Hero1.Y, Field.Hero1.X));

            player2 = new Ellipse() { Fill = Brushes.DarkBlue, Stroke = Brushes.Black };
            grid.Children.Add(SetSell(player2, Field.Hero2.Y, Field.Hero2.X));

            arrowDown = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow };
            arrowRight = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow };
            arrowLeft = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow };
            arrowUp = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow };

            arrowDown.MouseDown += (s, e) => Engine.PostMove(0, +1);
            arrowUp.MouseDown += (s, e) => Engine.PostMove(0, -1);
            arrowLeft.MouseDown += (s, e) => Engine.PostMove(-1, 0);
            arrowRight.MouseDown += (s, e) => Engine.PostMove(+1, 0);

            UpdatePos(null, null);
        }
开发者ID:Nublo,项目名称:Quoridor,代码行数:70,代码来源:WField.xaml.cs


注:本文中的IEngine.PostSetWall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。