• 大小: 5KB
    文件类型: .cs
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: C#
  • 标签: C#  迷宫代码  

资源简介

C# 迷宫代码,有兴趣可以参考一下,C# 迷宫代码,有兴趣可以参考一下

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;

namespace jiaoxue.Three
{
    class FindRoad
    {
        enum posision { NoneTopLeftDownRight};
        struct House
        {
            public bool Ispass;
            public posision NowPos;
            public void SetValue()
            {
                Ispass = true;
                NowPos = posision.None;
            }
        }
        struct SaveLoad
        {
            public int x;
            public int y;
            public posision NowPos;
        }
        static SaveLoad[] saveload=new SaveLoad[78];
        static House[] housees = new House[13 9];
        static int Num = 0;
        static int xmax = 12;
        static int ymax = 7;
        static void Main2()
        {
            CreatHouse();
            if (GetLoad(0 0))
            {
                for (int i = 0; i <= Num; i++)
                    Console.WriteLine(“x={0} y={1} pos={2}“saveload[i].x
                        saveload[i].ysaveload[i].NowPos);
            }
            else
                Console.WriteLine(“找不到路径“);
            Console.Read();
        }

        public static bool GetLoad(int x int y)
        {
            saveload[Num].x = x;
            saveload[Num].y = y;
            if (x == xmax && y == 0)
            {
                Console.WriteLine(“*****************“ + Num);
                for (int i = 0; i <= Num; i++)
                    Console.WriteLine(“x={0} y={1} pos={2}“ saveload[i].x
                        saveload[i].y saveload[i].NowPos);
                Num--;
                return false;
                //return true;
            }
            if(y+1<=ymax) //向上
                if (housees[x y + 1].Ispass && housees[x y + 1].NowPos == posision.None)
                {
                    housees[x y].NowPos = posision.Top;
                    saveload[Num].NowPos = posision.Top;
                    Num++;
                    if (GetLoad(x y + 1))
                        return true;
                }
            if (x + 1 <=xmax) //向右
                if (housees[x + 1 y].Ispass && housees[x + 1 y].NowPos == posision.None)
                {
                    housees[x y].NowPos = posision.Right;
                    saveload[Num].NowPos = posision.Right;
                    Num++;
                    if (GetLoad(x + 1 y))
                        return true;
                }
            if (y - 1 > -1) //向下
                if (housees[x y - 1].Ispass && housees[x y - 1].NowPos == posision.None)
                {
                    housees[x y].NowPos = posision.Down;
                    saveload[N

评论

共有 条评论