public Form1() { InitializeComponent(); var materialSkinManager = MaterialSkinManager.Instance;//设置主题颜色 materialSkinManager.AddFormToManage(this); materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT; materialSkinManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey300, Accent.DeepOrange100, TextShade.WHITE); refreshTimer.Enabled = false; myDraw = new Draw(labyPicture); myDraw.DrawLaby(); CurrentLaby = new Laby(myDraw.Laby); MethodNum = 0; CurrentMethod = 0; CurrentLine = 0; materialTab.SelectedTab = setPage;//将游戏设置设为起始页 initLabels(); initTable(); IsChosen = new bool[6] { false, false, false, false, false, false }; //初始时默认所有方法均未选定 }
public void Change(Laby laby) { if (laby.Width == widthNum && laby.Height == heightNum) { Laby.SetStartPoint(laby.GetStart().CellCor); Laby.SetEndPoint(laby.GetEnd().CellCor); for (int x = 0; x < laby.Width; x++) { for (int y = 0; y < laby.Height; y++) { Laby.SetCell(x, y, laby.GetCell(x, y)); } } } else { widthNum = laby.Width; heightNum = laby.Height; Laby = new Laby(laby); Laby = new Laby(widthNum, heightNum); Laby.SetStartPoint(laby.GetStart().CellCor); Laby.SetEndPoint(laby.GetEnd().CellCor); for (int x = 0; x < laby.Width; x++) { for (int y = 0; y < laby.Height; y++) { Laby.SetCell(x, y, laby.GetCell(x, y)); } } } }
public BreadthFirst(Laby laby) { Laby = laby; Closed = new List <Node>(); StartPoint = Laby.GetStart().CellCor; EndPoint = Laby.GetEnd().CellCor; Path = new List <Cor>(); Number = 1; Operations = 0; NodeQueue = new ConcurrentQueue <Node>(); NodeQueue.Enqueue(new Node(Number, 0, StartPoint, 0, 0)); Operations++; Number++; Closed.Clear(); Path.Clear(); }
public BestFirst(Laby laby) { Laby = laby; Closed = new List <Node>(); Open = new List <Node>(); StartPoint = Laby.GetStart().CellCor; EndPoint = Laby.GetEnd().CellCor; Path = new List <Cor>(); Number = 1; Operations = 0; Open.Add(new Node(Number, 0, StartPoint, 0, GetManhatten(StartPoint, EndPoint))); Operations++; Number++; Closed.Clear(); Path.Clear(); }
public DepthFirst(Laby laby) { Laby = laby; Closed = new List <Node>(); StartPoint = Laby.GetStart().CellCor; EndPoint = Laby.GetEnd().CellCor; Path = new List <Cor>(); Number = 1; Operations = 0; NodeStack = new Stack <Node>(); NodeStack.Push(new Node(Number, 0, StartPoint, 0, 0)); Operations++; Number++; Closed.Clear(); Path.Clear(); }
public Laby(Laby laby)//复制构造函数 { this.Height = laby.Height; this.Width = laby.Width; myLaby = new Cell[Width, Height]; for (int x = 0; x < laby.Width; x++) { for (int y = 0; y < laby.Height; y++) { myLaby[x, y] = new Cell(laby.myLaby[x, y]); } } StartPoint = new Cor(laby.StartPoint.X, laby.StartPoint.Y); EndPoint = new Cor(laby.EndPoint.X, laby.EndPoint.Y); }
public Dijkstra(Laby laby) { Laby = laby; Closed = new List <Node>(); Open = new List <Node>(); Open.Clear(); StartPoint = Laby.GetStart().CellCor; EndPoint = Laby.GetEnd().CellCor; Path = new List <Cor>(); Number = 1; Operations = 0; Open.Add(new Node(Number, 0, StartPoint, 0, 0)); Operations++; Number++; Closed.Clear(); Path.Clear(); }
private void SaveButton_Click(object sender, EventArgs e)//更改迷宫尺寸 { int width = 0, height = 0; try { width = Convert.ToInt32(widthText.Text); height = Convert.ToInt32(heightText.Text); } catch (Exception) { MessageBox.Show("请输入大小介于5~20之间的数字."); return; } if (width < 5 || height < 5 || width > 20 || height > 20) { MessageBox.Show("建议设置迷宫宽、高均介于5~20之间.", "请重设"); return; } if (width != CurrentLaby.Width || height != CurrentLaby.Height) { var r = MessageBox.Show("确认更改迷宫尺寸?", "请确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (r == DialogResult.Cancel) { return; } CurrentLaby = new Laby(width, height); CurrentLaby.SetRandom(); myDraw.Change(CurrentLaby); myDraw.DrawLaby(); } else { return; } }
public Draw(PictureBox pictureBox) { myPic = pictureBox; Laby = new Laby(widthNum, heightNum); Laby.SetRandom(); }