コード例 #1
0
ファイル: Location.cs プロジェクト: polytronicgr/GalaxyE
        public GameLocation(string locationCode, bool isBase36)
        {
            string[] tokens = locationCode.Split('.');

            this.Sector     = null;
            this.StarSystem = null;
            this.SystemBody = null;

            if (tokens.Length >= 2)
            {
                uint sX = 0, sY = 0;

                if (isBase36)
                {
                    sX = (uint)Base36.Decode(tokens[0]);
                    sY = (uint)Base36.Decode(tokens[1]);
                }
                else
                {
                    uint.TryParse(tokens[0], out sX);
                    uint.TryParse(tokens[1], out sY);
                }

                this.Sector = new Sector(sX, sY);
            }

            if (tokens.Length >= 3)
            {
                int systemNum;

                if (isBase36)
                {
                    systemNum = (int)Base36.Decode(tokens[2]);
                }
                else
                {
                    int.TryParse(tokens[2], out systemNum);
                }

                if (this.Sector.Systems.Count > systemNum)
                {
                    this.StarSystem = this.Sector.Systems[systemNum];
                }
                else
                {
                    this.StarSystem = StarSystem.GetStarSystem(this.Sector, systemNum);
                }
            }

            if (tokens.Length >= 4)
            {
                int systemBodyId;

                if (isBase36)
                {
                    systemBodyId = (int)Base36.Decode(tokens[3]);
                }
                else
                {
                    int.TryParse(tokens[3], out systemBodyId);
                }

                if (this.StarSystem.SystemBodies.Length > systemBodyId)
                {
                    this.SystemBody = this.StarSystem.SystemBodies[systemBodyId];
                }
                else
                {
                    this.SystemBody = new SystemBody(StarSystem, systemBodyId);
                }
            }

            if (tokens.Length >= 5)
            {
                this.PlanetSector = tokens[4];
            }

            if (tokens.Length >= 6)
            {
                this.Zone = tokens[5];
            }
        }
コード例 #2
0
ファイル: Coords.cs プロジェクト: polytronicgr/GalaxyE
        public static bool TryParse(string value, out Coords coords, bool isBase36)
        {
            string[] mainTokens = value.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

            uint sectorIndexX = 0;
            uint sectorIndexY = 0;
            int  sX = 0, sY = 0, sZ = 0;

            coords = new Coords(0, 0, 0, 0, 0);

            if (mainTokens.Length == 0)
            {
                return(false);
            }

            string[] sectorTokens = mainTokens[0].Split('.');

            if (sectorTokens.Length != 2)
            {
                return(false);
            }
            else
            {
                if (isBase36)
                {
                    sectorIndexX = (uint)Base36.Decode(sectorTokens[0]);
                }
                else if (!uint.TryParse(sectorTokens[0], out sectorIndexX))
                {
                    return(false);
                }

                if (isBase36)
                {
                    sectorIndexY = (uint)Base36.Decode(sectorTokens[1]);
                }
                else if (!uint.TryParse(sectorTokens[1], out sectorIndexY))
                {
                    return(false);
                }
            }

            if (mainTokens.Length > 1)
            {
                string[] systemTokens = mainTokens[1].Split('.');
                if (systemTokens.Length >= 3)
                {
                    if (isBase36)
                    {
                        sX = (int)Base36.Decode(systemTokens[0]);
                    }
                    else if (!int.TryParse(systemTokens[0], out sX))
                    {
                        return(false);
                    }
                    if (isBase36)
                    {
                        sY = (int)Base36.Decode(systemTokens[1]);
                    }
                    else if (!int.TryParse(systemTokens[1], out sY))
                    {
                        return(false);
                    }
                    if (isBase36)
                    {
                        sZ = (int)Base36.Decode(systemTokens[2]);
                    }
                    else if (!int.TryParse(systemTokens[2], out sZ))
                    {
                        return(false);
                    }
                }
            }

            coords = new Coords(sectorIndexX, sectorIndexY, sX, sY, sZ);
            return(true);
        }