Beispiel #1
0
        /// <summary>
        /// 根据字符串创建图形网格集合(适用于双宽模式)
        /// </summary>
        /// <param name="position">坐标</param>
        /// <param name="str">字符串</param>
        /// <param name="foreColors">前景色</param>
        /// <param name="backColors">背景色</param>
        /// <param name="depth">深度</param>
        /// <returns>图形网格集合</returns>
        public List <GraphicGrid> CreatGridByString(Vector2 position, string str, Colour[] foreColors, Colour[] backColors, uint depth = 0)
        {
            List <string>      strGrids     = DivideStringToGrids(str);
            List <GraphicGrid> graphicGrids = new List <GraphicGrid>();

            for (int i = 0; i < strGrids.Count; i++)
            {
                GraphicGrid graphicGrid = null;
                Vector2     pos         = new Vector2(position.X + i, position.Y);

                string item      = strGrids[i];
                Colour foreColor = foreColors[i];
                Colour backColor = backColors[i];

                if (item.Length == 1)
                {
                    graphicGrid = CreatGrid(pos, new CharInfo(item[0], foreColor, backColor), depth);
                }
                else if (item.Length == 2)
                {
                    graphicGrid = CreatGrid(pos, new CharInfo(item[0], foreColor, backColor),
                                            new CharInfo(item[1], foreColor, backColor), depth);
                }
                graphicGrids.Add(graphicGrid);
            }
            return(graphicGrids);
        }
Beispiel #2
0
        /// <summary>
        /// 根据数组创建图形网格集合(适用于单宽与双宽模式)
        /// </summary>
        /// <param name="position">坐标</param>
        /// <param name="strs">字符串数组</param>
        /// <param name="foreColors">前景色数组</param>
        /// <param name="backColors">背景色数组</param>
        /// <param name="depth">深度</param>
        /// <returns>图形网格集合</returns>
        public List <GraphicGrid> CreatGridByArray2D(Vector2 position, string[,] strs, Colour[,] foreColors, Colour[,] backColors, uint depth = 0)
        {
            List <GraphicGrid> graphicGrids = new List <GraphicGrid>();

            for (int i = 0; i < strs.GetLength(0); i++)
            {
                for (int j = 0; j < strs.GetLength(1); j++)
                {
                    GraphicGrid graphicGrid = null;
                    Vector2     pos         = new Vector2(position.X + j, position.Y + i);
                    string      str         = strs[i, j];
                    Colour      foreColor   = foreColors[i, j];
                    Colour      backColor   = backColors[i, j];

                    if (str.Length == 1)
                    {
                        graphicGrid = CreatGrid(pos, new CharInfo(str[0], foreColor, backColor), depth);
                    }
                    else if (str.Length == 2)
                    {
                        graphicGrid = CreatGrid
                                      (
                            pos,
                            new CharInfo(str[0], foreColor, backColor),
                            new CharInfo(str[1], foreColor, backColor),
                            depth
                                      );
                    }
                    graphicGrids.Add(graphicGrid);
                }
            }
            return(graphicGrids);
        }
Beispiel #3
0
        /// <summary>
        /// 创建图形网格(适用于双宽模式)
        /// </summary>
        /// <param name="position">坐标</param>
        /// <param name="left">左边的字符信息</param>
        /// <param name="right">右边的字符信息</param>
        /// <param name="depth">深度</param>
        /// <returns>图形网格</returns>
        public GraphicGrid CreatGrid(Vector2 position, CharInfo left, CharInfo right, uint depth = 0)
        {
            GraphicGrid grid = new GraphicGrid(position, left, right, depth);

            grids.Add(grid);
            return(grid);
        }
Beispiel #4
0
        /// <summary>
        /// 根据字符串创建图形网格集合(适用于单宽模式)
        /// </summary>
        /// <param name="position">坐标</param>
        /// <param name="str">字符串</param>
        /// <param name="foreColor">前景色</param>
        /// <param name="backColor">背景色</param>
        /// <param name="depth">深度</param>
        /// <returns>图形网格集合</returns>
        public List <GraphicGrid> CreatGridByString1(Vector2 position, string str, Colour foreColor, Colour backColor, uint depth = 0)
        {
            List <GraphicGrid> graphicGrids = new List <GraphicGrid>();

            for (int i = 0; i < str.Length; i++)
            {
                char        item        = str[i];
                GraphicGrid graphicGrid = null;
                Vector2     pos         = new Vector2(position.X + i, position.Y);

                graphicGrid = CreatGrid(pos, new CharInfo(item, foreColor, backColor), depth);

                graphicGrids.Add(graphicGrid);
            }
            return(graphicGrids);
        }
Beispiel #5
0
        /// <summary>
        /// 创建矩形(适用于单宽与双宽模式)
        /// </summary>
        /// <param name="position">坐标</param>
        /// <param name="size">尺寸</param>
        /// <param name="str">填充字符串</param>
        /// <param name="foreColor">前景色</param>
        /// <param name="backColor">背景色</param>
        /// <param name="depth">深度</param>
        /// <returns>图形网格集合</returns>
        public List <GraphicGrid> CreatRectangle
        (
            Vector2 position, Vector2 size,
            string str,
            Colour foreColor, Colour backColor,
            uint depth = 0
        )
        {
            List <GraphicGrid> graphicGrids = new List <GraphicGrid>();

            for (int i = 0; i < size.Y; i++)
            {
                for (int j = 0; j < size.X; j++)
                {
                    GraphicGrid graphicGrid = null;
                    Vector2     pos         = new Vector2(position.X + j, position.Y + i);

                    if (str.Length == 1)
                    {
                        graphicGrid = CreatGrid
                                      (
                            pos,
                            new CharInfo(str[0], foreColor, backColor),
                            depth
                                      );
                    }
                    else if (str.Length == 2)
                    {
                        graphicGrid = CreatGrid
                                      (
                            pos,
                            new CharInfo(str[0], foreColor, backColor),
                            new CharInfo(str[1], foreColor, backColor),
                            depth
                                      );
                    }

                    graphicGrids.Add(graphicGrid);
                }
            }

            return(graphicGrids);
        }
Beispiel #6
0
        /// <summary>
        /// 运行ILoveDestroy的小游戏
        /// </summary>
        public static void ILoveDestroy()
        {
            string[] lines = new string[]
            {
                @"              ,----------------,              ,---------,",
                @"         ,-----------------------,          ,""        ,""|",
                @"       ,""                      ,""|        ,""        ,""  |",
                @"      +-----------------------+  |      ,""        ,""    |",
                @"      |  .-----------------.  |  |     +---------+      |",
                @"      |  |                 |  |  |     | -==----'|      |",
                @"      |  | I LOVE DESTROY! |  |  |     |         |      |",
                @"      |  | By Charlie      |  |  |/----|`---=    |      |",
                @"      |  | C:\>_           |  |  |   ,/|==== ooo |      ;",
                @"      |  |                 |  |  |  // |(((( [33]|    ,"" ",
                @"      |  `-----------------'  |,"" .;'| |((((     |  ,""   ",
                @"      +-----------------------+  ;;  | |         |,""     ",
                @"         /_)______________(_/  //'   | +---------+       ",
                @"    ___________________________/___  `,                  ",
                @"   /  oooooooooooooooo  .o.  oooo /,   \,""-----------    ",
                @"  / ==ooooooooooooooo==.o.  ooo= //   ,`\--{)B     ,""    ",
                @" /_==__==========__==_ooo__ooo=_/'   /___________,""      ",
                @"                                                         "
            };
            //根据字符串数组初始化宽高
            Resources.GetLinesSize(lines, out int width, out int height);
            //初始化控制台
            Graphics graphics = RuntimeEngine.Construct2(ConsoleType.Default,
                                                         true, false, (short)width, (short)height, CharWidth.Single);
            //变量定义
            GraphicContainer computer  = null;
            Vector2          cursorPos = new Vector2(15, 8);
            char             c         = '\0';
            bool             __        = true;
            float            timer     = 0;
            float            interval  = 0.5f;
            int    limit   = 11;           //最多打印11个英文字符
            int    counter = 0;            //计数器
            string str     = string.Empty; //输入字符
            //键盘
            List <ConsoleKey> keyboard = new List <ConsoleKey>();

            for (int i = 48; i < 91; i++)
            {
                keyboard.Add((ConsoleKey)i);
            }
            keyboard.Add(ConsoleKey.Spacebar);
            keyboard.Add(ConsoleKey.Backspace);
            keyboard.Add(ConsoleKey.Enter);
            //指令集
            Dictionary <string, Action> commands = new Dictionary <string, Action>();

            commands.Add("exit", () => { RuntimeEngine.Exit(); });
            //开始生命周期
            RuntimeEngine.Start(
                () =>
            {
                //Start
                computer = graphics.CreatContainerByLines(lines);
                computer.SetColor(Colour.Black, Colour.White);
            },
                () =>
            {
                //Update
                timer += Time.DeltaTime;
                if (timer >= interval)
                {
                    timer = 0;
                    if (__)
                    {
                        c = '_';
                    }
                    else
                    {
                        c = '\0';
                    }
                    __ = !__;
                }
                foreach (ConsoleKey item in keyboard)
                {
                    //输入指令
                    if (item == ConsoleKey.Enter)
                    {
                        if (Input.GetKeyDown(item))
                        {
                            string lowerCase = str.ToLower();
                            if (commands.ContainsKey(lowerCase))
                            {
                                //执行命令
                                commands[lowerCase]();
                            }
                        }
                    }
                    else if (item == ConsoleKey.Backspace)
                    {
                        if (Input.GetKey(item))
                        {
                            if (counter > 0)
                            {
                                counter--;
                                //删除字符
                                str = str.Substring(0, counter);
                                //删除字符图像
                                GraphicGrid before = computer.GraphicGrids[
                                    cursorPos.Y * width + cursorPos.X];
                                before.Left = new CharInfo('\0', Colour.Black, Colour.White);
                                //光标后退一格
                                cursorPos.X--;
                            }
                        }
                    }
                    else
                    {
                        if (Input.GetKeyDown(item))
                        {
                            if (counter < limit)
                            {
                                counter++;
                                //新增字符
                                str += (char)item;
                                //新增字符图形
                                GraphicGrid before = computer.GraphicGrids[
                                    cursorPos.Y * width + cursorPos.X];
                                before.Left = new CharInfo((char)item, Colour.Black, Colour.White);
                                //光标前进一格
                                cursorPos.X++;
                            }
                        }
                    }
                }
                //设置光标
                GraphicGrid graphicGrid = computer.GraphicGrids[
                    cursorPos.Y * width + cursorPos.X];
                graphicGrid.Left = new CharInfo(c, Colour.Black, Colour.White);
                //执行渲染指令
                graphics.PreRender();
                graphics.Render();
            }
                ,
                () =>
            {
                //Destroy
            }, 30);
        }
Beispiel #7
0
        /// <summary>
        /// 创建矩形(适用于单宽与双宽模式)
        /// </summary>
        /// <param name="position">坐标</param>
        /// <param name="size">尺寸</param>
        /// <param name="borderSize">边框尺寸</param>
        /// <param name="inside">内部填充字符串</param>
        /// <param name="insideForeColor">内部填充字符串前景色</param>
        /// <param name="insideBackColor">内部填充字符串背景色</param>
        /// <param name="border">边框填充字符串</param>
        /// <param name="borderForeColor">边框填充字符串前景色</param>
        /// <param name="borderBackColor">边框填充字符串背景色</param>
        /// <param name="insideGraphicGrids">内部填充图形网格集合</param>
        /// <param name="borderGraphicGrids">边框填充图形网格集合</param>
        /// <param name="depth">深度</param>
        public void CreatRectangle
        (
            Vector2 position, Vector2 size, Vector2 borderSize,
            string inside, Colour insideForeColor, Colour insideBackColor,
            string border, Colour borderForeColor, Colour borderBackColor,
            out List <GraphicGrid> insideGraphicGrids,
            out List <GraphicGrid> borderGraphicGrids,
            uint depth = 0
        )
        {
            insideGraphicGrids = new List <GraphicGrid>();
            borderGraphicGrids = new List <GraphicGrid>();

            for (int i = 0; i < size.Y; i++)
            {
                for (int j = 0; j < size.X; j++)
                {
                    GraphicGrid graphicGrid = null;
                    Vector2     pos         = new Vector2(position.X + j, position.Y + i);

                    if (i >= 0 && i < borderSize.Y || j >= 0 && j < borderSize.X ||
                        i <= size.Y - 1 && i > size.Y - 1 - borderSize.Y ||
                        j <= size.X - 1 && j > size.X - 1 - borderSize.X)
                    {
                        if (border.Length == 1)
                        {
                            graphicGrid = CreatGrid
                                          (
                                pos,
                                new CharInfo(border[0], borderForeColor, borderBackColor),
                                depth
                                          );
                        }
                        else if (border.Length == 2)
                        {
                            graphicGrid = CreatGrid
                                          (
                                pos,
                                new CharInfo(border[0], borderForeColor, borderBackColor),
                                new CharInfo(border[1], borderForeColor, borderBackColor),
                                depth
                                          );
                        }

                        borderGraphicGrids.Add(graphicGrid);
                    }
                    else
                    {
                        if (inside.Length == 1)
                        {
                            graphicGrid = CreatGrid
                                          (
                                pos,
                                new CharInfo(inside[0], insideForeColor, insideBackColor),
                                depth
                                          );
                        }
                        else if (inside.Length == 2)
                        {
                            graphicGrid = CreatGrid
                                          (
                                pos,
                                new CharInfo(inside[0], insideForeColor, insideBackColor),
                                new CharInfo(inside[1], insideForeColor, insideBackColor),
                                depth
                                          );
                        }

                        insideGraphicGrids.Add(graphicGrid);
                    }
                }
            }
        }
Beispiel #8
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="graphicGrid">图形网格</param>
 public GraphicContainer(GraphicGrid graphicGrid)
 {
     GraphicGrids = new List <GraphicGrid> {
         graphicGrid
     };
 }
Beispiel #9
0
 /// <summary>
 /// 销毁图形网格
 /// </summary>
 /// <param name="graphicGrid">图形网格</param>
 public void DestroyGrid(GraphicGrid graphicGrid)
 {
     grids.Remove(graphicGrid);
 }
Beispiel #10
0
 /// <summary>
 /// 添加图形网格
 /// </summary>
 /// <param name="graphicGrid">图形网格</param>
 public void AddGrid(GraphicGrid graphicGrid)
 {
     grids.Add(graphicGrid);
 }