Example #1
0
        /// <summary>
        /// Creates a text layer made entirely from one character
        /// </summary>
        /// <param name="c">The character</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        public static TextLayer OneRepeatedChar(char c, int width, int height)
        {
            TextLayer tl = new TextLayer(width, height);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    tl.ChangeLetterAt(i, j, c);
                }
            }
            return(tl);
        }
Example #2
0
        /*
         * public static TextLayer TiledMap(TextMap tm, int width, int height, int xTileStart, int yTileStart) {
         *      if (xTileStart > width || yTileStart > height)
         *              throw new ArgumentOutOfRangeException ("The tiling starting points cannot be outside the size!");
         *
         *      TextLayer tl = new TextLayer (width, height);
         *      if (xTileStart != 0) {
         *              int preTileWidth = xTileStart;
         *              int remainingTileWidth = preTileWidth;
         *              int requiredMaps = (int)Math.Floor ((double)(xTileStart / tm.Width));
         *              double remainderOfMap = xTileStart % tm.Width;
         *
         *              for (int i = 0; i < requiredMaps; i++) {
         *
         *              }
         *      }
         *
         *      return null;
         * }
         */

        /// <summary>
        /// Border with specified width and height.
        /// </summary>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        public static TextLayer Border(int width, int height)
        {
            TextLayer tm = new TextLayer(width, height);

            tm.ChangeLetterAt(0, 0, '/');
            tm.ChangeLetterAt(width, 0, '\\');
            tm.ChangeLetterAt(0, height, '\\');
            tm.ChangeLetterAt(width, height, '/');

            for (int i = 1; i < width - 2; i++)
            {
                tm.ChangeLetterAt(i, 0, '‾');
                tm.ChangeLetterAt(i, height, '_');
            }

            for (int i = 0; i < height; i++)
            {
                tm.ChangeLetterAt(0, i, '|');
                tm.ChangeLetterAt(width, i, '|');
            }

            return(tm);
        }
Example #3
0
        /// <summary>
        /// Dialog with the specified width, height, dialog and charsPerLine.
        /// </summary>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        /// <param name="dialog">Dialog.</param>
        /// <param name="charsPerLine">Chars per line.</param>
        public static TextLayer Dialog(int width, int height, string dialog, int charsPerLine)
        {
            TextLayer tl             = new TextLayer(width, height);
            int       middleOfLayerX = Teolib.DivideThenFloor(width, 2);
            int       middleOfLayerY = Teolib.DivideThenFloor(height, 2);

            bool oddX = Teolib.IsNumberOdd(width);
            bool oddY = Teolib.IsNumberOdd(height);

            int requiredLines = Teolib.DivideThenCeil(dialog.Length, charsPerLine);     //Math.Ceiling (((decimal)(dialog.Length)) / (decimal)charsPerLine);
            int marginX       = Teolib.DivideThenFloor(width - charsPerLine, 2);        //Math.Floor (((decimal)(width - charsPerLine)) / 2);
            int marginY       = Teolib.DivideThenFloor(height - requiredLines, 2);      //Math.Floor (((decimal)(height - requiredLines)) / 2);

            List <string> lines           = new List <string> ();
            string        buffer          = "";
            int           currentPosition = 0;

            for (int i = 0; i < dialog.Length; i++)
            {
                buffer += dialog [i];
                currentPosition++;
                if (currentPosition + 1 >= charsPerLine || i == (dialog.Length - 1))
                {
                    lines.Add(buffer);
                    buffer          = "";
                    currentPosition = 0;
                }
            }

            currentPosition = 0;
            for (int i = marginY; i < marginY + requiredLines; i++)
            {
                string line = lines [currentPosition];
                int    start;
                int    limit;
                if (line.Length > charsPerLine)
                {
                    int requiredMargin = charsPerLine - line.Length;
                    int marginLeft;
                    int marginRight;
                    if (Teolib.IsNumberOdd(requiredMargin))
                    {
                        marginLeft  = Teolib.DivideThenFloor(requiredMargin, 2);
                        marginRight = Teolib.DivideThenCeil(requiredMargin, 2);
                    }
                    else
                    {
                        marginLeft = marginRight = requiredMargin / 2;
                    }
                    start = marginX + marginLeft;
                    limit = marginY - marginRight;
                }
                else
                {
                    start = marginX;
                    limit = marginX + charsPerLine;
                }
                int k = 0;
                for (int j = start; j < limit; j++)
                {
                    tl.ChangeLetterAt(j, i, line [k]);
                    k++;
                }
                currentPosition++;
            }

            return(tl);
        }