public XmlBoard(ListArrayOfT hexes) { _Hexes = new ListArrayOfT(hexes.Width, hexes.Height); foreach (Hex h in hexes) _Hexes.Add(h); }
/// <summary> /// Resizes the board to a new size. /// </summary> /// <param name="newWidth">New width of the board</param> /// <param name="newHeight">New height of the board</param> public void Resize(int newWidth, int newHeight, Hex defaultHex) { // default on seahexes if we have no default if (defaultHex == null) defaultHex = new SeaHex(); //return if there is nothing to resize if (_Width == newWidth && _Height == newHeight) { return; } //Instantiate a new board ListArrayOfT newboard = new ListArrayOfT(newWidth, newHeight); //loop through new sized matrix. for (int h = 0; h < newHeight; h++) { for (int w = 0; w < newWidth; w++) { //when width or height is bigger then original, add hexes if (w >= _Width || h >= _Height) { Hex newHex = null; //if outer bounds, put a SeaHex in place, otherwise a defaulthex if (w == newWidth - 1 || w == 0 || h == newHeight - 1 || h == 0) newHex = new SeaHex(); else newHex = defaultHex.Copy(); newHex.Location = new HexLocation() { W = w, H = h }; newboard[w, h] = newHex; } else { //if outer bounds, put a seahex in place, // otherwise the defaulthex if (w == newWidth - 1 || w == 0 || h == newHeight - 1 || h == 0) { newboard[w, h] = new SeaHex(); } else { newboard[w, h] = defaultHex.Copy(); } newboard[w, h] = Hexes[w, h].Copy(); } } } Hexes = newboard; }
/// <summary> /// Creates a new board with specified height and width /// </summary> /// <param name="width"></param> /// <param name="height"></param> public XmlBoard(int width, int height) : this() { _Width = width; _Height = height; _Hexes = new ListArrayOfT(width, height); // Default empty board is filled with seahexes for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) _Hexes.Add(new SeaHex() { Location = new HexLocation() { W = w, H = h } }); }