Esempio n. 1
0
 private void LoadLands()
 {
     if (!mapFile.Equals(""))
     {
         string path  = Directory.GetParent(mapFile).ToString();
         string lfile = path + "\\Land";
         if (File.Exists(lfile))
         {
             lands.Clear();
             StreamReader sr = new StreamReader(lfile);
             while (!sr.EndOfStream)
             {
                 string line = sr.ReadLine();
                 int    x    = 0;
                 int    y    = 0;
                 char   c    = '\0';
                 string name = "";
                 int    idx  = line.IndexOf(',');
                 if (idx > -1)
                 {
                     y    = Convert.ToInt32(line.Substring(0, idx));
                     line = line.Substring(idx + 1);
                 }
                 idx = line.IndexOf('\t');
                 if (idx > -1)
                 {
                     x    = Convert.ToInt32(line.Substring(0, idx));
                     line = line.Substring(idx + 1);
                 }
                 c    = Convert.ToChar(line.Substring(0, 1));
                 name = line.Substring(2).Trim();
                 Land l = new Land(x, y, c, name);
                 lands.Add(l);
             }
             sr.Close();
             lbLands.Items.Clear();
             lbLands.Items.AddRange(lands.ToArray());
         }
     }
 }
Esempio n. 2
0
        private void PlaceLand(int x, int y)
        {
            Land   l   = (Land)lbLands.SelectedItem;
            MapTag tag = new MapTag(l.Name, TagType.Land);
            // Add new tag to tiles
            Coord xy = new Coord(x, y);

            tiles[xy].Tags.Add(tag);
            foreach (Land land in lands)
            {
                if (land.Equals(l))
                {
                    land.X = x;
                    land.Y = y;
                    land.C = tiles[xy].C;
                    break;
                }
            }
            UpdateLandList();
            map.Refresh();
            state = State.MovingLand;
        }