当前位置: 首页 > news >正文

C#飞行棋(新手简洁版)

我们要在主函数的顶部写一些全局静态字段 确保能在后续的静态方法中能够获取到这些值和修改

static int[] Maps = new int[100];static string[] PlayerName = new string[2];static int[] PlayerScore = new int[2];static bool[] Flags= new bool[2] {true,true };

 static int[] Maps = new int[100]; 这段代码是设置一个整数类数组方便我们存储后续飞行棋的每个格子和格子所具有的特殊功能 以便于后续的取用 100 代表格子个位

static string[] PlayerName = new string[2];这是存储两个玩家的名字的字符串数组 方便后续调用两个玩家

 static int[] PlayerScore = new int[2];这是用于存储两位玩家所处的格子位数方便后续获取位置并更改

static bool[] Flags= new bool[2] {true,true };存储两位玩家的回合是否进行 后续暂停回合需要用到

主函数

  static void Main(string[] args){GameShow();Console.WriteLine("请输入玩家1的名字:");PlayerName[0] = Console.ReadLine();while (PlayerName[0] == ""){Console.WriteLine("玩家A的姓名不能为空,请重新输入");PlayerName[0] = Console.ReadLine();}Console.WriteLine("请输入玩家2的名字:");PlayerName[1] = Console.ReadLine();while (PlayerName[1] == ""){Console.WriteLine("玩家B的姓名不能为空,请重新输入");PlayerName[0] = Console.ReadLine();}if ( PlayerName[0] == PlayerName[1] ){Console.WriteLine("玩家名字不能相同!请重新输入玩家B的名字");PlayerName[1] = Console.ReadLine();}Console.WriteLine("按回车键开始");Console.ReadLine();Console.Clear();GameShow();Console.WriteLine("玩家A的名字为:{0},玩家B的名字为:{1}", PlayerName[0], PlayerName[1]);InitializeTheMap();FinallyMap();while (PlayerScore [0] < 99 && PlayerScore [1] < 99){for (int i = 0;  i < 2;  i++){if (Flags[i]){Play (i);}else{Flags[i] = true;}if (PlayerScore[i] == 99){Console.ForegroundColor = ConsoleColor.Blue;Console.WriteLine("玩家{0}赢了玩家{1}", PlayerName[i], PlayerName[1 - i]);break;}}}Console.WriteLine("按回车键结束游戏");Console.ReadLine();}

GameShow();打印欢迎语

//

 Console.WriteLine("请输入玩家1的名字:");
 PlayerName[0] = Console.ReadLine();
          
 while (PlayerName[0] == "")
 {
     Console.WriteLine("玩家A的姓名不能为空,请重新输入");
     PlayerName[0] = Console.ReadLine();
 }
 Console.WriteLine("请输入玩家2的名字:");
 PlayerName[1] = Console.ReadLine();
 while (PlayerName[1] == "")
 {
     Console.WriteLine("玩家B的姓名不能为空,请重新输入");
     PlayerName[0] = Console.ReadLine();
 }
 if ( PlayerName[0] == PlayerName[1] )
 {
     Console.WriteLine("玩家名字不能相同!请重新输入玩家B的名字");
     PlayerName[1] = Console.ReadLine();
 }

 Console.WriteLine("按回车键开始");
 Console.ReadLine();
 Console.Clear();

// 这段代码是用来输入玩家姓名

InitializeTheMap();设置上面的Maps整数数组的格子类型

FinallyMap();方法 打印格子

//

  while (PlayerScore [0] < 99 && PlayerScore [1] < 99)
  {
      for (int i = 0;  i < 2;  i++) 两位玩家
      {
          if (Flags[i])// 上面的Flags已经默认了此回合执行true
          {
              Play (i);
          }
          else 上一回合不执行后,下次回合正常执行需要改为true
          {
              Flags[i] = true;
          }
          if (PlayerScore[i] == 99)
          {
              Console.ForegroundColor = ConsoleColor.Blue;
              Console.WriteLine("玩家{0}赢了玩家{1}", PlayerName[i], PlayerName[1 - i]);
              break;
          }
      }
  }

// 这段代码用来判断回合是否暂停

欢迎语方法代码

 static void GameShow()
 {
     //Console.ForegroundColor控制台字体颜色
     //Console.BackgroundColor控制台背景颜色
     Console.ForegroundColor = ConsoleColor.Yellow;
     Console.WriteLine("************************************");
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine("************************************");
     Console.ForegroundColor = ConsoleColor.Green;
     Console.WriteLine("************************************");
     Console.ForegroundColor = ConsoleColor.White;
     Console.WriteLine("*************飞行棋游戏1.4*************");
     Console.ForegroundColor = ConsoleColor.Cyan;
     Console.WriteLine("************************************");
     Console.ForegroundColor = ConsoleColor.DarkMagenta;
     Console.WriteLine("************************************");
     Console.ForegroundColor = ConsoleColor.DarkBlue;
     Console.WriteLine("************************************");
     Console.ForegroundColor = ConsoleColor.White;
 }

static Random random = new Random(); 这是用来重置每次的地图每次地图需要不同

初始化地图

 static void InitializeTheMap(){int[] LuckDong = new int[5]; // 幸运◎int[] landMine = new int[5];// 地雷★int l = 0;int[] bomb = new int[5]; // 暂停▲int b = 0;int[] TimeTunnel = new int[5]; // 时光隧穿卍int t = 0;for (int i = 0; i < 20; i++){int num = random.Next(1, 101);Thread.Sleep(15);if (i < 5){LuckDong[i] = num;}else if (i < 10){landMine[l++] = num;}else if (i < 15){bomb[b++] = num;}else if (i < 20){TimeTunnel[t++] = num;}}for (int i = 0; i < LuckDong .Length; i++)Maps[LuckDong [i]] = 1;for (int i = 0; i < landMine.Length; i++)Maps[landMine[i]] = 2;for (int i = 0; i < bomb.Length; i++)Maps[bomb[i]] = 3;for (int i = 0; i < TimeTunnel.Length; i++)Maps[TimeTunnel[i]] = 4;}

//

int[] LuckDong = new int[5]; // 幸运◎
int[] landMine = new int[5];// 地雷★
int l = 0;
int[] bomb = new int[5]; // 暂停▲
int b = 0;
int[] TimeTunnel = new int[5]; // 时光隧穿卍
int t = 0;
for (int i = 0; i < 20; i++)
{
    int num = random.Next(1, 101);

    Thread.Sleep(15);


    if (i < 5)
    {
        LuckDong[i] = num;
    }
    else if (i < 10)
    {
        landMine[l++] = num;
    }
    else if (i < 15)
    {
        bomb[b++] = num;
    }
    else if (i < 20)
    {
        TimeTunnel[t++] = num;
    }
}

// 四种特殊类型的格子用随机数生成所在格子的位置

//

 for (int i = 0; i < LuckDong .Length; i++)
     Maps[LuckDong [i]] = 1;
 for (int i = 0; i < landMine.Length; i++)
     Maps[landMine[i]] = 2;
 for (int i = 0; i < bomb.Length; i++)
     Maps[bomb[i]] = 3;
 for (int i = 0; i < TimeTunnel.Length; i++)
     Maps[TimeTunnel[i]] = 4;

// 同种格子设置同种的值 位置随机且不同 分别for循环放入Maps数组中 方便后续打印

设置单个格子所代表的图案

 static string DrawStringMap(int i){string str = "";if (PlayerScore[0] == PlayerScore[1] && PlayerScore[0] == i){str = "<>";}else if (PlayerScore[0] == i){str = "A";}else if (PlayerScore[1] == i){str = "B";}else{switch (Maps[i]){case 0:Console.ForegroundColor = ConsoleColor.Yellow;str = "□";break;case 1:Console.ForegroundColor = ConsoleColor.Green;str = "◎";break;case 2:Console.ForegroundColor = ConsoleColor.Red;str = "☆";break;case 3:Console.ForegroundColor = ConsoleColor.Blue;str = "▲";break;case 4:Console.ForegroundColor = ConsoleColor.DarkCyan;str = "卐";break;}}return str;}

 static string DrawStringMap(int i)
 {
      string str = "";
     if (PlayerScore[0] == PlayerScore[1] && PlayerScore[0] == i)
     {
         str = "<>"; 起始时两个格子在同一起点用<>表示
     }
     else if (PlayerScore[0] == i)
     {
         
         str = "A";后续用A表示玩家一
     }
     else if (PlayerScore[1] == i)
     {
         str = "B";玩家二
     }
     else
     {
         switch (Maps[i])
         {
             case 0:
                 Console.ForegroundColor = ConsoleColor.Yellow;
                 str = "□";没有作用的空白格子
                 break;
             case 1:
                 Console.ForegroundColor = ConsoleColor.Green;
                 str = "◎";幸运格子 
                 break;
             case 2:
                 Console.ForegroundColor = ConsoleColor.Red;
                 str = "☆";炸弹
                 break;
             case 3:
                 Console.ForegroundColor = ConsoleColor.Blue;
                 str = "▲";暂停
                 break;
             case 4:
                 Console.ForegroundColor = ConsoleColor.DarkCyan;
                 str = "卐";时空隧道
                 break;
         }
     }
     return str;


 }

打印全部地图

 static void FinallyMap()
 {
     Console.ForegroundColor = ConsoleColor.Green;
     Console.WriteLine("图例:幸运轮盘:◎\t地雷:☆\t暂停:▲\t时空隧道:卐");
     Console.WriteLine("玩家A的名字为:{0},玩家B的名字为:{1}", PlayerName[0], PlayerName[1]);
     Console.WriteLine(PlayerName[0] + " " + PlayerScore[0] + " " + PlayerName[1] + " " + PlayerScore[1]);
     Console.ForegroundColor = ConsoleColor.White;

    //  第一横行
     for (int i = 0; i < 30; i++)
     {
         Console.Write(DrawStringMap(i));
         Console.ForegroundColor = ConsoleColor.White;
     }
     Console.WriteLine();
     

     // 第一竖行
     for (int i = 30; i < 35; i++)
     {
         for (int j = 0; j <= 28; j++)
         {
             Console.Write("  "); 
         }
         Console.Write(DrawStringMap(i));
         Console.ForegroundColor = ConsoleColor.White;
         Console.WriteLine();
     }
     

     // 第二横行
     for (int i = 64; i >= 35; i--)
     {
         Console.Write(DrawStringMap(i));
         Console.ForegroundColor = ConsoleColor.White;
     }
     Console.WriteLine();
  

     // 第二竖行
     for (int i = 65; i <= 69; i++)
     {
         Console.WriteLine(DrawStringMap(i));
         Console.ForegroundColor = ConsoleColor.White;
     }
     

     // 第三横行
     for (int i = 70; i <= 99; i++)
     {
         Console.Write(DrawStringMap(i));
         Console.ForegroundColor = ConsoleColor.White;
     }
     Console.WriteLine();
 }

 static void FinallyMap(){Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("图例:幸运轮盘:◎\t地雷:☆\t暂停:▲\t时空隧道:卐");Console.WriteLine("玩家A的名字为:{0},玩家B的名字为:{1}", PlayerName[0], PlayerName[1]);Console.WriteLine(PlayerName[0] + " " + PlayerScore[0] + " " + PlayerName[1] + " " + PlayerScore[1]);Console.ForegroundColor = ConsoleColor.White;//  第一横行for (int i = 0; i < 30; i++){Console.Write(DrawStringMap(i));Console.ForegroundColor = ConsoleColor.White;}Console.WriteLine();// 第一竖行for (int i = 30; i < 35; i++){for (int j = 0; j <= 28; j++){Console.Write("  "); }Console.Write(DrawStringMap(i));Console.ForegroundColor = ConsoleColor.White;Console.WriteLine();}// 第二横行for (int i = 64; i >= 35; i--){Console.Write(DrawStringMap(i));Console.ForegroundColor = ConsoleColor.White;}Console.WriteLine();// 第二竖行for (int i = 65; i <= 69; i++){Console.WriteLine(DrawStringMap(i));Console.ForegroundColor = ConsoleColor.White;}// 第三横行for (int i = 70; i <= 99; i++){Console.Write(DrawStringMap(i));Console.ForegroundColor = ConsoleColor.White;}Console.WriteLine();}

掷骰子的方法

static void Play(int num )
{
   Random  random = new Random();
    int dice = random.Next(1, 7);
    Console.WriteLine("按回车键开始掷骰子");
    Console.ReadLine();
    Console.WriteLine("{0}掷出了{1}点", PlayerName[num], dice);
    PlayerScore[num] += dice;
    ChangePlayerScore();
    Console.WriteLine("按回车键继续");
    Console.ReadLine();

上述代码用于获取随机掷骰子的点数


    if (PlayerScore[num] == PlayerScore[1-num ])
    {
        Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}后退6格", PlayerName[num], PlayerName[1 - num], PlayerName[1 - num]);
        PlayerScore[1 - num] -= 6;
        ChangePlayerScore();该方法是用来防止玩家位置出现在地图外
        Console.WriteLine("按回车键继续");
        Console.ReadLine();

    }

两种情况 
    else
    {
        switch (Maps[PlayerScore[num]])
        {
            case 0:
                {
                    Console.WriteLine("玩家{0}踩到了什么,无事发生", PlayerName[num]);
                    break;
                }
            case 1:
                {
                    Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择 1--交换位置 2--轰炸对方", PlayerName[num]);
                    string input = Console.ReadLine();
                    while (true)
                    {
                        if (input == "1")
                        {
                            Console.WriteLine("玩家{0}选择跟玩家{1}交换位置", PlayerName[num], PlayerName[1 - num]); ;
                            Console.ReadKey();
                            int temp = PlayerScore[num];
                            PlayerScore[num] = PlayerScore[1 - num];
                            PlayerScore[1 - num] = temp;
                            Console.WriteLine("交换完成!!!按任意键继续游戏!!!");
                            Console.ReadKey();
                            break;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("玩家{0}选择轰炸玩家{1},玩家{2}后退6格", PlayerName[num], PlayerName[1 - num], PlayerName[1 - num]);
                            PlayerScore [1 - num] -= 6;
                            ChangePlayerScore();
                            Console.ReadKey();
                            break;
                        }
                        else
                        {
                            Console.WriteLine("只能输入1或者2 1--交换位置 2--轰炸对方");
                            input = Console.ReadLine();
                        }
                    }
                    break;
                }
            case 2:
                Console.WriteLine("玩家{0}踩到了地雷,后退6格", PlayerName[num]);
                Console.ReadKey();
                PlayerScore [num] -= 6;
                ChangePlayerScore();
                break;
            case 3:
                Console.WriteLine("玩家{0}踩到了暂停,暂停一回合", PlayerName[num]);
                Flags[num] = false;
                Console.ReadKey();
                break;
            case 4:
                Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", PlayerName[num]);
                PlayerScore [num] += 10;
                ChangePlayerScore();
                Console.ReadKey();
                break;
        }
    }
    Console .Clear();
   
    FinallyMap();
   

}

static void Play(int num )
{Random  random = new Random();int dice = random.Next(1, 7);Console.WriteLine("按回车键开始掷骰子");Console.ReadLine();Console.WriteLine("{0}掷出了{1}点", PlayerName[num], dice);PlayerScore[num] += dice;ChangePlayerScore();Console.WriteLine("按回车键继续");Console.ReadLine();if (PlayerScore[num] == PlayerScore[1-num ]){Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}后退6格", PlayerName[num], PlayerName[1 - num], PlayerName[1 - num]);PlayerScore[1 - num] -= 6;ChangePlayerScore();Console.WriteLine("按回车键继续");Console.ReadLine();}else{switch (Maps[PlayerScore[num]]){case 0:{Console.WriteLine("玩家{0}踩到了什么,无事发生", PlayerName[num]);break;}case 1:{Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择 1--交换位置 2--轰炸对方", PlayerName[num]);string input = Console.ReadLine();while (true){if (input == "1"){Console.WriteLine("玩家{0}选择跟玩家{1}交换位置", PlayerName[num], PlayerName[1 - num]); ;Console.ReadKey();int temp = PlayerScore[num];PlayerScore[num] = PlayerScore[1 - num];PlayerScore[1 - num] = temp;Console.WriteLine("交换完成!!!按任意键继续游戏!!!");Console.ReadKey();break;}else if (input == "2"){Console.WriteLine("玩家{0}选择轰炸玩家{1},玩家{2}后退6格", PlayerName[num], PlayerName[1 - num], PlayerName[1 - num]);PlayerScore [1 - num] -= 6;ChangePlayerScore();Console.ReadKey();break;}else{Console.WriteLine("只能输入1或者2 1--交换位置 2--轰炸对方");input = Console.ReadLine();}}break;}case 2:Console.WriteLine("玩家{0}踩到了地雷,后退6格", PlayerName[num]);Console.ReadKey();PlayerScore [num] -= 6;ChangePlayerScore();break;case 3:Console.WriteLine("玩家{0}踩到了暂停,暂停一回合", PlayerName[num]);Flags[num] = false;Console.ReadKey();break;case 4:Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", PlayerName[num]);PlayerScore [num] += 10;ChangePlayerScore();Console.ReadKey();break;}}Console .Clear();FinallyMap();}

  FinallyMap(); 在玩的方法中由于玩家位置发生改变所以要重新打印一次地图

static void ChangePlayerScore()
{
    for (int  i = 0;  i < 2;  i++)
    {
        if (PlayerScore [i] < 0 )
        {
            PlayerScore[i]= 0;
        }
        if (PlayerScore[i] > 99 )
        {
            PlayerScore [i] = 99;
        }
    }
}

这方法是用来判断玩家位置是否出界如果出界默认在段端点

完整代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;namespace 飞行棋游戏
{internal class Program{static int[] Maps = new int[100];static string[] PlayerName = new string[2];static int[] PlayerScore = new int[2];static bool[] Flags= new bool[2] {true,true };static void Main(string[] args){GameShow();Console.WriteLine("请输入玩家1的名字:");PlayerName[0] = Console.ReadLine();while (PlayerName[0] == ""){Console.WriteLine("玩家A的姓名不能为空,请重新输入");PlayerName[0] = Console.ReadLine();}Console.WriteLine("请输入玩家2的名字:");PlayerName[1] = Console.ReadLine();while (PlayerName[1] == ""){Console.WriteLine("玩家B的姓名不能为空,请重新输入");PlayerName[0] = Console.ReadLine();}if ( PlayerName[0] == PlayerName[1] ){Console.WriteLine("玩家名字不能相同!请重新输入玩家B的名字");PlayerName[1] = Console.ReadLine();}Console.WriteLine("按回车键开始");Console.ReadLine();Console.Clear();GameShow();Console.WriteLine("玩家A的名字为:{0},玩家B的名字为:{1}", PlayerName[0], PlayerName[1]);InitializeTheMap();FinallyMap();while (PlayerScore [0] < 99 && PlayerScore [1] < 99){for (int i = 0;  i < 2;  i++){if (Flags[i]){Play (i);}else{Flags[i] = true;}if (PlayerScore[i] == 99){Console.ForegroundColor = ConsoleColor.Blue;Console.WriteLine("玩家{0}赢了玩家{1}", PlayerName[i], PlayerName[1 - i]);break;}}}Console.WriteLine("按回车键结束游戏");Console.ReadLine();}static void GameShow(){//Console.ForegroundColor控制台字体颜色//Console.BackgroundColor控制台背景颜色Console.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("************************************");Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine("************************************");Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("************************************");Console.ForegroundColor = ConsoleColor.White;Console.WriteLine("*************飞行棋游戏1.4*************");Console.ForegroundColor = ConsoleColor.Cyan;Console.WriteLine("************************************");Console.ForegroundColor = ConsoleColor.DarkMagenta;Console.WriteLine("************************************");Console.ForegroundColor = ConsoleColor.DarkBlue;Console.WriteLine("************************************");Console.ForegroundColor = ConsoleColor.White;}static Random random = new Random();static void InitializeTheMap(){int[] LuckDong = new int[5]; // 幸运◎int[] landMine = new int[5];// 地雷★int l = 0;int[] bomb = new int[5]; // 暂停▲int b = 0;int[] TimeTunnel = new int[5]; // 时光隧穿卍int t = 0;for (int i = 0; i < 20; i++){int num = random.Next(1, 101);Thread.Sleep(15);if (i < 5){LuckDong[i] = num;}else if (i < 10){landMine[l++] = num;}else if (i < 15){bomb[b++] = num;}else if (i < 20){TimeTunnel[t++] = num;}}for (int i = 0; i < LuckDong .Length; i++)Maps[LuckDong [i]] = 1;for (int i = 0; i < landMine.Length; i++)Maps[landMine[i]] = 2;for (int i = 0; i < bomb.Length; i++)Maps[bomb[i]] = 3;for (int i = 0; i < TimeTunnel.Length; i++)Maps[TimeTunnel[i]] = 4;}static void FinallyMap(){Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("图例:幸运轮盘:◎\t地雷:☆\t暂停:▲\t时空隧道:卐");Console.WriteLine("玩家A的名字为:{0},玩家B的名字为:{1}", PlayerName[0], PlayerName[1]);Console.WriteLine(PlayerName[0] + " " + PlayerScore[0] + " " + PlayerName[1] + " " + PlayerScore[1]);Console.ForegroundColor = ConsoleColor.White;//  第一横行for (int i = 0; i < 30; i++){Console.Write(DrawStringMap(i));Console.ForegroundColor = ConsoleColor.White;}Console.WriteLine();// 第一竖行for (int i = 30; i < 35; i++){for (int j = 0; j <= 28; j++){Console.Write("  "); }Console.Write(DrawStringMap(i));Console.ForegroundColor = ConsoleColor.White;Console.WriteLine();}// 第二横行for (int i = 64; i >= 35; i--){Console.Write(DrawStringMap(i));Console.ForegroundColor = ConsoleColor.White;}Console.WriteLine();// 第二竖行for (int i = 65; i <= 69; i++){Console.WriteLine(DrawStringMap(i));Console.ForegroundColor = ConsoleColor.White;}// 第三横行for (int i = 70; i <= 99; i++){Console.Write(DrawStringMap(i));Console.ForegroundColor = ConsoleColor.White;}Console.WriteLine();}static string DrawStringMap(int i){string str = "";if (PlayerScore[0] == PlayerScore[1] && PlayerScore[0] == i){str = "<>";}else if (PlayerScore[0] == i){str = "A";}else if (PlayerScore[1] == i){str = "B";}else{switch (Maps[i]){case 0:Console.ForegroundColor = ConsoleColor.Yellow;str = "□";break;case 1:Console.ForegroundColor = ConsoleColor.Green;str = "◎";break;case 2:Console.ForegroundColor = ConsoleColor.Red;str = "☆";break;case 3:Console.ForegroundColor = ConsoleColor.Blue;str = "▲";break;case 4:Console.ForegroundColor = ConsoleColor.DarkCyan;str = "卐";break;}}return str;}static void Play(int num ){Random  random = new Random();int dice = random.Next(1, 7);Console.WriteLine("按回车键开始掷骰子");Console.ReadLine();Console.WriteLine("{0}掷出了{1}点", PlayerName[num], dice);PlayerScore[num] += dice;ChangePlayerScore();Console.WriteLine("按回车键继续");Console.ReadLine();if (PlayerScore[num] == PlayerScore[1-num ]){Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}后退6格", PlayerName[num], PlayerName[1 - num], PlayerName[1 - num]);PlayerScore[1 - num] -= 6;ChangePlayerScore();Console.WriteLine("按回车键继续");Console.ReadLine();}else{switch (Maps[PlayerScore[num]]){case 0:{Console.WriteLine("玩家{0}踩到了什么,无事发生", PlayerName[num]);break;}case 1:{Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择 1--交换位置 2--轰炸对方", PlayerName[num]);string input = Console.ReadLine();while (true){if (input == "1"){Console.WriteLine("玩家{0}选择跟玩家{1}交换位置", PlayerName[num], PlayerName[1 - num]); ;Console.ReadKey();int temp = PlayerScore[num];PlayerScore[num] = PlayerScore[1 - num];PlayerScore[1 - num] = temp;Console.WriteLine("交换完成!!!按任意键继续游戏!!!");Console.ReadKey();break;}else if (input == "2"){Console.WriteLine("玩家{0}选择轰炸玩家{1},玩家{2}后退6格", PlayerName[num], PlayerName[1 - num], PlayerName[1 - num]);PlayerScore [1 - num] -= 6;ChangePlayerScore();Console.ReadKey();break;}else{Console.WriteLine("只能输入1或者2 1--交换位置 2--轰炸对方");input = Console.ReadLine();}}break;}case 2:Console.WriteLine("玩家{0}踩到了地雷,后退6格", PlayerName[num]);Console.ReadKey();PlayerScore [num] -= 6;ChangePlayerScore();break;case 3:Console.WriteLine("玩家{0}踩到了暂停,暂停一回合", PlayerName[num]);Flags[num] = false;Console.ReadKey();break;case 4:Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", PlayerName[num]);PlayerScore [num] += 10;ChangePlayerScore();Console.ReadKey();break;}}Console .Clear();FinallyMap();}static void ChangePlayerScore(){for (int  i = 0;  i < 2;  i++){if (PlayerScore [i] < 0 ){PlayerScore[i]= 0;}if (PlayerScore[i] > 99 ){PlayerScore [i] = 99;}}}}
}

相关文章:

C#飞行棋(新手简洁版)

我们要在主函数的顶部写一些全局静态字段 确保能在后续的静态方法中能够获取到这些值和修改 static int[] Maps new int[100];static string[] PlayerName new string[2];static int[] PlayerScore new int[2];static bool[] Flags new bool[2] {true,true }; static int[]…...

【OpenCV】图像转换

理论 傅立叶变换用于分析各种滤波器的频率特性。对于图像&#xff0c;使用 2D离散傅里叶变换&#xff08;DFT&#xff09; 查找频域。快速算法称为 快速傅立叶变换&#xff08;FFT&#xff09; 用于计算DFT。 Numpy中的傅立叶变换 首先&#xff0c;我们将看到如何使用Numpy查…...

力扣 重排链表-143

重排链表-143 /*** Definition for singly-linked list.* struct ListNode {* int val;* ListNode *next;* ListNode() : val(0), next(nullptr) {}* ListNode(int x) : val(x), next(nullptr) {}* ListNode(int x, ListNode *next) : val(x), next(next)…...

【Kubernetes理论篇】容器集群管理系统Kubernetes(K8S)

Kubernetes集群部署基本管理实战 这么好的机会&#xff0c;还在等什么&#xff01; 01、Kubernetes 概述 K8S是什么 K8S 的全称为 Kubernetes (K12345678S)&#xff0c;PS&#xff1a;“嘛&#xff0c;写全称也太累了吧&#xff0c;写”。不如整个缩写 K8s 作为缩写的结果…...

Kubernetes 常用操作大全:全面掌握 K8s 基础与进阶命令

Kubernetes&#xff08;简称 K8s&#xff09;作为一种开源的容器编排工具&#xff0c;已经成为现代分布式系统中的标准。它的强大之处在于能够自动化应用程序的部署、扩展和管理。在使用 Kubernetes 的过程中&#xff0c;熟悉常用操作对于高效地管理集群资源至关重要。本文将详…...

爬虫基础之Web网页基础

网页的组成 网页可以分为三大部分–HTML、CSS 和 JavaScript。如果把网页比作一个人&#xff0c;那么 HTML 相当于骨架、JavaScript 相当于肌肉、CSS 相当于皮肤&#xff0c;这三者结合起来才能形成一个完善的网页。下面我们分别介绍一下这三部分的功能。 HTML HTML(Hypertext…...

k8s, deployment

控制循环&#xff08;control loop&#xff09; for {实际状态 : 获取集群中对象X的实际状态&#xff08;Actual State&#xff09;期望状态 : 获取集群中对象X的期望状态&#xff08;Desired State&#xff09;if 实际状态 期望状态{什么都不做} else {执行编排动作&#xf…...

使用ensp搭建OSPF+BGP和静态路由,底层PC使用dhcp,实现PC互通

1.4种方式&#xff0c;实现PC2可以互通底层的所有设备 OSPF&#xff1a;OSPF是一种用于互联网协议网络的链路状态路由协议 BGP&#xff1a;是一种用于互联网上进行路由和可达性信息传递的外部网关协议&#xff08;EGP&#xff09; 静态路由&#xff1a; 静态路由是一种路由方…...

TÜLU 3: Pushing Frontiers in Open Language Model Post-Training

基本信息 &#x1f4dd; 原文链接: https://arxiv.org/abs/2411.15124&#x1f465; 作者: Nathan Lambert, Jacob Morrison, Valentina Pyatkin, Shengyi Huang, Hamish Ivison, Faeze Brahman, Lester James V. Miranda, Alisa Liu, Nouha Dziri, Shane Lyu, Yuling Gu, Sau…...

深入解读 MySQL EXPLAIN 与索引优化实践

MySQL 是当今最流行的关系型数据库之一&#xff0c;为了提升查询性能&#xff0c;合理使用 EXPLAIN 工具和优化索引显得尤为重要。本文将结合实际示例&#xff0c;探讨如何利用 EXPLAIN 分析查询执行计划&#xff0c;并分享索引优化的最佳实践。 一、EXPLAIN 工具简介 EXPLAIN …...

Flume——进阶(agent特性+三种结构:串联,多路复用,聚合)

目录 agent特性ChannelSelector描述&#xff1a; SinkProcessor描述&#xff1a; 串联架构结构图解定义与描述配置示例Flume1&#xff08;监测端node1&#xff09;Flume3&#xff08;接收端node3&#xff09;启动方式 复制和多路复用结构图解定义描述配置示例node1node2node3启…...

ragflow连ollama时出现的Bug

ragflow和ollama连接后&#xff0c;已经添加了两个模型但是ragflow仍然一直warn&#xff1a;Please add both embedding model and LLM in Settings &#xff1e; Model providers firstly.这里可能是我一开始拉取的镜像容器太小&#xff0c;容不下当前添加的模型&#xff0c;导…...

基于centos7.7编译Redis6.0

背景&#xff1a; OS&#xff1a;CentOs 7.7 Redis: 6.0.6 编译构建报错如下&#xff1a; In file included from server.c:30:0: server.h:1044:5: error: expected specifier-qualifier-list before ‘_Atomic’_Atomic unsigned int lruclock; /* Clock for LRU eviction …...

uni-app项目无法在Android Studio模拟器上运行

目录 1 问题描述2 尝试解决3 引发原因4 解决方法4.1 换用 MuMu 模拟器 5 结语 1 问题描述 在使用 uni-app 开发 Pad 端 App 时&#xff0c;初始化项目后打算先运行一下确保初始化正常。打开 Android Studio 模拟器后&#xff0c;然后在 HbuilderX 中选择使用 App 标准基座 运…...

第一部分:Linux系统(基础及命令)

Linux操作系统的实操性非常强&#xff0c;纯操作&#xff0c;不适用于日常的办公使用 1.初始Linux 1.1 操作系统概述 1.1.1 了解OS的作用 OS&#xff1a;是计算机软件的一种&#xff0c;主要负责&#xff1a;作为用户和计算机硬件之间的桥梁&#xff0c;调度和管理计算机硬…...

No module named ‘_ssl‘ No module named ‘_ctypes‘

如果你使用的是基于 yum 的 Linux 发行版&#xff08;例如 CentOS、RHEL、Fedora&#xff09;&#xff0c;安装 libc6-dev 的方式稍有不同。在这些系统中&#xff0c;通常对应的包是 glibc-devel。 No module named ‘_ctypes’ 使用 yum 安装 glibc-devel 更新系统的软件包列…...

【QT】编写第一个 QT 程序 对象树 Qt 编程事项 内存泄露问题

目录 1. 编写第一个 QT 程序 1.1 使用 标签 实现 &#x1f407; 图形化界面实现 &#x1f407; 纯代码形式实现 1.2 使用 按钮 实现 &#x1f40b; 图形化界面实现 &#x1f40b; 纯代码形式实现 1.3 使用 编辑框 实现 &#x1f95d; 图形化界面实现 &#x1f95…...

VTK编程指南<六>:VTK可视化管线与渲染详解

1、VTK渲染引擎 回顾前几章节的RenderCylinder示例 可以找到以下的类: vtkProp; ytkAbstractMapper; vtkProperty; vtkCamera; vtkLight; vtkRenderer; vtkRenderWindow; vtkRenderWindowInteractor vtkTransform; vtkLookupTable;可以发现这些类都是与数据显示或渲染相关的。…...

基于STM32的智能计步器

引言 随着健康意识的提高&#xff0c;计步器逐渐成为人们日常生活中重要的健康管理工具。本文将指导你如何使用STM32微控制器制作一个智能计步器。该计步器通过加速度传感器检测步伐&#xff0c;并使用OLED显示屏显示步数。通过这个项目&#xff0c;你将学习到STM32开发的基本流…...

VB.NET 从入门到精通:开启编程进阶之路

摘要&#xff1a; 本文全面深入地阐述了 VB.NET 的学习路径&#xff0c;从基础的环境搭建与语法入门开始&#xff0c;逐步深入到面向对象编程、图形用户界面设计、数据访问、异常处理、多线程编程以及与其他技术的集成等核心领域&#xff0c;通过详细的代码示例与理论讲解&…...

K8S认证|CKS题库+答案| 11. AppArmor

目录 11. AppArmor 免费获取并激活 CKA_v1.31_模拟系统 题目 开始操作&#xff1a; 1&#xff09;、切换集群 2&#xff09;、切换节点 3&#xff09;、切换到 apparmor 的目录 4&#xff09;、执行 apparmor 策略模块 5&#xff09;、修改 pod 文件 6&#xff09;、…...

UE5 学习系列(三)创建和移动物体

这篇博客是该系列的第三篇&#xff0c;是在之前两篇博客的基础上展开&#xff0c;主要介绍如何在操作界面中创建和拖动物体&#xff0c;这篇博客跟随的视频链接如下&#xff1a; B 站视频&#xff1a;s03-创建和移动物体 如果你不打算开之前的博客并且对UE5 比较熟的话按照以…...

DIY|Mac 搭建 ESP-IDF 开发环境及编译小智 AI

前一阵子在百度 AI 开发者大会上&#xff0c;看到基于小智 AI DIY 玩具的演示&#xff0c;感觉有点意思&#xff0c;想着自己也来试试。 如果只是想烧录现成的固件&#xff0c;乐鑫官方除了提供了 Windows 版本的 Flash 下载工具 之外&#xff0c;还提供了基于网页版的 ESP LA…...

汇编常见指令

汇编常见指令 一、数据传送指令 指令功能示例说明MOV数据传送MOV EAX, 10将立即数 10 送入 EAXMOV [EBX], EAX将 EAX 值存入 EBX 指向的内存LEA加载有效地址LEA EAX, [EBX4]将 EBX4 的地址存入 EAX&#xff08;不访问内存&#xff09;XCHG交换数据XCHG EAX, EBX交换 EAX 和 EB…...

精益数据分析(97/126):邮件营销与用户参与度的关键指标优化指南

精益数据分析&#xff08;97/126&#xff09;&#xff1a;邮件营销与用户参与度的关键指标优化指南 在数字化营销时代&#xff0c;邮件列表效度、用户参与度和网站性能等指标往往决定着创业公司的增长成败。今天&#xff0c;我们将深入解析邮件打开率、网站可用性、页面参与时…...

HDFS分布式存储 zookeeper

hadoop介绍 狭义上hadoop是指apache的一款开源软件 用java语言实现开源框架&#xff0c;允许使用简单的变成模型跨计算机对大型集群进行分布式处理&#xff08;1.海量的数据存储 2.海量数据的计算&#xff09;Hadoop核心组件 hdfs&#xff08;分布式文件存储系统&#xff09;&a…...

A2A JS SDK 完整教程:快速入门指南

目录 什么是 A2A JS SDK?A2A JS 安装与设置A2A JS 核心概念创建你的第一个 A2A JS 代理A2A JS 服务端开发A2A JS 客户端使用A2A JS 高级特性A2A JS 最佳实践A2A JS 故障排除 什么是 A2A JS SDK? A2A JS SDK 是一个专为 JavaScript/TypeScript 开发者设计的强大库&#xff…...

第7篇:中间件全链路监控与 SQL 性能分析实践

7.1 章节导读 在构建数据库中间件的过程中&#xff0c;可观测性 和 性能分析 是保障系统稳定性与可维护性的核心能力。 特别是在复杂分布式场景中&#xff0c;必须做到&#xff1a; &#x1f50d; 追踪每一条 SQL 的生命周期&#xff08;从入口到数据库执行&#xff09;&#…...

上位机开发过程中的设计模式体会(1):工厂方法模式、单例模式和生成器模式

简介 在我的 QT/C 开发工作中&#xff0c;合理运用设计模式极大地提高了代码的可维护性和可扩展性。本文将分享我在实际项目中应用的三种创造型模式&#xff1a;工厂方法模式、单例模式和生成器模式。 1. 工厂模式 (Factory Pattern) 应用场景 在我的 QT 项目中曾经有一个需…...

React核心概念:State是什么?如何用useState管理组件自己的数据?

系列回顾&#xff1a; 在上一篇《React入门第一步》中&#xff0c;我们已经成功创建并运行了第一个React项目。我们学会了用Vite初始化项目&#xff0c;并修改了App.jsx组件&#xff0c;让页面显示出我们想要的文字。但是&#xff0c;那个页面是“死”的&#xff0c;它只是静态…...