/// <summary> /// Sets dimensions for the crossword. /// </summary> /// <param name="columns">Number of crossword columns.</param> /// <param name="rows">Numer of crossword rows.</param> public void SetDimensions(int columns, int rows) { _columns = columns; _rows = rows; if (_letters != null) { LoggerSAP.Log("Array of letter not empty. Deleting it."); } LoggerSAP.Log("Allocating new array of base crossword elements."); _letters = new BaseCrosswordElement[_columns, _rows]; }
/// <summary> /// Default implementation reads crossword dimensions (type is already known by CrosswordLoader, who used factory method /// to create appropriate crossword type). Then it deserializes all elements, by calling their appropriate deserializers /// (using factory method from ElementsFactory). /// Override it, if your derived crossword type requires to read specific information that was serialized. /// </summary> /// <param name="myNode">Node from disk file, containing serialized information about this crossword.</param> virtual public void DeserializeFromNode(System.Xml.XmlNode myNode) { int columns = int.Parse(myNode.Attributes["columns"].Value); int rows = int.Parse(myNode.Attributes["rows"].Value); SetDimensions(columns, rows); foreach (XmlNode element in myNode.SelectNodes("elements/crosswordItem")) { BaseCrosswordElement bce = RecreateElementFromXmlNode(element, this); } }
private static BaseCrosswordElement RecreateElementFromXmlNode(XmlNode element, Crossword loadedObject) { string type = element.Attributes["type"].Value; int column = int.Parse(element.Attributes["column"].Value); int row = int.Parse(element.Attributes["row"].Value); BaseCrosswordElement bce = ElementsFactory.SAP.CreateObject(type, loadedObject, column, row); bce.DeserializeFromNode(element); loadedObject.SubstituteCrosswordElement(bce, column, row); return(bce); }
/// <summary> /// Replaces and redraws the element at the specified location. /// </summary> /// <param name="bce">Replacing element (new).</param> /// <param name="column">Location column.</param> /// <param name="row">Location row.</param> public void SubstituteCrosswordElement(BaseCrosswordElement bce, int column, int row) { if (_letters[column, row] != null) { _letters[column, row].RemoveWindowsControl(); } _letters[column, row] = bce; if (_parent != null) { bce.Draw(_parent.DisplayRectangle.Left + column * letterWidth, _parent.DisplayRectangle.Top + row * letterHeight, _parent); } }