NRailroad CreateRailroad(string name, int purchasePrice, int initToll,
                             Vector3 pos, Quaternion rotation, float scale)
    {
        NRailroad railroad = CreateSpace(_spaceTypes["railroad"], pos, rotation, scale) as NRailroad;

        // Set the text
        TextMesh textMesh = railroad.GetComponentInChildren <TextMesh>();

        textMesh.text = name;

        // Set the color


        // set owner marker position
        Vector3 omp = pos + Quaternion.AngleAxis(railroad.gameObject.transform.rotation.eulerAngles.z, Vector3.forward) * ownerMarkerOffset;

        railroad.OwnerMarkerPos = omp;

        railroad.Initialize(name, _properties.Count, purchasePrice, initToll, railroadBgColor, mortgageBgColor);
        return(railroad);
    }
 public void Initialize(NRailroad railroad)
 {
     textRailroadName.text  = railroad.PropertyName;
     textPurchasePrice.text = "$" + railroad.PurchasePrice.ToString();
 }
    public void LoadMap(string fileName)
    {
        XDocument xdoc;

        xdoc = XDocument.Load("Assets/StreamingAssets/Maps/" + fileName);
        XElement root  = xdoc.Root;
        var      items = root.Elements("space");

        Vector3    pos = startPos;
        Vector3    increment = new Vector3(), squareIncrement = new Vector3();
        Quaternion rot = Quaternion.identity;

        int edge = 0;

        foreach (XElement item in items)
        {
            string type = item.Attribute("type").Value;
            if (type == "go" || type == "jail" || type == "parking" || type == "gotojail")
            { // TO-DO: algorithm needs improving :(
                // making some parameters
                int a = edge % 2, b = (edge + 1) % 2;
                int c = 0, d = 0;
                if (edge == 0 || edge == 3)
                {
                    c = -1;
                }
                else
                {
                    c = 1;
                }
                if (edge == 1)
                {
                    d = -1;
                }
                else
                {
                    d = 1;
                }

                // position offset
                if (edge > 0)
                {
                    pos += new Vector3(a * d * (spaceHeight - spaceWidth) / 2 * scale, b * d * (spaceHeight - spaceWidth) / 2 * scale, 0);
                }

                // Create the square space
                _spaces.Add(CreateSpace(_spaceTypes[type], pos, Quaternion.identity, scale));

                // calculating increments for the next edge
                increment       = new Vector3(b * c * spaceWidth * scale, a * c * spaceWidth * scale, 0);
                squareIncrement = new Vector3(b * c * (spaceHeight + spaceWidth) / 2 * scale, a * c * (spaceHeight + spaceWidth) / 2 * scale, 0);

                pos += squareIncrement;
                rot  = Quaternion.Euler(0, 0, (4 - edge) * 90);
                edge++;
            }
            else
            {
                if (type == "land")
                {
                    string pName = item.Element("name").Value;
                    Color  gpColor;
                    ColorUtility.TryParseHtmlString(item.Element("group").Value, out gpColor);
                    int      pPrice    = int.Parse(item.Element("purchasePrice").Value);
                    int      uPrice    = int.Parse(item.Element("upgradePrice").Value);
                    int[]    tolls     = new int[6];
                    XElement tollItems = item.Element("toll");
                    for (int i = 0; i <= 5; i++)
                    {
                        tolls[i] = int.Parse(tollItems.Element("lvl" + i).Value);
                    }
                    NLand newLand = CreateLand(pName, pPrice, uPrice, tolls, gpColor, pos, rot, scale);
                    _spaces.Add(newLand);
                    _properties.Add(newLand);
                    if (!groups.ContainsKey(gpColor))
                    {
                        List <NLand> landList = new List <NLand>();
                        landList.Add(newLand);
                        groups.Add(gpColor, landList);
                    }
                    else
                    {
                        groups[gpColor].Add(newLand);
                    }
                }
                else if (type == "railroad")
                {
                    string    name        = item.Element("name").Value;
                    int       pPrice      = int.Parse(item.Element("purchasePrice").Value);
                    int       initToll    = int.Parse(item.Element("initialToll").Value);
                    NRailroad newRailroad = CreateRailroad(name, pPrice, initToll, pos, rot, scale);
                    _spaces.Add(newRailroad);
                    _properties.Add(newRailroad);
                }
                else if (type == "spinner" || type == "chest" || type == "chance" || type == "parkingfee")
                {
                    _spaces.Add(CreateSpace(_spaceTypes[type], pos, rot, scale));
                }
                pos += increment;
            }
            numSpaces++;
        }
    }