麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > C# > 正文

C# L型棋牌覆蓋實現代碼與效果

2020-01-24 03:27:06
字體:
來源:轉載
供稿:網友

//Main

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChessBoard
{
    class Program
    {
        //誰能教教我英語啊,英語語法什么的錯誤之處還望海涵,
        static void Main(string[] args)
        {
            Function obj = new Function();

            Console.WriteLine("Please intput CheseBoard Size(2^size):");
            int size = (int)Math.Pow(2, Convert.ToInt32(Console.ReadLine()));
            if (size != 1)
            {
                ConsoleColor FC = Console.ForegroundColor;
                //string[] Color = { "Black" , "DarkBlue" , "DarkGreen" , "DarkCyan" , "Gray",
                //                   "DarkRed" , "DarkMagenta" , "DarkYellow" , "Red",
                //                   "DarkGray" , "Blue" , "Green" , "Cyan", "Magenta",
                //                   "Yellow" , "White"};
                string[,] Board = new string[size, size];

                //Do you know ?
                String[] Colors = ConsoleColor.GetNames(typeof(ConsoleColor));

                Console.WriteLine("please input special grid position (row and col):");
                int rows = Convert.ToInt32(Console.ReadLine());
                int cols = Convert.ToInt32(Console.ReadLine());

                obj.CheseBoard(Board, size, rows, cols);

                for (int r = 0; r < Board.GetLength(0); r++)
                {
                    for (int c = 0; c < Board.GetLength(1); c++)
                    {
                        int Value = Convert.ToInt32(Board[r, c].ToString());
                        if (Value > 0)
                        {
                            if (Value > 15)
                            {
                                Value %= 15;
                            }
                            if ((Value %= 15) == 0)
                            {
                                Value += 1;
                            }
                            Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), Colors[Value]);
                        }
                        Console.Write(Board[r, c] + "  ");
                        // Console.ForegroundColor = FC;
                        Console.ResetColor();
                    }
                    Console.WriteLine();
                }
            }
            else
            {
                Console.WriteLine("Bugs Bug ! ! !");
            }
            Console.ReadKey();
        }
    }
}


//Class

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChessBoard
{
    class Function
    {
        /// <summary>
        /// 初始化L型骨牌
        /// </summary>
        private int LDominoNumberInitial = 0;
       

        /// <summary>
        ///  L型骨牌棋盤覆蓋
        /// </summary>
        /// <param name="Board"></param>
        /// <param name="size"></param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        public void CheseBoard(string[,] Board, int size, int row, int col)
        {
            int InitialRow = 0;
            int InitialCol = 0;
            //不合法的輸入
            if (row > size - 1 || col > size - 1)
            {
                Console.WriteLine("Error !!!!!!!!!!");
            }
                //棋盤只有一個格子
            else if (size == 1)
            {
                Console.WriteLine(Board[row, col] = "-1");
            }
            else
            {
                Board[row, col] = "-1";
                DivisionBoard(Board, InitialRow, InitialCol, row, col, size);
            }
        }

        /// <summary>
        /// 大棋盤4分為小的棋盤,在沒有特殊位置的小棋盤中放L骨牌一角(作為特殊位置)
        /// 然后再次對每個小的4劃分...至只有一個格子.
        /// </summary>
        /// <param name="Board"></param>
        /// <param name="InitialRow"></param>
        /// <param name="InitialCol"></param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <param name="size"></param>
        public void DivisionBoard(string[,] Board, int InitialRow, int InitialCol, int row, int col, int size)
        {
            if (size == 1)
            {
                return;
            }
            //It's Important....全局的骨牌數的副本
            int LDominoNumber = LDominoNumberInitial++;
            //判斷特殊位置的界限值
            size /= 2;
            //left up
            if (row < InitialRow + size && col < InitialCol + size)
            {
                //特殊位置在里面
                DivisionBoard(Board, InitialRow, InitialCol, row, col, size);
            }
            else
            {
                //不在里面,在這里面放L骨牌的一角,為下次遞歸做準備..
                if (LDominoNumber < 10)
                {
                    Board[InitialRow + size - 1, InitialCol + size - 1] = "0" + LDominoNumber.ToString();
                }
                else
                {
                    Board[InitialRow + size - 1, InitialCol + size - 1] = LDominoNumber.ToString();
                }
                //Console.ForegroundColor = FC;
                //最左上角
                DivisionBoard(Board, InitialRow, InitialCol, InitialRow + size - 1, InitialCol + size - 1, size);
            }
            //right up
            if (row < InitialRow + size && col >= InitialCol + size)
            {
                DivisionBoard(Board, InitialRow, InitialCol + size, row, col, size);
            }
            else
            {
                if (LDominoNumber < 10)
                {
                    Board[InitialRow + size - 1, InitialCol + size] = "0" + LDominoNumber.ToString();
                }
                else
                {
                    Board[InitialRow + size - 1, InitialCol + size] = LDominoNumber.ToString();
                }
                DivisionBoard(Board, InitialRow, InitialCol + size, InitialRow + size - 1, InitialCol + size, size);
            }
            //left down
            if (row >= InitialRow + size && col < InitialCol + size)
            {
                DivisionBoard(Board, InitialRow + size, InitialCol, row, col, size);
            }
            else
            {
                if (LDominoNumber < 10)
                {
                    Board[InitialRow + size, InitialCol + size - 1] = "0" + LDominoNumber.ToString();
                }
                else
                {
                    Board[InitialRow + size, InitialCol + size - 1] = LDominoNumber.ToString();
                }
                DivisionBoard(Board, InitialRow + size, InitialCol, InitialRow + size, InitialCol + size - 1, size);
            }
            //right down
            if (row >= InitialRow + size && col >= InitialCol + size)
            {
                DivisionBoard(Board, InitialRow + size, InitialCol + size, row, col, size);
            }
            else
            {
                if (LDominoNumber < 10)
                {
                    Board[InitialRow + size, InitialCol + size] = "0" + LDominoNumber.ToString();
                }
                else
                {
                    Board[InitialRow + size, InitialCol + size] = LDominoNumber.ToString();
                }
                DivisionBoard(Board, InitialRow + size, InitialCol + size, InitialRow + size, InitialCol + size, size);
            }
        }
    }
}


//程序運行結果截圖

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美 videos粗暴 | 在线a毛片免费视频观看 | 国产成人强伦免费视频网站 | 欧美一级精品 | 欧美性受ⅹ╳╳╳黑人a性爽 | 午夜视频在线免费 | 中文字幕h | 伊人yinren22综合网色 | 香蕉国产在线视频 | 高清视频一区二区 | av在线免费看网站 | 日本高清在线免费 | 免费观看一区二区三区视频 | 日本一区二区在线看 | 亚洲成人国产综合 | 国产精品久久久久久影院8一贰佰 | 日韩黄色av网站 | 久久久精品视 | 免费一级毛片在线播放不收费 | 福利在线国产 | 亚洲精品免费播放 | 成人午夜视频免费 | 午夜亚洲视频 | 国产91影院 | 五月婷婷第四色 | 国产精品久久久久久久久久iiiii | 久久久久久久久久网站 | 91 在线视频观看 | 黄色网址免费在线 | a视频在线看 | 色播亚洲 | 国产免费人做人爱午夜视频 | xxxx hd videos| 手机免费看一级片 | 久久精品网| 亚洲精品一区二区三区大胸 | 多人乱大交xxxxx变态 | 911视频免费版 | 香蕉视频18 | 精品国产乱码久久久久久丨区2区 | 午夜视频色 |