CSharp基础知识6-控制台五子棋程序

五子棋:


class Program
    {
        static void Main(string[] args)
        {
           string qipan="□";
           string jia="●";
           string yi = "○";
           string[,] str = new string[11, 11];
           int a = str.GetLength(0);
           int b = str.GetLength(1);
           for (int i = 0; i < a; i++)
           {
               if (i == 0)
               {
                   for (int j = 0; j < b; j++)
                       str[i, j] = string.Format("{0,-2}",j.ToString());
               }
               else
               {
                   for (int j = 0; j < b; j++)
                   {
                       if (j == 0)
                       {
                           str[i, j] = string.Format("{0,-2}", i.ToString());
                       }
                       else
                       {
                           str[i, j] = qipan;
                       }
                   }
               }
           }
           bool mark = true;
           while (true)
           {
               Console.BackgroundColor = ConsoleColor.White;
               Console.ForegroundColor = ConsoleColor.Black;
               Console.Clear();
               for (int i = 0; i < a; i++)
               {
                   for (int j = 0; j < b; j++)
                   {
                       Console.Write(str[i, j]);
                   }
                   Console.WriteLine();
               }
               Console.WriteLine("请输落子坐标,例如\"4,5\"");
               if (mark)
               {
                   Console.Write("甲:");
               }
               else
               {
                   Console.Write("乙:");
               }
               string Read = Console.ReadLine();
               string[] Arrc = Read.Split(',', ',');
               int m = int.Parse(Arrc[0]);
               int n = int.Parse(Arrc[1]);
               if (str[m, n] == qipan)
               {
                   if (mark)
                   {
                       str[m, n] = jia;
                   }
                   else
                   {
                       str[m, n] = yi;
                   }
                   mark = !mark;
               }
               else
               {
                   Console.Write("这里不能落子");
                   System.Threading.Thread.Sleep(1000);
               }
           }  
        }
    }              
 

你可能感兴趣的:(职场,五子棋,控制台,休闲,csharp)