public Item Fight(Gladiator Player, Enemy Opponent) { if (Player.GetHealth() > 0) { int dmg = Player.Attack(Opponent); Draw.ShowEnemyStats(Opponent, true, dmg); } if (Opponent.health > 0) { int enemyDmg = Opponent.Attack(Player); Draw.ShowPlayerStats(Player, true, enemyDmg, Opponent); } else { credit.BattleCredit(Player, Program.Round); DefeatedOpponents.Add(Opponent.name); return(Opponent.DropItem()); } if (Player.GetHealth() <= 0) { String textFile = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".txt"; using (StreamWriter writer = new StreamWriter(textFile, true)) { foreach (Object opponent in DefeatedOpponents) { writer.WriteLine(opponent); } writer.WriteLine(Player.credits + " credits"); } } return(null); }
public static void HidePlayerInventory(Gladiator player) { int Length = 15; int MaxWidth = 0; int MaxWidthEquip = 0; String[] equippedPositions = { "HELMET", "BODY", "WEAPON" }; foreach (Item item in Item.ListOfItems) { foreach (String pos in equippedPositions) { if (pos.Length > MaxWidthEquip) { MaxWidthEquip = pos.Length; } } if (item.ToString().Length + MaxWidthEquip > MaxWidth) { MaxWidth = item.ToString().Length + MaxWidthEquip; } } int MaxWidthFixed = MaxWidth + 8; int curserPosWidth = MaxWidthFixed - 1; for (int i = 0; i < Length; i++) { Console.SetCursorPosition(WIDTH - curserPosWidth, HEIGHT - 1 - i); for (int n = WIDTH - MaxWidthFixed; n < WIDTH - 1; n++) { Console.Write(" "); } } Console.SetCursorPosition(WIDTH - curserPosWidth + 3, HEIGHT); Console.Write("═"); Console.SetCursorPosition(WIDTH, HEIGHT - Length + 2); Console.Write("║"); Console.SetCursorPosition(WIDTH, HEIGHT - Length + 6); Console.Write("║"); Console.SetCursorPosition(WIDTH, HEIGHT); }
public static void ShowPlayerStats(Gladiator gladiator, Boolean didDmg, int dmg, Enemy enemy) { prepCursor(2, HEIGHT - 1); Console.Write(" ".PadRight(gladiatorDrawWidth)); Console.ForegroundColor = ConsoleColor.Green; String drawText = gladiator.name + " [HP: " + gladiator.GetHealth() + " Attack: " + gladiator.GetStrength() + "]"; gladiatorDrawWidth = drawText.Length; prepCursor(2, HEIGHT - 1); Console.Write(drawText); Console.ForegroundColor = ConsoleColor.White; finishedCursor(); if (didDmg) { ConsoleColor[] colors = { ConsoleColor.White, ConsoleColor.White, ConsoleColor.White, ConsoleColor.White, ConsoleColor.Gray, ConsoleColor.DarkGray, ConsoleColor.Black }; for (int i = 0; i < colors.Length; i++) { EnemyAttack(-dmg, colors[i], enemy); System.Threading.Thread.Sleep(250); } } }
public void DeadEnemyMoneyDrop(Gladiator gladiator) { gladiator.credits += Money; }
public void BattleCredit(Gladiator gladiator, int level) { latestDrop = Credits * level; gladiator.credits += latestDrop; }
public static void ShowPlayerInventory(Gladiator player, Boolean deleteMode) { int MaxWidth = 0; int MaxWidthEquip = 0; int Length = 8; String[] equippedPositions = { "HELMET", "BODY", "WEAPON" }; Item[] equippedItem = { player.EquippedHelmet, player.EquippedChest, player.EquippedWeapon }; foreach (Item item in Item.ListOfItems) { foreach (String pos in equippedPositions) { if (pos.Length > MaxWidthEquip) { MaxWidthEquip = pos.Length; } } if (item.Name.Length + MaxWidthEquip > MaxWidth) { MaxWidth = item.ToString().Length + MaxWidthEquip; } } int MaxWidthFixed = MaxWidth + 7; int curserPosWidth = MaxWidthFixed - 1; String inventoryTitle; if (deleteMode) { inventoryTitle = "[ DELETE MODE ]"; } else { inventoryTitle = "[ INVENTORY ]"; } String equippedTitle = "[ EQUIPPED ]"; Console.SetCursorPosition(WIDTH - curserPosWidth, HEIGHT - 5 - Length); Console.Write("╔" + equippedTitle.PadBoth(MaxWidthFixed, '═') + "╣"); for (int i = 0; i < 3; i++) { String itemName; if (equippedItem[i] != null) { itemName = equippedItem[i].ToString(); } else { itemName = ""; } String drawString = "║ " + equippedPositions[i] + ": " + itemName.PadLeft(MaxWidth - equippedPositions[i].Length + 1); Console.SetCursorPosition(WIDTH - curserPosWidth, HEIGHT - 4 - Length + i); Console.Write(drawString); } Console.SetCursorPosition(WIDTH - curserPosWidth, HEIGHT - 1 - Length); Console.Write("╠" + inventoryTitle.PadBoth(MaxWidthFixed, '═') + "╣"); for (int i = 0; i < 8; i++) { String itemName = ""; if (player.inventory.inventoryList.Count >= i + 1) { itemName = (player.inventory.inventoryList[i] as Item).ToString(); } String drawString = "║ " + string.Format("{0:D2}", i + 1) + ") " + itemName.PadLeft(MaxWidth); Console.SetCursorPosition(WIDTH - curserPosWidth, HEIGHT - Length + i); Console.Write(drawString); } Console.SetCursorPosition(WIDTH - curserPosWidth, HEIGHT); Console.Write("╩"); Console.SetCursorPosition(WIDTH, HEIGHT); }
private static void handleInput(Gladiator Player, Enemy Opponent) { while (Console.KeyAvailable) { Console.ReadKey(true); } Boolean deleteMode = false; while (true) { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.I) { if (showingInventory) { Draw.HidePlayerInventory(Player); Draw.ShowEnemyStats(Opponent, false, 0); Draw.FightOptions(); deleteMode = false; } else { Draw.ShowPlayerInventory(Player, false); } showingInventory = !showingInventory; } else if (showingInventory && (key.Key == ConsoleKey.D1 || key.Key == ConsoleKey.D2 || key.Key == ConsoleKey.D3 || key.Key == ConsoleKey.D4 || key.Key == ConsoleKey.D5 || key.Key == ConsoleKey.D6 || key.Key == ConsoleKey.D7 || key.Key == ConsoleKey.D8)) { int selected = 0; switch (key.Key) { case ConsoleKey.D1: selected = 1; break; case ConsoleKey.D2: selected = 2; break; case ConsoleKey.D3: selected = 3; break; case ConsoleKey.D4: selected = 4; break; case ConsoleKey.D5: selected = 5; break; case ConsoleKey.D6: selected = 6; break; case ConsoleKey.D7: selected = 7; break; case ConsoleKey.D8: selected = 8; break; } if (deleteMode) { if (Player.inventory.inventoryList.Count > selected - 1) { Player.inventory.inventoryList.RemoveAt(selected - 1); } } else { Player.EquipItem(Player.inventory.GetFromInventory(selected - 1)); } Draw.ShowPlayerInventory(Player, deleteMode); Draw.ShowPlayerStats(Player, false, 0, null); } else if (key.Key == ConsoleKey.D && showingInventory) { deleteMode = !deleteMode; Draw.ShowPlayerInventory(Player, deleteMode); } else if (key.Key == ConsoleKey.Enter) { break; } } }
static void Main(string[] args) { String name; Draw.initWindowSettings(); Draw.InitWindow(); Draw.displayStartup(); Draw.ShowText("Greetings Gladiator!", 1); name = Draw.ShowTextInput("What is your name?: ", 2); Draw.ShowText("Huh... Please step into the arena " + name, 3); Gladiator Player = new Gladiator(name); Draw.ShowPlayerStats(Player, false, 0, null); Draw.ShowTextPressEnter("< Press Enter to step into the arena >", 5); Draw.ShowText("You step into the arena.", 5); Logic logic = new Logic(); Enemy Opponent; Item droppedItem = null; do { Round++; Opponent = new Enemy(logic.GetName(), Round); Draw.ShowEnemyStats(Opponent, false, 0); if (Round != 1) { Draw.centerText(Opponent.name + " approaches you.", 6); Draw.centerText("", 7); Draw.centerText("< Press Enter to begin fight >", 8); Draw.ShowTextPressEnter(" ", 9); } else { Draw.ShowText(Opponent.name + " approaches you.", 6); Draw.ShowText("< Press Enter to begin fight >", 8); Draw.ShowTextPressEnter(" ", 9); } Draw.Clear(); Draw.InitWindow(); Draw.ShowRound(Round); while (Opponent.health > 0 && Player.GetHealth() > 0) { Draw.ShowPlayerStats(Player, false, 0, null); Draw.ShowEnemyStats(Opponent, false, 0); Draw.FightOptions(); handleInput(Player, Opponent); Draw.ClearFightOptions(); droppedItem = logic.Fight(Player, Opponent); } if (Player.GetHealth() <= 0) { break; } Player.RemoveActivePotion(); Draw.Clear(); Draw.InitWindow(); Draw.ShowRound(Round); Draw.ShowPlayerStats(Player, false, 0, null); Draw.ShowEnemyStats(Opponent, false, 0); Draw.centerText("You defeated " + Opponent.name + "!", 5); if (droppedItem != null) { Draw.centerText(Opponent.name + " dropped " + droppedItem.Name + " [" + droppedItem.Rarity + "] " + "and " + logic.GetCredit().latestDrop + " Credits", 6); } Draw.centerText("< Press Enter to continue >", 7); Draw.ShowTextPressEnter(" ", 8); Player.inventory.AddToInventory(droppedItem); } while (Player.GetHealth() > 0); Draw.Clear(); Draw.centerText(" _____ __ __ ______ ______ ________ _____ ", Draw.HEIGHT / 2 - 4); Draw.centerText(" / ____| /\\ | \\/ | ____| / __ \\ \\ / / ____| __ \\ ", Draw.HEIGHT / 2 - 3); Draw.centerText("| | __ / \\ | \\ / | |__ | | | \\ \\ / /| |__ | |__) |", Draw.HEIGHT / 2 - 2); Draw.centerText("| | |_ | / /\\ \\ | |\\/| | __| | | | |\\ \\/ / | __| | _ / ", Draw.HEIGHT / 2 - 1); Draw.centerText("| |__| |/ ____ \\| | | | |____ | |__| | \\ / | |____| | \\ \\ ", Draw.HEIGHT / 2); Draw.centerText(" \\_____/_/ \\_\\_| |_|______| \\____/ \\/ |______|_| \\_\\", Draw.HEIGHT / 2 + 1); Draw.centerText("You survived to Round (" + Round + ") and gathered " + Player.credits + " credits!", Draw.HEIGHT / 2 + 3); while (true) { } }
public int Attack(Gladiator player) { AttackDamage = strength; player.DealDamage(AttackDamage); return(AttackDamage); }