走迷宫C#版(一)

本文介绍了一个使用C#编写的CMaze类,该类包含了迷宫的构造、绘图、路径搜索等功能。CMaze类通过Stack存储路径,采用深度优先搜索策略探索迷宫,并提供Run方法来自动解决迷宫。此外,还提供了Reset方法以重新开始迷宫,以及ToString方法用于输出字符形式的迷宫地图。
摘要由CSDN通过智能技术生成

//迷宫类相关

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;

namespace MazeDemo
{
 /// <summary>
 /// 迷宫类
 /// </summary>
 public class CMaze
 {
  bool[,] mg;  //地图格子
  Stack stack; //堆栈
  Point in_p;  //入口点
  Point out_p; //出口点
  Point start_p; //绘制迷时候的起始点
  Size boxsize; //每个格子的大小
  int step_count; //共走多少步

  public CMaze()
  {
   stack=new Stack();
   this.start_p=new Point(0,0);
   this.boxsize=new Size(50,50);
   step_count=0;
  }

  public CMaze(bool[,] _mg):this()
  {
   this.mg=_mg;
  }

  public CMaze(bool[,] _mg,Point _in,Point _out):this()
  {
   this.mg=_mg;
   this.in_p=_in;
   this.out_p=_out;
   Stack way=this.Test(this.in_p,_in);
   stack.Push(new CCoor(this.in_p,way));
   this.step_count++;
  }


  /// <summary>
  /// 绘制迷宫时窗口的起始坐标
  /// </summary>
  public Point StartPoint
  {
   set{this.start_p=value;}
   get{return this.start_p;}
  }

  /// <summary>
  /// 当前迷宫共走多少步
  /// </summary>
  public int StepCount
  {
   get{return this.step_count;}
  }

  /// <summary>
  /// 迷宫格子大小
  /// </summary>
  public Size BoxSize
  {
   set{this.boxsize=value;}
   get{return this.boxsize;}
  }

  /// <summary>
  /// 堆栈数据个数
  /

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值