public void CreateUnit(Tile tile) { Unit unit = new Unit(); unit.X = tile.X; unit.Y = tile.Y; unit.Player = this; tile.Unit = unit; unit.Tile = tile; Units.Add(unit); }
public void CreateBasicMap(int width, int length) { Random rand = new Random(); Console.WriteLine("Creating map {0} wide by {1} long", width, length); Tiles = new List<List<Tile>>(); for (int y = 0; y < length; y++) { List<Tile> list = new List<Tile>(); for (int x = 0; x < width; x++) { Tile tile = new Tile(x, y); if (rand.NextDouble() > 0.7) tile.IsWall = true; list.Add(tile); } Tiles.Add(list); } }
public void MoveUnit(Unit unit, Tile tile) { unit.Tile.Unit = null; unit.X = tile.X; unit.Y = tile.Y; tile.Unit = unit; unit.Tile = tile; }
public void MoveShot(Shot shot, Tile tile) { shot.Tile.Shot = null; shot.X = tile.X; shot.Y = tile.Y; tile.Shot = shot; shot.Tile = tile; }
public void LoadMap(MapSetup setup) { string mapfile = setup.MapFile; List<List<string>> data = Tools.ReadDelimitedFile(mapfile, ','); Data.Map.Tiles.Clear(); for (int y = 0; y < data.Count; y++) { List<string> strdata = data[y]; List<Tile> list = new List<Tile>(); for (int x = 0; x < strdata.Count; x++) { string code = strdata[x]; Tile tile = null; if (code == null || code == "") { tile = new Tile(x, y); } else if (code[0] == ' ') { tile = new Tile(x, y); } else if (code[0] == 'x') { tile = new Tile(x, y); tile.IsWall = true; } else if (code[0] == 'U') { tile = new Tile(x, y); int playernum = int.Parse(code[1].ToString()) - 1; if (Data.PlayerDict.Keys.Contains(playernum)) Data.PlayerDict[playernum].CreateUnit(tile); } else { tile = new Tile(x, y); Console.WriteLine("Unknown tile type, set as empty"); } list.Add(tile); } Data.Map.Tiles.Add(list); } }