Exemplo n.º 1
0
        public override string ToString()
        {
            StringBuilder sBuilder = new StringBuilder();

            for (int y = 0; y < buffer.GetLength(1); y++)
            {
                byte lastBgColor = 0;
                byte lastFgColor = 0;
                for (int x = 0; x < buffer.GetLength(0); x++)
                {
                    var d = buffer[x, y];

                    if (d != null)
                    {
                        bool printProperties = (x == 0 || lastBgColor != d.Background || lastFgColor != d.Foreground);

                        if (printProperties)
                        {
                            lastBgColor = d.Background;
                            lastFgColor = d.Foreground;

                            string escSequence = "";
                            if (NumOfColors == NumOfColorsEnum.XTERM256)
                            {
                                escSequence = ANSI.SetColor256(d.Foreground, d.Background);
                            }
                            else if (NumOfColors == NumOfColorsEnum.ANSI)
                            {
                                escSequence = ANSI.ColorANSI16(
                                    (ANSI.ANSIColor_16)FANSI.Color256To16(d.Foreground, false),
                                    (ANSI.ANSIColor_8)FANSI.Color256To16(d.Background, true)
                                    );
                            }
                            sBuilder.Append(escSequence);
                        }

                        sBuilder.Append(d.Char);
                    }
                    else
                    {
                        sBuilder.Append(this.FillChar);
                    }
                }

                sBuilder.AppendFormat("{0}\r\n", ANSI.ClearFormat());
            }

            sBuilder.Append(ANSI.ClearFormat());

            return(sBuilder.ToString());
        }
Exemplo n.º 2
0
        public void SendMessage(string message)
        {
            player.AcquireSendDataLock();
            try {
                player.SendLine("{0}{1}{0} {2}",
                                ANSI.SetColorANSI16("-", ANSI.ANSIColor_16.BrightYellow),
                                ANSI.SetColorANSI16("♦", ANSI.ANSIColor_16.White),
                                ANSI.SetColorANSI16(message, messageColor));

                //player.SendLine(string.Format("{0}", message));
                System.Threading.Thread.Sleep(500);
            } finally {
                player.ReleaseSendDataLock();
            }
        }
Exemplo n.º 3
0
        public static string GetStatusString(SpaceShip ship)
        {
            string baseStatus = "► {2}: H {0} E {1}";

            ANSI.ANSIColor_16 energyColor;
            ANSI.ANSIColor_16 hullColor;

            if (ship.Hull > 50)
            {
                hullColor = ANSI.ANSIColor_16.Green;
            }
            else if (ship.Hull > 25)
            {
                hullColor = ANSI.ANSIColor_16.DarkYellow;
            }
            else
            {
                hullColor = ANSI.ANSIColor_16.Red;
            }

            if (ship.Energy > 50)
            {
                energyColor = ANSI.ANSIColor_16.Green;
            }
            else if (ship.Energy > 25)
            {
                energyColor = ANSI.ANSIColor_16.DarkYellow;
            }
            else
            {
                energyColor = ANSI.ANSIColor_16.Red;
            }

            string hullValue =
                ANSI.ColorANSI16(hullColor) +
                string.Empty.PadLeft(ship.Hull * 10 / 100, '■').PadLeft(10) +
                ANSI.ClearFormat();

            string energyValue =
                ANSI.ColorANSI16(energyColor) +
                string.Empty.PadLeft(ship.Energy * 10 / 100, '■').PadLeft(10) +
                ANSI.ClearFormat();

            return(string.Format(baseStatus, hullValue, energyValue, ship.Code));
        }
Exemplo n.º 4
0
        public void SendFailMessage(string message, string status)
        {
            player.AcquireSendDataLock();
            try {
                player.SendFormat("{0}{1}{0} {2}",
                                  ANSI.SetColorANSI16("-", ANSI.ANSIColor_16.BrightCyan),
                                  ANSI.SetColorANSI16("♦", ANSI.ANSIColor_16.White),
                                  ANSI.SetColorANSI16(message.PadRight(60), messageColor));

                System.Threading.Thread.Sleep(100);
                player.SendFormat("{2}[ {0}{1}{2} ]\r\n",
                                  ANSI.ColorANSI16(ANSI.ANSIColor_16.Red),
                                  status,
                                  ANSI.ClearFormat()
                                  );
                System.Threading.Thread.Sleep(500);
            } finally {
                player.ReleaseSendDataLock();
            }
        }
Exemplo n.º 5
0
        public void SendCountDownMessage(string message, string status, int steps, int stepTime, bool showNumbers)
        {
            player.AcquireSendDataLock();
            try {
                int messageLenght = message.Length;

                player.SendFormat("{0}{1}{0} {2}",
                                  ANSI.SetColorANSI16("-", ANSI.ANSIColor_16.BrightRed),
                                  ANSI.SetColorANSI16("♦", ANSI.ANSIColor_16.White),
                                  ANSI.SetColorANSI16(message, messageColor));

                for (int i = 0; i <= steps; i++)
                {
                    System.Threading.Thread.Sleep(stepTime);
                    if (showNumbers)
                    {
                        player.SendFormat("{0} ",
                                          ANSI.SetColorANSI16((steps - i).ToString(), ANSI.ANSIColor_16.BrightCyan));
                        messageLenght += 2;
                    }
                    else
                    {
                        player.SendFormat(ANSI.SetColorANSI16(".", ANSI.ANSIColor_16.BrightCyan));
                        messageLenght++;
                    }
                }

                player.SendFormat("{3}{2}[ {0}{1}{2} ]\r\n",
                                  ANSI.ColorANSI16(ANSI.ANSIColor_16.Green),
                                  status,
                                  ANSI.ClearFormat(),
                                  "".PadRight(60 - messageLenght)
                                  );
                System.Threading.Thread.Sleep(500);
            } finally {
                player.ReleaseSendDataLock();
            }
        }
Exemplo n.º 6
0
        private void GetPlanetSectorString(SystemBody.PlanetSectorType sector, StringBuilder zoneBuilder)
        {
            bool isRetricted = (sector & SystemBody.PlanetSectorType.Restricted) == SystemBody.PlanetSectorType.Restricted;
            bool hasStarPort = (sector & SystemBody.PlanetSectorType.StarPort) == SystemBody.PlanetSectorType.StarPort;

            bool isGaz          = (sector & SystemBody.PlanetSectorType.Gaz) == SystemBody.PlanetSectorType.Gaz;
            bool isRock         = (sector & SystemBody.PlanetSectorType.Rock) == SystemBody.PlanetSectorType.Rock;
            bool isLand         = (sector & SystemBody.PlanetSectorType.Land) == SystemBody.PlanetSectorType.Land;
            bool isLava         = (sector & SystemBody.PlanetSectorType.Lava) == SystemBody.PlanetSectorType.Lava;
            bool isWater        = (sector & SystemBody.PlanetSectorType.Water) == SystemBody.PlanetSectorType.Water;
            bool isIce          = (sector & SystemBody.PlanetSectorType.Ice) == SystemBody.PlanetSectorType.Ice;
            bool isUnclassified = (sector & SystemBody.PlanetSectorType.Unclassified) == SystemBody.PlanetSectorType.Unclassified;

            zoneBuilder.AppendFormat("{0}[{1}", ANSI.ColorANSI16((isRetricted) ? ANSI.ANSIColor_16.Red : ANSI.ANSIColor_16.Cyan), ANSI.ClearFormat());

            if (hasStarPort)
            {
                zoneBuilder.AppendFormat("{0}{{P}}{1}", ANSI.ColorANSI16(ANSI.ANSIColor_16.Green), ANSI.ClearFormat());
            }
            else
            {
                if (isGaz)
                {
                    zoneBuilder.AppendFormat("{0}%%%{1}",
                                             ANSI.ColorANSI16(ANSI.ANSIColor_16.Magenta),
                                             ANSI.ClearFormat());
                }
                if (isRock)
                {
                    zoneBuilder.AppendFormat("{0}###{1}",
                                             ANSI.ColorANSI16(ANSI.ANSIColor_16.Darkgray),
                                             ANSI.ClearFormat());
                }
                if (isLand)
                {
                    zoneBuilder.AppendFormat("{0}###{1}",
                                             ANSI.ColorANSI16(ANSI.ANSIColor_16.Green),
                                             ANSI.ClearFormat());
                }
                if (isLava)
                {
                    zoneBuilder.AppendFormat("{0}%%%{1}",
                                             ANSI.ColorANSI16(ANSI.ANSIColor_16.Red),
                                             ANSI.ClearFormat());
                }
                if (isWater)
                {
                    zoneBuilder.AppendFormat("{0}%%%{1}",
                                             ANSI.ColorANSI16(ANSI.ANSIColor_16.Blue),
                                             ANSI.ClearFormat());
                }
                if (isIce)
                {
                    zoneBuilder.AppendFormat("{0}###{1}",
                                             ANSI.ColorANSI16(ANSI.ANSIColor_16.White),
                                             ANSI.ClearFormat());
                }
                if (isUnclassified)
                {
                    zoneBuilder.AppendFormat("{0}%%%{1}",
                                             ANSI.ColorANSI16(ANSI.ANSIColor_16.BrightYellow),
                                             ANSI.ClearFormat());
                }
            }

            zoneBuilder.AppendFormat("{0}]{1}", ANSI.ColorANSI16((isRetricted) ? ANSI.ANSIColor_16.Red : ANSI.ANSIColor_16.Cyan), ANSI.ClearFormat());
            //return zoneBuilder.ToString();
        }
Exemplo n.º 7
0
        public string GetInfo()
        {
            string baseDir  = "./Messages/Planets";
            string filename = string.Empty;

            switch (Planet.BodyType)
            {
            case SystemBodyType.Asteroid: filename = "AS.MII"; break;

            case SystemBodyType.RockyWorld: filename = "R.MII"; break;

            case SystemBodyType.RockyPlanetoid: filename = "R2.MII"; break;

            case SystemBodyType.Inferno: filename = "I.MII"; break;

            case SystemBodyType.Venuzian: filename = "V.MII"; break;

            case SystemBodyType.Terrestrial: filename = "T.MII"; break;

            case SystemBodyType.WaterWorld: filename = "W.MII"; break;

            case SystemBodyType.IceWorld: filename = "W2.MII"; break;

            case SystemBodyType.GasGiant: filename = "GS.MII"; break;

            case SystemBodyType.RingedGasGiant: filename = "GS2.MII"; break;

            case SystemBodyType.SubGasGiant: filename = "GS3.MII"; break;

            default: filename = "R.MII"; break;
            }


            //get the star ansi image;
            filename = Path.Combine(baseDir, filename);
            var starFile = Messages.Message.ReadMII2File(filename);

            TextCanvas canvas = new TextCanvas(screenWidth, starFile.Height, TextCanvas.NumOfColorsEnum.XTERM256);

            starFile.Write(0, 0, canvas);

            canvas.DrawString(40, canvas.Height - 5, string.Format("Planet: {0}", Planet.Name), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(40, canvas.Height - 4, string.Format("Planet class: {0}", Planet.GetClass_Ext()), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(40, canvas.Height - 3, string.Format("Orbital period: {0} Earth years", Planet.OrbitalPeriod), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(40, canvas.Height - 2, string.Format("Orbital radius: {0:0.000} AU", Planet.OrbitalRadius), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(40, canvas.Height - 1, string.Format("Surface Temperature: {0:0.0}°", Planet.Temperature), (byte)ANSI.ANSIColor_16.Cyan, 0);


            StringBuilder sBuilder = new StringBuilder();

            sBuilder.AppendLine(canvas.ToString());
            //sBuilder.AppendLine(WrapString(Planet.Description));

            sBuilder.AppendFormat("\r\n");
            sBuilder.AppendFormat(ANSI.SetColorANSI16("Surface sectors:\r\n", ANSI.ANSIColor_16.BrightCyan));

            char lineChar = 'A';

            for (int y = 0; y < Planet.PlanetSector.GetLength(1); y++)
            {
                if (y == 0)
                {
                    sBuilder.Append("  ");
                    sBuilder.Append(ANSI.ColorANSI16(ANSI.ANSIColor_16.BrightCyan));
                    for (int x = 0; x < Planet.PlanetSector.GetLength(0); x++)
                    {
                        sBuilder.AppendFormat("  {0,-2} ", x + 1);
                    }
                    sBuilder.Append(ANSI.ClearFormat());
                    sBuilder.AppendFormat("\r\n");
                }

                sBuilder.Append(ANSI.SetColorANSI16(string.Format("{0,-2}", lineChar), ANSI.ANSIColor_16.BrightCyan)); lineChar++;
                for (int x = 0; x < Planet.PlanetSector.GetLength(0); x++)
                {
                    GetPlanetSectorString(Planet.PlanetSector[x, y], sBuilder);
                }

                sBuilder.AppendFormat("\r\n");
            }

            sBuilder.AppendFormat(ANSI.SetColorANSI16("\r\nSpace Ports / Stations: ", ANSI.ANSIColor_16.BrightCyan));
            sBuilder.AppendFormat("{0}\r\n", (Planet.SpacePort.Count > 0) ? "" : ANSI.SetColorANSI16("None", ANSI.ANSIColor_16.Cyan));
            foreach (var s in Planet.SpacePort)
            {
                sBuilder.AppendFormat("{3}[{4}{0}{3}] {4}{1,-30}{3} Sector: {4}{2}{5}\r\n",
                                      s.Id, s.Name, s.PlanetSector,
                                      ANSI.ColorANSI16(ANSI.ANSIColor_16.Cyan),
                                      ANSI.ColorANSI16(ANSI.ANSIColor_16.BrightCyan),
                                      ANSI.ClearFormat()
                                      );
            }

            return(sBuilder.ToString());
        }