C#视频 飞行棋

C# 飞行棋就是对之前所学的一个运用,最主要的使用了方法,方法的调用。
飞行棋这个例子,只要理解了他的逻辑关系,每一步做什么,下一步做什么,就比较好掌握和理解。

下面是做出来的效果
在这里插入图片描述
其中最难的就是掷骰子这步了,到了特定的格子实现格子功能,这一点是这个程序中最难得一点了。

 public static void RowTouZi(int playerPos)
        {
    
    
            Random r = new Random();
            int num = r.Next(1,7);

            string msg = "";
            Console.WriteLine("{0}按任意键开始掷骰子", PlayerNames[playerPos]);
            ConsoleKeyInfo coninfo = Console.ReadKey(true);
            if (coninfo.Key == ConsoleKey.Q)
            {
    
    
                coninfo = Console.ReadKey(true);
                if (coninfo.Key == ConsoleKey.A)
                {
    
    
                    coninfo = Console.ReadKey(true);
                    if (coninfo.Key == ConsoleKey.Z)
                    {
    
    
                        num = 50;
                    }
                }
            }
            //Console.ReadKey(true);

            Console.WriteLine("{0}掷出了{1}", PlayerNames[playerPos], num);
            Console.WriteLine("{0}按任意键开始行动.....", PlayerNames[playerPos]);
            Console.ReadKey(true);
            PlayerPos[playerPos] += num;
            CheckPos();
            if (PlayerPos[playerPos] == PlayerPos[1 - playerPos])
            {
    
    
                msg=string.Format("玩家{0}踩到了玩家{1},玩家{2}退6格", PlayerNames[playerPos], PlayerNames[1 - playerPos], PlayerNames[1 - playerPos]);
                PlayerPos[1 - playerPos] -= 6;
                CheckPos();

            }
            else
            {
    
    
                switch (Map[PlayerPos[playerPos]])
                {
    
    
                    case 0: msg="行动完了"; break;
                    case 1:
                        msg = string.Format("{0}走到了幸运轮盘,请选择 1----交换位置,2----轰炸对方", PlayerNames[playerPos]);
                        int number = ReadInt(msg, 1, 2);
                        if (number == 1)
                        {
    
    
                            int temp = 0;
                            temp = PlayerPos[playerPos];
                            PlayerPos[playerPos] = PlayerPos[1 - playerPos];
                            PlayerPos[1 - playerPos] = temp;
                            msg=string.Format("玩家{0}选择了与玩家{1}交换位置", PlayerNames[playerPos], PlayerNames[1 - playerPos]);
                        }
                        else
                        {
    
    
                            PlayerPos[1 - playerPos] = 0;
                            msg=string.Format("玩家{0}选择轰炸玩家{1}", PlayerNames[playerPos], PlayerNames[1 - playerPos]);

                        }

                        break;
                    case 2:
                        //踩到地雷了
                        msg="恭喜你,能踩到地雷,百年不遇,退6格";
                        PlayerPos[playerPos] -= 6;
                        CheckPos();

                        break;
                    case 3:
                        msg="踩到暂停了";
                        flag[playerPos] = true;
                        break;
                    case 4:
                        msg="恭喜你,这个猥琐家伙竟然穿越了10步";
                        PlayerPos[playerPos] += 10;
                        CheckPos();
                        break;
                }

            }
            
            Console.Clear();
            DrawMap();
            Console.WriteLine(msg);
        }


       

猜你喜欢

转载自blog.csdn.net/wangwei021933/article/details/108889199