黑马程序员-飞行棋2

 

------- Windows Phone 7手机开发、.Net培训、期待与您交流! -------

飞行棋游戏中,用到了一些方法。

方法可以理解成把一个要经常做的操作或者一段要经常写到的代码,写成方法,从而简便了代码的调用和工作效率。

飞行棋中用到了以下几个方法:

showUI方法:用来显示游戏的界面

代码如下:

class UI
    {
        /// <summary>
        /// 用于绘制程序的开始界面
        /// </summary>
        public static void showUI()
        {
            Console.WriteLine("********************************************");//输出游戏的欢迎界面
            Console.WriteLine("************骑  士  飞  行  棋**************");
            Console.WriteLine("********************************************");
        }
 public static void huitu()
        {
            for (int a = 0; a < num.Length; a++)
            {
                num[a] = 0;
            }

            int[] luckten = { 6, 23, 40, 55, 69, 83 };//幸运轮盘
            int[] landmine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷
            int[] pause = { 9, 27, 60, 93 };//暂停
            int[] timetunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道
            for (int a = 0; a < luckten.Length; a++)
            {

                num[luckten[a]] = 1;//使地图上下标为luckten内的值的元素变成幸运轮盘
            }
            for (int a = 0; a < landmine.Length; a++)
            {
                num[landmine[a]] = 2;//使地图下标为landmine的元素变成地雷
            }
            for (int a = 0; a < pause.Length; a++)
            {
                num[pause[a]] = 3;//使地图下标为pause的元素值的元素变成暂停
            }
            for (int a = 0; a < timetunnel.Length; a++)
            {
                num[timetunnel[a]] = 4;//使下标为timetunnle的变成时空隧道
            }

        }
  public static void drowmap()
        {//绘制0-29格的地图
            for (int a = 0; a <= 29; a++)
            {
                Console.Write(getmappos(a));
            }
            Console.WriteLine("");
            //绘制30-34格的地图
            for (int a = 30; a <= 34; a++)
            {
                for (int j = 0; j < 29; j++)
                {
                    Console.Write("  ");
                }
                Console.WriteLine(getmappos(a));

                //绘制35-64的地图
            }
          
            for (int a = 64; a >= 35; a--)
            {
                Console.Write(getmappos(a));
            }
            Console.WriteLine();
            for(int a=65;a<=69;a++)
            {
                Console.WriteLine(getmappos(a));
            }
            for (int a = 70; a <= 99; a++)
            {
                Console.Write(getmappos(a));
            }
    /// <summary>
        /// 用于根据数字绘制地图的图案
        /// </summary>
        /// <param name="a">a为输入数组所代表的格数</param>
        /// <returns></returns>
        public static string getmappos(int a)
        {
            string fuck="";
            if (playerpost[0] == a && playerpost[1] == a)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                fuck = ("<>");
            }
            else if (playerpost[0] == a)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                fuck = ("A");
            }
            else if (playerpost[1] == a)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                fuck = ("B");
            }
            else
            {
                switch (num[a])
                {
                    case 0:
                        Console.ForegroundColor = ConsoleColor.White;
                        fuck = ("");
                        break;
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Red;
                        fuck = ("");
                        break;
                    case 2:
                        Console.ForegroundColor = ConsoleColor.Green;
                        fuck = ("");
                        break;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.DarkBlue;
                        fuck = ("");
                        break;
                    case 4:
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        fuck = ("");
                        break;
                }
                
            }

            
            return fuck;

上面的方法用于根据地图数组内元素具体的值,绘制不同图案到地图中。

飞行棋虽然代码不多,但是却将很多知识点融合在一起,可以达到系统复习的效果。

------- Windows Phone 7手机开发、.Net培训、期待与您交流! -------

转载于:https://www.cnblogs.com/neusoft2/archive/2013/01/19/2874855.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值