首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

飞行棋map的实现

2012-12-20 
飞行棋地图的实现编写飞行棋主要把棋盘用代码写出来,而地图又要能连接起来,不能断掉,地图上要有每个关卡的

飞行棋地图的实现
编写飞行棋主要把棋盘用代码写出来,而地图又要能连接起来,不能断掉,地图上要有每个关卡的图例,也是要用代码显示出来。
/// <summary>
        /// 绘制标志
        /// </summary>
        public static void ShowUi()
        {
            Console.WriteLine("*********************************");
            Console.WriteLine("*骑    士      飞      行     棋*");
            Console.WriteLine("*********************************");
        }
        /// <summary>
        ///绘制地图
        /// </summary>
        public static void DrawMap()
        {
            Console.WriteLine("图例:幸运盘:◎   地雷:★    暂停:▲    时空隧道:卐");
            for (int i = 0; i <=29; i++)
            {
                Console.Write(GetMap(i));
            }
            Console.WriteLine();
            for (int i =30; i < 35; i++)//画这列地图要和第一列地图接起来,所要地图不能换行顶行画,要通过一次循环把前面的变成空格
            {
                for (int j = 0; j < 29; j++)
                {
                    Console.Write(" ");
                }
                Console.WriteLine(GetMap(i));
            }
            for (int i = 64; i >= 35; i--)//画这行地图要从尾画到头,所以循环式依次相减的
            {
                Console.Write(GetMap(i));
            }
            Console.WriteLine();
            for (int i = 65; i <= 69; i++)
            {
                Console.WriteLine(GetMap(i));
            }
            for (int i = 70; i <= 99; i++)
            {
                Console.Write(GetMap(i));
            }
            Console.WriteLine();
            Console.ResetColor();//将控制台的前景色和背景色设置为默认值
        }
        /// <summary>
        /// 获得第pos坐标上应该绘制的图案
        /// </summary>
        /// <param name="pos">要绘制的坐标</param>
        /// <returns></returns>
        static string GetMap(int pos)
        {
            string result = "";
            if (player[0] == pos && player[1] == pos)//判断A和B是否在当前要画的第i格上
            {
                Console.ForegroundColor = ConsoleColor.Yellow;//设置前景颜色
                result = "<>";
            }
            else if (player[0] == pos)//A在当前要画的格上
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                result = "A";
            }
            else if (player[1] == pos)//B在当前要画的格上
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                result="B";
            }
            else
            {
                switch (Map[pos])//以Map[pos]的值来选择该坐标上应该画什么图案
                {
                    case 0:
                        Console.ForegroundColor = ConsoleColor.White;
                        result="□"; break;
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Red;
                        result="◎"; break;
                    case 2:
                        Console.ForegroundColor = ConsoleColor.Green;
                        result="★"; break;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.Blue;
                        result="▲"; break;
                    case 4:
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        result="卐"; break;
                }
            }
            return result;
        }
        /// <summary>
        /// 初始化地图
        /// </summary>
        static void InitialMap()
        {
            int[] lT = {4,20,36,45,65,80,94 };//将是幸运盘的坐标要一个数组表示
            int[] lP = { 5, 13, 17, 33, 38, 50, 69 };//将是地雷的坐标要一个数组表示
            int[] pause = { 9, 29, 60, 93 };//将是暂停的坐标要一个数组表示
            int[] tT = { 18, 25, 45, 63, 72, 88, 90, 99 };//将是时空隧道的坐标要一个数组表示
            for (int i = 0; i < lT.Length; i++)
            {
                Map[lT[i]] = 1;//将是幸运盘的坐标赋值为1
            } for (int i = 0; i < lP.Length; i++)
            {
                Map[lP[i]] = 2;//将是地雷的坐标赋值为2
            }
            for (int i = 0; i < pause.Length; i++)
            {
                Map[pause[i]] = 3;//将是暂停的坐标赋值为3
            }
            for (int i = 0; i < tT.Length; i++)
            {
                Map[tT[i]] = 4;//将是时空隧道的坐标赋值为4
            }        
        }

热点排行