예제 #1
0
        public virtual void ShowStats(IHasStats of)
        {
            Console.WriteLine(of.ToString());
            Console.WriteLine("Adjectives:" + string.Join(",", of.Adjectives));

            Console.WriteLine("Stats:" + string.Join(Environment.NewLine, of.BaseStats.Select(s => s.Key.ToString() + ':' + s.Value)));

            if (of is IActor a)
            {
                Console.WriteLine("Items:" + string.Join(",", a.Items));
            }
            if (of is IRoom r)
            {
                Console.WriteLine("Items:" + string.Join(",", r.Items));
            }
        }
예제 #2
0
        void RenderLine(ConsoleDriver driver, IHasStats toRender, int col, int line, int width)
        {
            string suffix = "   ";

            //Get relation to player
            if (toRender is IActor a)
            {
                var world        = a.CurrentLocation.World;
                var relationship = world.Relationships.SumBetween(a, world.Player);

                if (relationship < -40)
                {
                    suffix = "---";
                }
                else
                if (relationship < -20)
                {
                    suffix = "-- ";
                }
                else
                if (relationship < 0)
                {
                    suffix = "-  ";
                }
                else
                if (relationship > 40)
                {
                    suffix = "+++";
                }
                else
                if (relationship > 20)
                {
                    suffix = "++ ";
                }
                else
                if (relationship > 0)
                {
                    suffix = "+  ";
                }
            }

            //allow for the suffix
            var ustring = toRender.ToString();

            ustring = ustring.Substring(0, Math.Min(ustring.Length, width - 3)) + suffix;
            ustring = ustring.PadRight(width);

            int byteLen = ustring.Length;
            int used    = 0;

            for (int i = 0; i < byteLen;)
            {
                (var rune, var size) = Utf8.DecodeRune(ustring, i, i - byteLen);
                var count = Rune.ColumnWidth(rune);
                if (used + count >= width)
                {
                    break;
                }

                if (rune == '-')
                {
                    driver.SetAttribute(_red);
                }
                else
                if (rune == '+')
                {
                    driver.SetAttribute(_green);
                }
                else
                {
                    driver.SetAttribute(_normal);
                }

                driver.AddRune(rune);
                used += count;
                i    += size;
            }
            for (; used < width; used++)
            {
                driver.AddRune(' ');
            }
        }