Exemple #1
0
 private void 初始化地图()
 {
     this.是否铺完铁轨 = false;
     this.大地.Children.Clear();
     this.地块列队   = new List <地块>(this.地块数量);
     this.已铺地块列队 = new List <地块>(this.地块数量);
     for (int i = 0; i < this.地块数量; i++)
     {
         var 地块对象 = new 地块(new Point(i % 7, i / 7), 类型.无)
         {
             //Name = $"N_{i % 7}_{i / 7}",
             Width     = this.地块尺寸,
             Height    = this.地块尺寸,
             Margin    = new Thickness((i % 7) * this.地块尺寸, (i / 7) * this.地块尺寸, 0, 0),
             IsEnabled = false
         };
         地块对象.Click += 铺设铁轨;
         this.地块列队.Add(地块对象);
         this.大地.Children.Add(地块对象);
     }
     this.关键地块                 = new Rectangle();
     this.关键地块.Margin          = new Thickness(this.关键坐标.X * this.地块尺寸, this.关键坐标.Y * this.地块尺寸, 0, 0);
     this.关键地块.Stroke          = Brushes.CornflowerBlue;
     this.关键地块.RadiusX         = this.关键地块.RadiusY = 5;
     this.关键地块.StrokeThickness = 4;
     this.关键地块.Width           = this.关键地块.Height = this.地块尺寸;
     this.大地.Children.Add(this.关键地块);
 }
Exemple #2
0
        private Path 画节点路径(地块 当前地块)
        {
            var result = default(Path);

            if (当前地块.路线 != null)
            {
                var 节点起点坐标 = new Point((当前地块.坐标.X + 当前地块.路线.起点坐标.X) * 当前地块.Width, (当前地块.坐标.Y + 当前地块.路线.起点坐标.Y) * 当前地块.Height);

                var 节点终点坐标 = new Point((当前地块.坐标.X + 当前地块.路线.终点坐标.X) * 当前地块.Width, (当前地块.坐标.Y + 当前地块.路线.终点坐标.Y) * 当前地块.Height);

                if (当前地块.路线.起点方向 == 方向.右 && 当前地块.路线.终点方向 == 方向.||
                    当前地块.路线.起点方向 == 方向.&& 当前地块.路线.终点方向 == 方向.右 ||
                    当前地块.路线.起点方向 == 方向.左 && 当前地块.路线.终点方向 == 方向.||
                    当前地块.路线.起点方向 == 方向.&& 当前地块.路线.终点方向 == 方向.左)
                {
                    result = this.计算路径(节点起点坐标, 节点终点坐标, SweepDirection.Clockwise);                     //new ArcSegment(节点坐标, new Size(当前地块.Width / 2, 当前地块.Height / 2), 90, false, SweepDirection.Clockwise, true);
                }
                else if (当前地块.路线.起点方向 == 方向.左 && 当前地块.路线.终点方向 == 方向.||
                         当前地块.路线.起点方向 == 方向.&& 当前地块.路线.终点方向 == 方向.左 ||
                         当前地块.路线.起点方向 == 方向.右 && 当前地块.路线.终点方向 == 方向.||
                         当前地块.路线.起点方向 == 方向.&& 当前地块.路线.终点方向 == 方向.右)
                {
                    result = this.计算路径(节点起点坐标, 节点终点坐标, SweepDirection.Counterclockwise);
                }
                else
                {
                    result = this.计算路径(节点起点坐标, 节点终点坐标);
                }
            }
            return(result);
        }
Exemple #3
0
        private void 铺设铁轨(object sender, RoutedEventArgs e)
        {
            // 由于重新设置地块 所以前一次计算的“下一地块”需要重置
            if (this.一地块缓存 != null)
            {
                this.一地块缓存.IsEnabled = false;
            }

            // 得到当前设置的地块对象
            地块 当前铺设的地块 = (地块)sender;

            // 点击的地块不是老地方的话也就是说往下个地块点击
            if (this.已铺地块列队.FirstOrDefault(o => o == 当前铺设的地块) == null)
            {
                this.已铺地块列队.Add(当前铺设的地块);
                this.已铺地块列队[this.已铺地块列队.Count - 2].IsEnabled = false;
            }
            else
            {
                if (当前铺设的地块.路线 != null)
                {
                    this.路径集合.RemoveAt(this.路径集合.Count - 1);
                    this.大地.Children.RemoveAt(this.大地.Children.Count - 1);
                }
            }

            // 需要上一段铁轨的信息 来确定当前铁轨的路径
            当前铺设的地块.随机变化地块(this.已铺地块列队[this.已铺地块列队.Count - 2]);

            地块 一地块 = this.获取下一地块(当前铺设的地块);

            this.一地块缓存 = 一地块;

            if (一地块 != null)
            {
                if (一地块.类型 != 类型.终点)
                {
                    一地块.IsEnabled = true;                                   //this.Title = "成功";
                }
                else
                {
                    if (当前铺设的地块.路线.终点方向 == 一地块.路线.接点方向)
                    {
                        当前铺设的地块.IsEnabled = false;
                        this.是否铺完铁轨       = true;
                    }
                }
            }

            var 当前路径 = this.画节点路径(当前铺设的地块);

            if (当前路径 != null)
            {
                this.路径集合.Add(当前路径);
                this.大地.Children.Add(当前路径);
            }
        }
Exemple #4
0
        private 地块 获取下一地块(地块 当前地块)
        {
            var 一地块 = default(地块);

            if (当前地块.类型 != 类型.空 && 当前地块.路线 != null)
            {
                var X坐标 = 当前地块.坐标.X;
                var Y坐标 = 当前地块.坐标.Y;
                switch (当前地块.路线.终点方向)
                {
                case 方向.左: { if (当前地块.坐标.X > 0)
                             {
                                 X坐标 = 当前地块.坐标.X - 1;
                             }
                             break; }

                case 方向.右: { if (当前地块.坐标.X < 6)
                             {
                                 X坐标 = 当前地块.坐标.X + 1;
                             }
                             break; }

                case 方向.: { if (当前地块.坐标.Y > 0)
                            {
                                Y坐标 = 当前地块.坐标.Y - 1;
                            }
                            break; }

                case 方向.: { if (当前地块.坐标.Y < 4)
                            {
                                Y坐标 = 当前地块.坐标.Y + 1;
                            }
                            break; }
                }
                var 一地块坐标 = new Point(X坐标, Y坐标);
                if (一地块坐标 != 当前地块.坐标)
                {
                    if (this.已铺地块列队.FirstOrDefault(o => o.坐标 == 一地块坐标) == null)
                    {
                        一地块 = this.地块列队.FirstOrDefault(o => o.坐标 == 一地块坐标);
                    }
                    else if (一地块坐标 == this.终点坐标)
                    {
                        一地块 = this.已铺地块列队.FirstOrDefault(o => o.坐标 == this.终点坐标);
                    }
                }
            }
            //if (下一地块 != null) 下一地块.IsEnabled = true;
            当前地块.IsEnabled = true;
            return(一地块);
        }
Exemple #5
0
        public void 随机变化地块(地块 一地块)
        {
            var 随机对象  = new Random();
            var 当前随机数 = 随机对象.Next(1, 8);

            while (当前随机数 == this.前一次随机数)
            {
                当前随机数 = 随机对象.Next(1, 8);
            }
            this.设置地块((类型)当前随机数);
            this.前一次随机数 = 当前随机数;

            // 路线有两条 根据上一个路线的终点来确定本次路线
            this.路线 = this.路线集.FirstOrDefault(o => o.起点方向 == 一地块.路线.接点方向);
        }