黑马程序员-我的入学笔记3-飞行棋小程序

来源:互联网 发布:dvrnet监控软件 编辑:程序博客网 时间:2024/05/17 13:09

---------------------- <a href="http://edu.csdn.net"target="blank">ASP.Net+Android+IO开发S</a>、<a href="http://edu.csdn.net"target="blank">.Net培训</a>、期待与您交流! ----------------------
        看视频的时候,还真有些兴奋,连着看完了,理解了差不多,开始动手写,刚开始还真不知道怎么下手,刚看的思路,好像记得,又好像想不起来.回去又看看了视频,就边写,回去又边看,写了好久哦,头真晕啊,哎,一个小小项目还真没这么容易,我写了有两天,断断续续写完了,调试了下,老有问题,再去调试,有时写错的一个思路,折腾了好久.终于改好BUG,还是有满足感的,但我知道还有很远的路,不知道什么时候我能迎来自己的第一个真正的项目.今天为了写笔记发博客,我又看了之前写的代码,一下子还不能完全看懂,这还是不是自己写的呢,我想动手改一改原来想改的功能,还到论坛上发了问题,理了下思路,动手做了,只多实现了停两次的功能,后面的时空隧道传到下个时空隧道的功能,有些思路但还真不知道怎么写,我想肯定关于集合.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 飞行棋
{
   class Program
    {   
         /// <summary>
        /// 重要的部分,是思路,有几点以后可以扩展的有console.readkey,通过指定键进行不同的功能
        /// 另外是游戏中每个格子功能的扩展,比如暂停两次(我已经实现了,通过增加一个变量,再累加次数),
       /// 时空飞船飞到指定位置(我想应该是通过集合,没学以后再扩展)
        /// 进或退后到了另一格可以再进行格子上的功能(时空飞船只能飞一次)
        /// 最后获胜的特殊显示
        /// 还有就是以后游戏的显示画面,是动态的就更好了,一格一格的走
        /// 先这样想着,以后可以再改
        /// </summary>

        public static int[] Map = new int[100];//地图有一百个格子
        public static int[] playerAB = { 0, 0 };//分别区分玩家AB的下标
        static bool flag = true;//定义的标签,看是不是会暂停一次
        static string[] name = new string[2];//定义个数组存玩家AB的姓名
        static int[] stop = { 3, 3 };//得定义一个数组分别标记玩家A和玩家B暂停的次数
        static void Main(string[] args)
        {
            ShowUI();//调用开头方法,输出一个开头图案
           #region \开头分别输入玩家的姓名
            Console.WriteLine("请输入玩家A的姓名:");
            name[0] = ReadName();
            Console.WriteLine("请输入玩家B的姓名:");
            name[1] = ReadName();
            while (name[0] == name[1])
            {
                Console.WriteLine("不能输入与玩家A重复的名字");
                name[1] = ReadName();
            }
            Console.Clear();
            #endregion
            #region \初始化地图开始游戏
            Console.WriteLine("{0}的士兵由A表示", name[0]);
            Console.WriteLine("{0}的士兵由B表示", name[1]);
            Console.WriteLine("游戏开始..........");     //游戏开始
            Console.WriteLine("图例: 普通格:□ 幸运轮盘:◎ 地雷:★ 暂停:▲ 时空隧道:卍\n");




            ChushiMap();//初始化很重要,不然全是方块
            HuiMap();//绘制初始地图
            Console.WriteLine("\n游戏开始..............");
            #endregion
       while (playerAB[0] < 99 && playerAB[1] < 99)
      {
           玩家A掷筛子
             int play = 0;
                if (flag == false || stop[play] < 2)//用来判断要暂停几次
                {
                    if (stop[play] == 0)
                        Console.WriteLine("{0}被暂停了一次", name[play]);
                    else if (stop[play] == 1)
                        Console.WriteLine("{0}又被暂停了一次", name[play]);
                    flag = true;
                    stop[play]++;//用来增加暂停的次数
                }
                else
                {
                    play = 0;
                    Yunxin(play);
              }


            玩家B掷骰


             #region 分出胜负,输出结果
            if (playerAB[0] >= 99)
                Console.WriteLine("恭喜{0}获得胜利,{1}要继续努力哦", name[0], name[1]);
            else
                Console.WriteLine("恭喜{0}获得胜利,{1}要继续努力哦", name[1], name[0]); 
            #endregion
            Console.ReadKey();    

       }

 }

           这里是要调用的方法
+         public static void ShowUI()//游戏开头,简单的输出
+         public static string ReadName()//得到一个非空的姓名
+         public static void ChushiMap()// 地图初始化
+         public static string HuiMapGe(int pos)//每格的图形及颜色的改变
+         public static void HuiMap()//绘整张图
+         public static int Zhioneshu()//得到一个随机数
+         public static int Oneortwo()//只能输入1或2
+         public static int Panduan(int playr)// 控制玩家的地标不小于0,不大于99

+         public static void Yunxin(int pl)//主要游戏部分,根据下标完成功能
         {
            if (flag == true)
            {
                Console.WriteLine("请{0}掷骰子", name[pl]);
                int z = Zhioneshu();//调用得到随机数的方法
                Console.WriteLine("玩家{1}掷出了{0}", z, name[pl]);
                playerAB[pl] = playerAB[pl] + z;
                playerAB[pl] = Panduan(playerAB[pl]);//调用判读地标的范围
                Console.ReadKey(true);

                Console.Clear();
                HuiMap();
                if (playerAB[pl] == playerAB[1 - pl])//下面是每个键的功能
                {
                    Console.WriteLine("{0}踩到了{1},将他踩到原点", name[pl], name[1 - pl]);
                    playerAB[1 - pl] = 0;
                }
                else
                {
                    switch (Map[playerAB[pl]])
                    {
                        case 1:
                            Console.WriteLine("{0}到达了幸运轮盘:请选择 1--交换位置 2--轰炸对方", name[pl]);
                            int x = Oneortwo();
                            int temp;
                            if (x == 1)
                            {
                                temp = playerAB[0];
                                playerAB[0] = playerAB[1];
                                playerAB[1] = temp;
                            }
                            else
                            {
                                playerAB[1 - pl] = playerAB[1 - pl] - 6;
                                playerAB[1 - pl] = Panduan(playerAB[1 - pl]);
                            }
                            break;
                        case 2:
                            Console.WriteLine("啊哦!{0}你踩到了地雷,你要退6格", name[pl]);
                            playerAB[pl] = playerAB[pl] - 6;
                            playerAB[pl] = Panduan(playerAB[pl]);
                            break;
                        case 3:
                            Console.WriteLine("你得到了暂停牌,对方{0}暂停两次", name[1 - pl]);
                            flag = false;
                            stop[1 - pl] = 0;//这里通过赋值让他暂停几次(暂停两次)
                            break;
                       case 4:
                            Console.WriteLine("恭喜,{0}你搭上了时空隧道往前进10步", name[pl]);
                            // 这的功能可以改进到下一个时空隧道位子上去,一时想不到,以后再来改
                            playerAB[pl] = playerAB[pl] + 10;//思路是,地图的下标也是时空隧道组的值,

                            找到时空隧道坐标加1指向下个的值,再付给                          

                             playAB[pl]
                            playerAB[pl] = Panduan(playerAB[pl]);
                            break;
                        default:
                            Console.WriteLine("{0}达到空白格 没有反应", name[pl]);
                            break;
                    }
                }
                Console.ReadKey(true);
            }
            Console.Clear();
            HuiMap();
            Console.WriteLine("现在玩家{1}在 {0}", playerAB[pl], name[pl]);
            Console.WriteLine("现在玩家{1}在 {0}\n", playerAB[1 - pl], name[1 - pl]);
        }
  }  
      其实通过后面的学习,方法放在一个类中,更方便以后的掉用也更清楚,这里其他的方法我就不贴出来了,以后我一定要再添加功能,扩展扩展

原创粉丝点击