public void displayGrid(GridEntity[,] grid) { for (int i = 0; i < mapSize; i++) { for (int j = 0; j < mapSize; j++) { Console.Write(grid[i, j].getName()); } Console.WriteLine(); } Console.WriteLine(); }
private void setLocations(string map, GridEntity[,] grid) { string[] splittedValues = map.Split(':'); setLocationLists(splittedValues[2], "brick", grid); setLocationLists(splittedValues[3], "stone", grid); setLocationLists(splittedValues[4], "water", grid); }
private void setLocationLists(string values, string type, GridEntity[,] grid) { Point p; string[] tokens = values.Split(';'); for (int i = 0; i < tokens.Length; i++) { p = new Point(int.Parse(tokens[i].Split(',')[0]), int.Parse(tokens[i].Split(',')[1])); try { if (type.Equals("brick")) { //Brick b = new Brick(p); grid[p.Y, p.X] = new Brick(p); //locations.Add(new Brick(p)); } else if (type.Equals("stone")) { grid[p.Y, p.X] = new Stone(p); //Stone b = new Stone(p); //locations.Add(new Stone(p)); } else if (type.Equals("water")) { grid[p.Y, p.X] = new Water(p); //Water b = new Water(p); //locations.Add(new Water(p)); } } catch (NullReferenceException) { //Console.WriteLine("exception"); } } }
private void handleLifePacks(string msg, GridEntity[,] grid) { string[] tokens = msg.Split(':'); Point p = new Point(int.Parse(tokens[1].Split(',')[0]), int.Parse(tokens[1].Split(',')[1])); grid[p.Y, p.X] = new LifePack(p, int.Parse(tokens[2]), 0); //coinLocations.Add(p); //LifePack lifepack = new LifePack(p, int.Parse(tokens[2]), 0); }
private void handleCoins(string msg, GridEntity[,] grid) { string[] tokens = msg.Split(':'); Point p = new Point(int.Parse(tokens[1].Split(',')[0]), int.Parse(tokens[1].Split(',')[1])); grid[p.Y, p.X] = new CoinPile(p, int.Parse(tokens[2]), 0, int.Parse(tokens[3])); //coinLocations.Add(p); //CoinPile coins = new CoinPile(p, int.Parse(tokens[2]), 0, int.Parse(tokens[3])); }
private void generateGrid(string map) { this.mapSize = 10; //brickLocations = new List<Brick>(); //stoneLocations = new List<Stone>(); //waterLocations = new List<Water>(); //coinLocations = new List<CoinPile>(); grid = new GridEntity[mapSize, mapSize]; for (int i = 0; i < mapSize; i++) { for (int j = 0; j < mapSize; j++) { grid[i, j] = new GridEntity(new Point(j, i)); } //Console.WriteLine(); } setLocations(map, grid); displayGrid(grid); }