private string GetMapAreaTitle(Character player, Map map) { var activeTile = map.GetPositionValue(player.Position); var item = player.VisibleItems.FirstOrDefault(i => i.XPos == player.XPos && i.YPos == player.YPos); if (item != null) { return string.Format("{0}/{1} ({2},{3})", map.Name, item.Name, player.XPos, player.YPos); } var roomId = (activeTile & (uint) TileFlags.ROOM_ID); if (roomId > 0) { return string.Format("{0}/{1} ({2},{3})", map.Name, roomId, player.XPos, player.YPos); } return string.Format("{0} ({1},{2})", map.Name, player.XPos, player.YPos); }
private ConsoleArea UpdateMapArea(Map map, Character player, IEnumerable<Position> otherPositionsToRedraw) { if (!_maps.ContainsKey(map.Name)) { _maps[map.Name] = CreateMapArea(map); } else { FillArea(map, _maps[map.Name], player.VisibleArea.Concat(otherPositionsToRedraw)); } var mapArea = _maps[map.Name]; var goalForPlayer = _context.GetGoalForPlayer(player.Id); if (goalForPlayer != null) { var tile = GetTile(map.GetPositionValue(goalForPlayer)); mapArea.Write(tile.Character, goalForPlayer.X, goalForPlayer.Y, ConsoleColor.Green, ConsoleColor.DarkGreen); } player.VisibleItems.ToList().ForEach(item => DrawItem(item, mapArea)); player.VisibleEntities.ToList().ForEach(item => DrawEntity(item, mapArea)); DrawPlayer(player.Id, player.XPos, player.YPos, mapArea); mapArea.SetTitle(GetMapAreaTitle(player, map)); mapArea.CenterOffset(player.XPos, player.YPos); return mapArea; }
private string GetDebugInfo(Character player, Map map) { var positionValue = (TileFlags)map.GetPositionValue(player.Position); var debug = string.Format("Current: {0}", positionValue); var flags = Enum.GetValues(typeof (TileFlags)) .Cast<TileFlags>() .Where(flag => flag != TileFlags.NOTHING) .ToList(); var exactMatches = flags.Where(flag => (positionValue & flag) == flag).ToList(); foreach (var flag in flags) { var tileFlags = positionValue & flag; if (tileFlags > 0 && tileFlags != flag) { debug += string.Format(" | {0}:{1}", flag, tileFlags); } } debug += string.Format(" ({0})", string.Join("|", exactMatches)); var label = (uint) (positionValue & TileFlags.LABEL); if (label > 0) { debug += string.Format(" LBL:'{0}'", Console2.Encoding.GetString(BitConverter.GetBytes(label))); } return debug; }
private void FillArea(Map map, ConsoleArea area, IEnumerable<Position> positions) { foreach (var position in positions) { var tile = GetTile(map.GetPositionValue(position)); area.Write(tile.Character, position.X, position.Y, tile.ForeColor, tile.BackColor); } }