C# Video Flying Chess

C# Flying Chess is an application of what we have learned before, and the most important method is the method call.
The flying chess example, as long as you understand its logical relationship, what to do at each step, and what to do next, it will be easier to master and understand.

The following is the effect made.
Insert picture description here
Among them, the most difficult step is to roll the dice. It is the most rare point in this program to realize the grid function when it comes to a specific grid.

 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);
        }


       

Guess you like

Origin blog.csdn.net/wangwei021933/article/details/108889199