///ROUTINES. public Item SingleItemSelectionMenu(string ask, List <Item> itemlist) { if (itemlist.Count == 0) { return(null); } if (itemlist.Count == 1) { return(itemlist[0]); } int cursor = 0; ConsoleKeyInfo keyPressed; do { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; Console.Clear(); Console.WriteLine("What item would you want to " + ask + "?"); for (int i = 0; i < itemlist.Count; i++) { if (i == cursor) { Console.BackgroundColor = ConsoleColor.DarkRed; } else { Console.BackgroundColor = ConsoleColor.Black; } Console.WriteLine(itemlist[i].DisplayName); } keyPressed = Console.ReadKey(true); switch (keyPressed.Key) { case ConsoleKey.NumPad2: case ConsoleKey.DownArrow: cursor++; break; case ConsoleKey.NumPad8: case ConsoleKey.UpArrow: cursor--; break; //case ConsoleKey.Spacebar: return itemlist[cursor]; break; //case ConsoleKey.Enter: return itemlist[cursor]; break; case ConsoleKey.Escape: Log.AddOneFromList(StringFactory.CancelStrings()); return(null); default: break; } if (cursor >= itemlist.Count) { cursor = 0; } if (cursor < 0) { cursor = itemlist.Count - 1; } } while (keyPressed.Key != ConsoleKey.Spacebar && keyPressed.Key != ConsoleKey.Enter); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; return(itemlist[cursor]); }
public static void MeleeAttack(Unit attacker, Unit victim) { Weapon attackerWeapon = attacker.Inv.Wielded; if (attackerWeapon != null) { if (!attackerWeapon.targetInMeleeRange(attacker.CoordX, attacker.CoordY, victim.CoordX, victim.CoordY)) { //Zomg error _DEBUG.AddDebugMessage("ERROR: attempt to melee from non-melee range."); } attacker.Timing.AddActionTime(TimeCost.MeleeAttackCost(attacker)); int finalDamage = CalculateMeleeDamage(attacker, victim); bool victimStabbed = false; if (attacker.Inv.Wielded.TypeOfMeleeDamage == Weapon.MeleeDamageTypes.Stab && victim.IsUnaware()) { finalDamage *= 6; //zomg Log.AddOneFromList(StringFactory.AttackerStabsVictim(attacker, victim)); victimStabbed = true; } else { if (attacker is Player) { Log.AddLine("You hit " + victim.Name + " with your " + attacker.Inv.Wielded.DisplayName + "!"); } else { Log.AddLine(attacker.Name + " hits " + victim.Name + " with the " + attacker.Inv.Wielded.DisplayName + "!"); } } victim.Hitpoints -= finalDamage; if (attacker is Player) { _DEBUG.AddDebugMessage(" " + finalDamage.ToString() + " damage"); } if (victim is Player) { Gameover.KilledBy = attacker.Name; if (victim.Hitpoints < victim.GetMaxHitpoints() / 3 || victim.Hitpoints < 3) { Log.AddAlertMessage("!!LOW HITPOINT WARNING!!"); } } if (victimStabbed) { Log.AddOneFromList(StringFactory.stabbedVictimReacts(victim)); } } }
void shootDialogue() { if (Inv.Wielded.Range == 1) { Log.AddLine("You can't shoot with the " + Inv.Wielded.DisplayName + "!"); return; } Log.AddLine("Which target? (tab - next, f - fire, esc - cancel)"); bool nextTargetPlease = true; while (nextTargetPlease) { nextTargetPlease = false; foreach (Actor currTarget in World.AllActors) { if (WorldLOS.VisibleLineExist(CoordX, CoordY, currTarget.CoordX, currTarget.CoordY)) { WorldRendering.drawInCircleFOV(CoordX, CoordY, visibilityRadius); WorldRendering.drawUnitsInCircle(CoordX, CoordY, visibilityRadius); this.Draw(); currTarget.DrawHighlighted(); Console.ForegroundColor = ConsoleColor.Red; WorldRendering.DrawLineNotInclusive(CoordX, CoordY, currTarget.CoordX, currTarget.CoordY, '*'); ConsoleKeyInfo keyPressed = Console.ReadKey(true); if (keyPressed.Key == ConsoleKey.Tab) { nextTargetPlease = true; continue; } if (keyPressed.Key == ConsoleKey.Escape) { Log.AddOneFromList(StringFactory.CancelStrings()); return; } if (keyPressed.Key == ConsoleKey.F) { Attack.RangedAttack(this, currTarget); return; } } } } Log.ReplaceLastLine("No targets in range!"); }
public List <Item> MultipleItemSelectionMenu(string ask, List <Item> itemlist) { if (itemlist.Count <= 1) { return(itemlist); } int cursor = 0; List <Item> selectedItems = new List <Item>(); List <bool> selectedIndexes = new List <bool>(); for (int i = 0; i < itemlist.Count; i++) { selectedIndexes.Add(false); } string selectChar; ConsoleKeyInfo keyPressed; do { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; Console.Clear(); Console.WriteLine("What do you want to " + ask + "?"); for (int i = 0; i < itemlist.Count; i++) { if (i == cursor) { Console.BackgroundColor = ConsoleColor.DarkRed; } else { Console.BackgroundColor = ConsoleColor.Black; } if (selectedIndexes[i] == false) { selectChar = "-"; } else { selectChar = " +"; } Console.WriteLine(selectChar + " " + itemlist[i].DisplayName); } keyPressed = Console.ReadKey(true); switch (keyPressed.Key) { case ConsoleKey.NumPad2: case ConsoleKey.DownArrow: cursor++; break; case ConsoleKey.NumPad8: case ConsoleKey.UpArrow: cursor--; break; case ConsoleKey.Spacebar: selectedIndexes[cursor] = !selectedIndexes[cursor]; break; case ConsoleKey.Escape: Log.AddOneFromList(StringFactory.CancelStrings()); return(selectedItems); break; default: break; } if (cursor >= itemlist.Count) { cursor = 0; } if (cursor < 0) { cursor = itemlist.Count - 1; } } while (keyPressed.Key != ConsoleKey.Enter); for (int i = 0; i < itemlist.Count; i++) { if (selectedIndexes[i]) { selectedItems.Add(itemlist[i]); } } Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; return(selectedItems); }