private void DrawItems(BufferContainer buffer, int x, int y, List <Item> items, StorageLocation current, StorageLocation target, bool isActive = false) { var i = 0; foreach (var item in items) { var alphabet = "abcdefghijklmnopqrstuvwxyz"; var itemY = i + y; var borderColor = ConsoleColor.DarkGray; var letterColor = ConsoleColor.DarkGray; var textColor = ConsoleColor.DarkGray; var priceColor = ConsoleColor.DarkGray; var glyphColor = ConsoleColor.DarkGray; var attackColor = ConsoleColor.DarkGray; var armourColor = ConsoleColor.DarkGray; var enabled = true; if (isActive) { switch (target) { case StorageLocation.Equipment: { var command = new EquipItemCommand(); var canUse = command.CanSelect(item); if (canUse) { borderColor = ConsoleColor.Gray; letterColor = ConsoleColor.Yellow; textColor = item == null ? ConsoleColor.Gray : ConsoleColor.White; priceColor = ConsoleColor.DarkYellow; glyphColor = item == null ? ConsoleColor.Gray : ColourUtilities.ConvertToConsoleColor(item.Appearance.ForeGroundColor); attackColor = ConsoleColor.Yellow; armourColor = ConsoleColor.Green; } break; } case StorageLocation.Crucible: { var canUse = false; if (item != null) { canUse = CanUseItemInRecipe(item); } if (canUse) { borderColor = ConsoleColor.Gray; letterColor = ConsoleColor.Yellow; textColor = item == null ? ConsoleColor.Gray : ConsoleColor.White; priceColor = ConsoleColor.DarkYellow; glyphColor = item == null ? ConsoleColor.Gray : ColourUtilities.ConvertToConsoleColor(item.Appearance.ForeGroundColor); attackColor = ConsoleColor.Yellow; armourColor = ConsoleColor.Green; } break; } default: { borderColor = ConsoleColor.Gray; letterColor = ConsoleColor.Yellow; textColor = item == null ? ConsoleColor.Gray : ConsoleColor.White; priceColor = ConsoleColor.DarkYellow; glyphColor = item == null ? ConsoleColor.Gray : ColourUtilities.ConvertToConsoleColor(item.Appearance.ForeGroundColor); attackColor = ConsoleColor.Yellow; armourColor = ConsoleColor.Green; break; } } } WriteAt(buffer, x, itemY, " ) ", borderColor); WriteAt(buffer, x, itemY, alphabet[i].ToString(), letterColor); if (item == null) { // what is the location? if (current == StorageLocation.Equipment) { var text = ((EquipementSlot)i) + " slot is empty"; WriteAt(buffer, x + 3, itemY, text, textColor); } } else { if (enabled) { WriteAt(buffer, x + 3, itemY, item.Appearance.Glyph, glyphColor); } var text = item.NounText; if (text.Length > 32) { text = text.Substring(0, 29) + "..."; } WriteAt(buffer, x + 5, itemY, text, textColor); // TODO: Eventually need to handle equipment that gives both an armor and attack bonus. if (item.attack != null) { DrawStat(buffer, x, itemY, "»", item.attack.AverageDamage, attackColor, attackColor, enabled); } else if (item.armor != 0) { DrawStat(buffer, x, itemY, "•", item.armor, armourColor, armourColor, enabled); } if (item.price != 0) { var price = PriceString(item.price); WriteAt(buffer, x + 49 - price.Length, itemY, price, priceColor); } } // Increment the item counter i++; } // If this is the crucible then maybe a recipe has been completed. if (current == StorageLocation.Crucible) { if (completeRecipe != null) { i++; i++; var textColour = ConsoleColor.Yellow; if (isActive) { textColour = ConsoleColor.DarkGray; } var csv = string.Join(", ", completeRecipe.Produces.ToArray()); WriteAt(buffer, 0, y + i++, $"This recipe {csv}!", textColour); WriteAt(buffer, 0, y + i++, "Press[Space] to forge item!", textColour); } } }
public override void Draw(BufferContainer buffer) { //ClearArea(buffer); var hero = Game.Hero; var actors = Game.CurrentStage.Actors; var foreGroundColour = hero.Appearance.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(hero.Appearance.ForeGroundColor); var backGroundColour = hero.Appearance.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(hero.Appearance.BackGroundColor); int lineCounter = 0; WriteAt(buffer, 0, lineCounter++, "Visible Creatures:", ConsoleColor.DarkYellow, backGroundColour); WriteAt(buffer, 0, lineCounter, hero.Appearance.Glyph, foreGroundColour, backGroundColour); WriteAt(buffer, 2, lineCounter, Game.Hero.Name); WriteAt(buffer, 22, lineCounter, $"({hero.Position.x},{hero.Position.y})"); WriteAt(buffer, 32, lineCounter++, $"{hero.Health.Current}/{hero.Health.Max}"); foreach (var actor in actors) { if (actor is Monster) { var monster = actor as Monster; if (Option.ShowAll) { foreGroundColour = monster.Appearance.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(monster.Appearance.ForeGroundColor); backGroundColour = monster.Appearance.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(monster.Appearance.BackGroundColor); WriteAt(buffer, 0, lineCounter, " ".PadRight(MaxWidth, ' '), ConsoleColor.White, ConsoleColor.Black); if (monster.Appearance.Glyph.Length > 1) { Debugger.Break(); } WriteAt(buffer, 0, lineCounter, monster.Appearance.Glyph, foreGroundColour, backGroundColour); WriteAt(buffer, 2, lineCounter, monster.NounText); WriteAt(buffer, 22, lineCounter, $"({monster.Position.x},{monster.Position.y})"); WriteAt(buffer, 32, lineCounter, $"{monster.Health.Current}/{monster.Health.Max}"); lineCounter++; } else { if (!Game.CurrentStage.Shadows[monster.Position.x, monster.Position.y].IsInShadow) { foreGroundColour = monster.Appearance.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(monster.Appearance.ForeGroundColor); backGroundColour = monster.Appearance.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(monster.Appearance.BackGroundColor); WriteAt(buffer, 0, lineCounter, " ".PadRight(MaxWidth, ' '), ConsoleColor.White, ConsoleColor.Black); if (monster.Appearance.Glyph.Length > 1) { Debugger.Break(); } WriteAt(buffer, 0, lineCounter, monster.Appearance.Glyph, foreGroundColour, backGroundColour); WriteAt(buffer, 2, lineCounter, monster.NounText); WriteAt(buffer, 22, lineCounter, $"({monster.Position.x},{monster.Position.y})"); WriteAt(buffer, 32, lineCounter, $"{monster.Health.Current}/{monster.Health.Max}"); lineCounter++; } } } } }
public override void Draw(BufferContainer buffer) { var hero = Game.Hero; var foreGroundColour = hero.Appearance.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(hero.Appearance.ForeGroundColor); var backGroundColour = hero.Appearance.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(hero.Appearance.BackGroundColor); var line = $"Lv: {Game.Hero.Level}[{Game.Hero.LevelPercentage}%] HP: {Game.Hero.Health.Current}/{Game.Hero.Health.Max} Charge:{Game.Hero.Charge.Current}/{Game.Hero.Charge.Max} "; WriteAt(buffer, 0, 0, line, foreGroundColour, backGroundColour); var secondLine = $"Armour: {Game.Hero.Armor} Weapon: {Game.Hero.GetAttack(null).BaseDamage} Food: {Math.Floor(Game.Hero.Food)}"; WriteAt(buffer, 0, 1, secondLine, foreGroundColour, backGroundColour); }
public override void Draw(BufferContainer buffer) { var debugger = Debugger.Instance; var startOfGetMatrixViewPort = DateTime.Now; var viewPortMatrix = GetMatrixViewPort(); var endOfGetMatrixViewPort = DateTime.Now; var matrixWidth = viewPortMatrix.GetUpperBound(0) + 1; var matrixHeight = viewPortMatrix.GetUpperBound(1) + 1; // TODO: view port tranformation... // 1. the top two row for the ruler // 2. the left three rows for the ruler // 3. the rest of the matrix cut down. var startOfDrawingMatrixViewPort = DateTime.Now; for (var rowIndex = 0; rowIndex < matrixHeight; rowIndex++) { for (var columnIndex = 0; columnIndex < matrixWidth; columnIndex++) { var currentTile = viewPortMatrix[columnIndex, rowIndex]; if (Option.ShowAll) { var foreGroundColour = currentTile.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(currentTile.ForeGroundColor); var backGroundColour = currentTile.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(currentTile.BackGroundColor); buffer.Write(currentTile.Glyph, Left + columnIndex, Top + rowIndex, foreGroundColour, backGroundColour); } else { if (!currentTile.IsExplored) { buffer.Write($".", Left + columnIndex, Top + rowIndex, ConsoleColor.DarkRed); } else if (currentTile.IsInShadow) { buffer.Write(currentTile.Glyph, Left + columnIndex, Top + rowIndex, ConsoleColor.DarkGray); } else if (currentTile.IsHidden) { buffer.Write($".", Left + columnIndex, Top + rowIndex, ConsoleColor.DarkGreen); } else { var foreGroundColour = currentTile.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(currentTile.ForeGroundColor); var backGroundColour = currentTile.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(currentTile.BackGroundColor); buffer.Write(currentTile.Glyph, Left + columnIndex, Top + rowIndex, foreGroundColour, backGroundColour); } } } } // Stage Statistics var currentLine = 0; buffer.Write($"Number of Unexplored: {GameState.Instance.Game.CurrentStage.numberAlreadyExplored} [{GameState.Instance.Game.CurrentStage.percentageAlreadyExplored}%].", Left, Top + matrixHeight + currentLine++); buffer.Write($"Current Level: {GameState.Instance.Game.CurrentStage.StageNumber}.", Left, Top + matrixHeight + currentLine++); var endOfDrawingMatrixViewPort = DateTime.Now; var timeTakenToGettingMatrixViewPort = endOfGetMatrixViewPort - startOfGetMatrixViewPort; var timeTakenToDrawingMatrixViewPort = endOfDrawingMatrixViewPort - startOfDrawingMatrixViewPort; debugger.LogToDisk($" $ Time for getting viewport: {timeTakenToGettingMatrixViewPort.TotalMilliseconds}", LogLevel.Debug); debugger.LogToDisk($" $ Time for drawing: {timeTakenToDrawingMatrixViewPort.TotalMilliseconds}", LogLevel.Debug); }
public void DrawVisibleItems(BufferContainer buffer, Appearence[,] source, VectorBase heroPosition) { var viewPortMatrix = GetMatrixViewPort(source, heroPosition); var matrixWidth = viewPortMatrix.GetUpperBound(0) + 1; var matrixHeight = viewPortMatrix.GetUpperBound(1) + 1; for (var rowIndex = 0; rowIndex < matrixHeight; rowIndex++) { for (var columnIndex = 0; columnIndex < matrixWidth; columnIndex++) { var currentTile = viewPortMatrix[columnIndex, rowIndex].Clone(); if (!currentTile.IsExplored || currentTile.IsInShadow || currentTile.IsHidden) { buffer.Write($" ", columnIndex, rowIndex, ConsoleColor.DarkRed); } else { var foreGroundColour = currentTile.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(currentTile.ForeGroundColor); var backGroundColour = currentTile.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(currentTile.BackGroundColor); buffer.Write(currentTile.Glyph, columnIndex, rowIndex, foreGroundColour, backGroundColour); } } } }
/// Draws a list of [items] on [terminal] at [x], [y]. /// /// This is used both on the [ItemScreen] and in game for things like using and /// dropping items. /// /// Items can be drawn in one of three states: /// /// * If [canSelect] is `null`, then item list is just being viewed and no /// items in particular are highlighted. /// * If [canSelect] returns `true`, the item is highlighted as being /// selectable. /// * If [canSelect] returns `false`, the item cannot be selected and is /// grayed out. /// /// An item row looks like this: /// 1 2 3 4 /// 01234567890123456789012345678901234567890123456789 /// a) = a Glimmering War Hammer of Wo... »29 992,106 private void DrawItems(BufferContainer buffer, int x, int y, List <Item> items, Func <Item, bool> canSelect) { var i = 0; foreach (var item in items) { var alphabet = "abcdefghijklmnopqrstuvwxyz"; var itemY = i + y; var borderColor = ConsoleColor.DarkGray; var letterColor = ConsoleColor.Gray; var textColor = ConsoleColor.White; var priceColor = ConsoleColor.Gray; var enabled = true; if (canSelect != null) { if (canSelect(item)) { borderColor = ConsoleColor.Gray; letterColor = ConsoleColor.Yellow; textColor = ConsoleColor.White; priceColor = ConsoleColor.DarkYellow; } else { borderColor = ConsoleColor.Black; letterColor = ConsoleColor.Black; textColor = ConsoleColor.DarkGray; priceColor = ConsoleColor.DarkGray; enabled = false; } } WriteAt(buffer, x, itemY, " ) ", borderColor); WriteAt(buffer, x, itemY, alphabet[i].ToString(), letterColor); if (item == null) { // what is the location? if (Location == ItemLocations.Equipment) { var text = ((EquipementSlot)i) + " slot is empty"; WriteAt(buffer, x + 3, itemY, text, textColor); } } else { if (enabled) { WriteAt(buffer, x + 3, itemY, item.Appearance.Glyph, ColourUtilities.ConvertToConsoleColor(item.Appearance.ForeGroundColor)); } var text = item.NounText; if (text.Length > 32) { text = text.Substring(0, 29) + "..."; } WriteAt(buffer, x + 5, itemY, text, textColor); // TODO: Eventually need to handle equipment that gives both an armor and attack bonus. if (item.attack != null) { DrawStat(buffer, x, itemY, "»", item.attack.AverageDamage, ConsoleColor.Yellow, ConsoleColor.DarkYellow, enabled); } else if (item.armor != 0) { DrawStat(buffer, x, itemY, "•", item.armor, ConsoleColor.Green, ConsoleColor.DarkGreen, enabled); } if (item.price != 0) { var price = PriceString(item.price); WriteAt(buffer, x + 49 - price.Length, itemY, price, priceColor); } } // Increment the item counter i++; } }