/// <summary> /// Initialize a new instance of <see cref="Game"/> with map from file with specified path and specified <see cref="IMapWriter"/>. /// </summary> /// <param name="path">Specified path of a resource file.</param> /// <param name="mapWriter">Specified <see cref="IMapWriter"/></param> /// <returns>New instance of <see cref="Game"/></returns> /// <exception cref="InvalidMapException">The map has an incorrect format.</exception> public static Game LoadGameWithSpecifiedMapWriterFromFile(string path, IMapWriter mapWriter) { var fileData = GetFileData(path).Split(new[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); var characterWasAdded = false; (int x, int y)characterPosition = (0, 0); var map = new List <Cell> [fileData.Length]; for (var i = 0; i < map.Length; i++) { map[i] = new List <Cell>(); } for (var x = 0; x < fileData.Length; x++) { for (var y = 0; y < fileData[x].Length; y++) { if (Enum.TryParse <Cell>(((int)fileData[x][y]).ToString(), out var cell)) { if (Enum.IsDefined(typeof(Cell), cell)) { if (cell == Cell.Character) { if (characterWasAdded) { throw new InvalidMapException("There are several characters."); } characterWasAdded = true; characterPosition = (x, y); map[x].Add(Cell.FreeSpace); } else { map[x].Add(cell); } } else { throw new InvalidMapException("There is unfamiliar symbol."); } } else { throw new InvalidMapException("There is unfamiliar symbol."); } } } if (!characterWasAdded) { throw new InvalidMapException("There is no character."); } return(new Game(map, characterPosition, mapWriter)); }
public void Generating(ITableReader tableReader, IClassWriter classWriter, IClassLogicWriter classLogicWriter, IMapWriter mapWriter) { tableReader.Close(); classWriter.ClearProperty(); mapWriter.ClearItem(); if (classLogicWriter != null) { classLogicWriter.ClearProperty(); } string className = FileMedia.ENTITY_CLASS_PRE + Misc.GetPublicName(tableReader.TableName); classWriter.NameSpace = _nameSpace; classWriter.ClassName = className; if (classLogicWriter != null) { classLogicWriter.ClassNameSpace = _nameSpace; classLogicWriter.ClassName = className; classLogicWriter.ClassLogicNameSpace = _logicNameSpace; classLogicWriter.ClassLogicName = className + "Helper"; } mapWriter.ClassName = string.Format("{0}.{1}", _nameSpace, className); mapWriter.AssemblyName = _assemblyName; mapWriter.TableName = tableReader.TableName; try { tableReader.Open(); while (tableReader.Read()) { TableColumn tableColumn = tableReader.CurrentColumn().Value; string propertyName = Misc.GetPublicName(tableColumn.Name); classWriter.AppendProperty(propertyName, tableColumn, tableColumn.DotNetType); if (classLogicWriter != null) { classLogicWriter.AppendProperty(propertyName, tableColumn.DotNetType, tableColumn.IsKey); } mapWriter.AppendItem(new MapItem(propertyName, tableColumn.Name, tableColumn.DatabaseType, tableColumn.IsKey, tableColumn.CanBeNull, tableColumn.MaxLength, true, true)); } classWriter.WriteOut(); if (classLogicWriter != null) { classLogicWriter.WriteOut(); } mapWriter.WriteOut(); } finally { tableReader.Close(); } }
public void Setup() { _mapWriter = A.Fake <IMapWriter>(); }