private void addNewBlock(Block b, int arrayLocX, int arrayLocY) { //adds a new block to the target grid and adds it to the array blockArray[arrayLocX, arrayLocY] = b; targetGrid.Children.Add(blockArray[arrayLocX, arrayLocY]); }
public void PlaceBlock(Type newBlockType, Block target) { if (player.Cargo < player.CargoBayCapacity || target.GetType() == typeof(Block_dirt) || target.GetType() == typeof(Block_stone) || target.GetType() == typeof(Block_air)) { //places a block of a specified type at a specified location. if (target.penetrable || newBlockType == typeof(Block_air)) { int[] blockArrayLoc = (Engine.GetArrayLocation(target.Margin.Left, target.Margin.Top)); //replace block in worldarray and grid targetGrid.Children.Remove(target); blockArray[blockArrayLoc[0], blockArrayLoc[1]] = (Block)Engine.GetNewBlock_ofType(newBlockType); blockArray[blockArrayLoc[0], blockArrayLoc[1]].setPosition(new Point(blockArrayLoc[0] * 25, blockArrayLoc[1] * 25)); targetGrid.Children.Add(blockArray[blockArrayLoc[0], blockArrayLoc[1]]); Canvas.SetZIndex(blockArray[blockArrayLoc[0], blockArrayLoc[1]], 10); if (newBlockType == typeof(Block_air)) { blockArray[blockArrayLoc[0], blockArrayLoc[1]].penetrable = true; } } } if (target.GetType() != typeof(Block_dirt) && target.GetType() != typeof(Block_stone) && target.GetType() != typeof(Block_air) && player.Cargo < player.CargoBayCapacity) { player.Cargo += 1; } }