private void DrawChooseHeroFromConsole(int choice, Hero hero) { Drawer draw = new Drawer(); string choicePointer = "==>"; Console.ResetColor(); Console.Clear(); draw.DrawString("Choose your hero!", ConsoleColor.Black, 5, 5); draw.DrawString("Warrior", ConsoleColor.Black, 8, 8); draw.DrawString("Rogue", ConsoleColor.Black, 10, 8); draw.DrawString("Mage", ConsoleColor.Black, 12, 8); draw.DrawString(choicePointer, ConsoleColor.DarkMagenta, (6 + choice * 2), 4); draw.DrawImage(hero.Image,ConsoleColor.Black,15,4); draw.DrawString("Strength: " + hero.Statistics.Strength, ConsoleColor.Black, 33, 55); draw.DrawString("Dexterity: " + hero.Statistics.Dexterity, ConsoleColor.Black, 35, 55); draw.DrawString("Willpower: " + hero.Statistics.EillPower, ConsoleColor.Black, 37, 55); draw.DrawString("Weapon: " + hero.Weapon.name, ConsoleColor.Black, 20, 55); draw.DrawString("Weapon Damage: " + hero.Weapon.damage, ConsoleColor.Black, 21, 55); draw.DrawString("Magic: " + hero.Weapon.magic.Name, ConsoleColor.Black, 23, 55); draw.DrawString("Magic Damage: " + hero.Weapon.magic.damage, ConsoleColor.Black, 24, 55); draw.DrawString("Magic Damage on Self: " + hero.Weapon.magic.damageOnSelf, ConsoleColor.Black, 25, 55); draw.DrawString("Magic Chance to Stun: " + hero.Weapon.magic.chanceToStun, ConsoleColor.Black, 26, 55); Console.SetCursorPosition(0, 0); }
public static void Save(Hero currentHero) { using (FileStream save = new FileStream(@"../../Data/Save/save.bin",FileMode.Create)) { file.Serialize(save, currentHero); } }
private void ChangeHero() { HeroTypes types = new HeroTypes(); switch (choice) { case 1: hero = types.Warrior(); break; case 2: hero = types.Rogue(); break; case 3: hero = types.Mage(); break; default: break; } }
public void Menu(Hero hero) { DrawMenu(); this.shadow = hero; ConsoleKeyInfo pressedKey = Console.ReadKey(); while (!pressedKey.Key.Equals(ConsoleKey.Enter)) { if (pressedKey.Key.Equals(ConsoleKey.UpArrow)) { if (choice > 1) { choice--; DrawMenu(); } else { choice = options.Length; DrawMenu(); } } else if (pressedKey.Key.Equals(ConsoleKey.DownArrow)) { if (choice < options.Length) { choice++; DrawMenu(); } else { choice = 1; DrawMenu(); } } pressedKey = Console.ReadKey(); } switch (choice) { case 1: return; case 2: MenuShowHeroStats(hero); break; case 3: //save break; case 4: //load break; case 5: Environment.Exit(0); break; default: break; } }
public void DrawConversation(Hero hero, NPC npc) { Drawer draw = new Drawer(); Console.BackgroundColor = ConsoleColor.Black; Console.Clear(); draw.DrawImage(hero.Image, ConsoleColor.Black, 5, 5); draw.DrawImage(npc.Image, ConsoleColor.Black, 5, 55); draw.PrintConversation(npc.ConversationPath); Console.ReadLine(); Console.Clear(); Console.ResetColor(); // the matrix must be rewriten now }
/// Will be a more complex menu with a few choices in it public Hero ChooseHeroFromConsole() { choice = 1; ChangeHero(); DrawChooseHeroFromConsole(choice, hero); ConsoleKeyInfo pressedKey = Console.ReadKey(); while (!pressedKey.Key.Equals(ConsoleKey.Enter)) { if (pressedKey.Key.Equals(ConsoleKey.UpArrow)) { if (choice > 1) { choice--; ChangeHero(); } else { choice = 3; ChangeHero(); } } else if (pressedKey.Key.Equals(ConsoleKey.DownArrow)) { if (choice < 3) { choice++; ChangeHero(); } else { choice = 1; ChangeHero(); } } DrawChooseHeroFromConsole(choice, hero); pressedKey = Console.ReadKey(); } hero.Name = GetHeroName(); if (hero.Name.Equals("Cheater")) { hero = new HeroTypes().Cheater(); } return hero; }
public void GetRandomWeapon(Hero hero) { List<Weapon> possibleWeapons; List<Magic> possibleMagic; Random rnd = new Random(); Weapon weapon; Weapons weaps = new Weapons(); Spells spls = new Spells(); possibleWeapons = weaps.WeakWeapons; possibleMagic = spls.BasicSpells; switch (hero.level) { case 1: possibleWeapons = weaps.WeakWeapons; possibleMagic = spls.BasicSpells; break; case 2: possibleWeapons = weaps.AverageWeapons; possibleMagic = spls.AdvancedSpells; break; case 3: possibleWeapons = weaps.GoodWeapons; possibleMagic = spls.MasterSpells; break; default: break; } weapon = possibleWeapons[rnd.Next(possibleWeapons.Count)]; weapon.magic = possibleMagic[rnd.Next(possibleMagic.Count)]; DrawMenuInConsole(hero, weapon); bool ChangeWeapon = GetChoice(); if (ChangeWeapon) { hero.Weapon = weapon; } }
private void DrawMenuInConsole(Hero hero, Weapon weapon) { Drawer draw = new Drawer(); Console.ResetColor(); Console.Clear(); string message = "You have found a new weapon!"; draw.DrawString(message, ConsoleColor.Black, 6, Console.WindowWidth / 2 - message.Length / 2); message = "The weapon is " + weapon.name + " and it's damage is " + weapon.damage; draw.DrawString(message, ConsoleColor.Black, 10, Console.WindowWidth / 2 - message.Length / 2); message = "The weapon's magic is " + weapon.magic.Name + " and it's effects are: "; draw.DrawString(message, ConsoleColor.Black, 11, Console.WindowWidth / 2 - message.Length / 2); int line = 13; if (weapon.magic.damage > 0) { message = "Damage: " + weapon.magic.damage; draw.DrawString(message, ConsoleColor.Black, line, Console.WindowWidth / 2 - message.Length / 2); line++; } if (weapon.magic.damageOnSelf != 0) { if (weapon.magic.damageOnSelf > 0) { message = "Damage on self: " + weapon.magic.damageOnSelf; draw.DrawString(message, ConsoleColor.Black, line, Console.WindowWidth / 2 - message.Length / 2); line++; } else { message = "Heal: " + (0 - weapon.magic.damageOnSelf); draw.DrawString(message, ConsoleColor.Black, line, Console.WindowWidth / 2 - message.Length / 2); line++; } } if (weapon.magic.chanceToStun > 0) { message = "Chance to stun: " + (100 * weapon.magic.chanceToStun) + "%"; draw.DrawString(message, ConsoleColor.Black, line, Console.WindowWidth / 2 - message.Length / 2); line++; } message = "Your current weapon is " + hero.Weapon.name + " and it's damage is " + hero.Weapon.damage; draw.DrawString(message, ConsoleColor.Black, 17, Console.WindowWidth / 2 - message.Length / 2); message = "The weapon's magic is " + hero.Weapon.magic.Name + " and it's effects are: "; draw.DrawString(message, ConsoleColor.Black, 18, Console.WindowWidth / 2 - message.Length / 2); line = 20; if (hero.Weapon.magic.damage > 0) { message = "Damage: " + hero.Weapon.magic.damage; draw.DrawString(message, ConsoleColor.Black, line, Console.WindowWidth / 2 - message.Length / 2); line++; } if (hero.Weapon.magic.damageOnSelf != 0) { if (hero.Weapon.magic.damageOnSelf > 0) { message = "Damage on self: " + hero.Weapon.magic.damageOnSelf; draw.DrawString(message, ConsoleColor.Black, line, Console.WindowWidth / 2 - message.Length / 2); line++; } else { message = "Heal: " + (0 - hero.Weapon.magic.damageOnSelf); draw.DrawString(message, ConsoleColor.Black, line, Console.WindowWidth / 2 - message.Length / 2); line++; } } if (hero.Weapon.magic.chanceToStun > 0) { message = "Chance to stun: " + (100 * hero.Weapon.magic.chanceToStun) + "%"; draw.DrawString(message, ConsoleColor.Black, line, Console.WindowWidth / 2 - message.Length / 2); line++; } message = "Do you want to leave your weapon behind, and take the new weapon?"; draw.DrawString(message, ConsoleColor.Black, 25, Console.WindowWidth / 2 - message.Length / 2); message = "[Y /N] "; draw.DrawString(message, ConsoleColor.Black, 27, Console.WindowWidth / 2 - message.Length / 2); Console.SetCursorPosition(0, 0); }
public VisualElement[,] LoadLevel(VisualElement[,] matrix, Hero hero, List<NPC> emptyNPCList) { Dangers dangers = new Dangers(); VisualElements VisualLoader = new VisualElements(); NPCs npcs = new NPCs(); emptyNPCList.Clear(); Levels levels = new Levels(); string[] level = levels.Level1; List<DangerousTerritory> dangersOnThisLevel = dangers.Level1Dangers; switch (hero.level) { case 1: dangersOnThisLevel = dangers.Level1Dangers; level = levels.Level1; break; case 2: dangersOnThisLevel = dangers.Level2Dangers; level = levels.Level2; break; case 3: dangersOnThisLevel = dangers.Level3Dangers; level = levels.Level3; break; default: break; } for (int r = 0; r < matrix.GetLength(0); r++) { for (int c = 0; c < matrix.GetLength(1); c++) { if (level[r][c].Equals(' ')) { matrix[r, c] = VisualLoader.Grass(sizeOfVisualElements); } else if (level[r][c].Equals('/')) { matrix[r, c] = VisualLoader.Grass(1); matrix[r, c].content = dangersOnThisLevel[0]; /// will have 1-st enemy } else if (level[r][c].Equals('.')) { matrix[r, c] = VisualLoader.Desert(sizeOfVisualElements); matrix[r, c].content = dangersOnThisLevel[1]; /// will have 2-nd enemy } else if (level[r][c].Equals('+')) { matrix[r, c] = VisualLoader.Barren(sizeOfVisualElements); matrix[r, c].content = dangersOnThisLevel[2]; /// will have 3-rd enemy } else if (level[r][c].Equals('#')) { matrix[r, c] = VisualLoader.Rock(sizeOfVisualElements); } else if (level[r][c].Equals(':')) { matrix[r, c] = VisualLoader.Grass(sizeOfVisualElements); } else if (level[r][c].Equals('*')) { matrix[r, c] = VisualLoader.Rock(sizeOfVisualElements); /// Will be chest } else if (char.IsDigit(level[r][c])) { matrix[r, c] = VisualLoader.NPC(sizeOfVisualElements); /// will be NPC NPC npc = npcs.npcList[int.Parse((level[r][c]).ToString())]; npc.Position = new Position(r, c); emptyNPCList.Add(npc); } else if (level[r][c].Equals('\'')) { matrix[r, c] = VisualLoader.Desert(sizeOfVisualElements); matrix[r, c].content = dangersOnThisLevel[3]; /// will be BOSS } else if (level[r][c].Equals('H')) { matrix[r, c] = VisualLoader.Grass(sizeOfVisualElements); if (hero.Position.row == 0 || hero.Position.col == 0) { hero.Position = new Position(r, c); } } else { matrix[r, c] = VisualLoader.Empty(sizeOfVisualElements); } } } return matrix; }
public VisualElement[,] LoadVisibleLevel(VisualElement[,] VisibleMatrix, VisualElement[,] matrix, Hero hero) { VisualElements VisualLoader = new VisualElements(); VisibleMatrix[VisibleMatrix.GetLength(0) / 2, VisibleMatrix.GetLength(1) / 2] = VisualLoader.Hero(1); for (int r2 = 0; r2 < VisibleMatrix.GetLength(0); r2++) { for (int c2 = 0; c2 < VisibleMatrix.GetLength(0); c2++) { int actualPositionRow = hero.Position.row - VisibleMatrix.GetLength(0) / 2 + r2; int actualPositionCol = hero.Position.col - VisibleMatrix.GetLength(0) / 2 + c2; if (actualPositionRow >= 0 || actualPositionRow > matrix.GetLength(0) || actualPositionCol >= 0 || actualPositionCol > matrix.GetLength(1)) { VisibleMatrix[r2, c2] = VisualLoader.Empty(sizeOfVisualElements); } else { VisibleMatrix[r2, c2] = matrix[actualPositionRow, actualPositionCol]; } } } return VisibleMatrix; }
public void DrawHero(Hero hero) { Console.SetCursorPosition(hero.Position.col, hero.Position.row); Console.BackgroundColor = ConsoleColor.DarkRed; Console.Write('H'); }
//static VisualElement[,] VisibleMatrix = new VisualElement[height, width]; static void Main(string[] args) { Console.Title = "SazeracMagicSword"; Console.WindowHeight = height; Console.WindowWidth = width; //1) Main menu (new game / load game) int mainMenuChoosen = MainMenu.StartMainMenu(); if (mainMenuChoosen == 1) { hero = MainMenu.SelectedChoice(mainMenuChoosen); } else if (mainMenuChoosen == 2) { hero = LoadSaveGame.Load(); } else { Environment.Exit(0); } matrix = load.LoadLevel(matrix, hero, NPCsOfCurrentLevel); //VisibleMatrix = load.LoadVisibleLevel(VisibleMatrix, matrix, hero); // throws an exception... //2) Dynamic game //draw.DrawMatrixInConsole(VisibleMatrix); draw.DrawMatrixInConsole(matrix); while (true) { draw.DrawHero(hero); Console.SetCursorPosition(80, 0); ConsoleKeyInfo pressedKey = Console.ReadKey(); ProcessInput(pressedKey); } }
static void ProcessInput(ConsoleKeyInfo pressedKey) { if (pressedKey.Key.Equals(ConsoleKey.UpArrow)) { if (!matrix[hero.Position.row - 1, hero.Position.col].isSolid) { draw.DrawInConsole(matrix[hero.Position.row, hero.Position.col], hero.Position.row, hero.Position.col); hero.Move(Direction.up); CheckHeroPosition(); } } else if (pressedKey.Key.Equals(ConsoleKey.DownArrow)) { if (!matrix[hero.Position.row + 1, hero.Position.col].isSolid) { draw.DrawInConsole(matrix[hero.Position.row, hero.Position.col], hero.Position.row, hero.Position.col); hero.Move(Direction.down); CheckHeroPosition(); } } else if (pressedKey.Key.Equals(ConsoleKey.LeftArrow)) { if (!matrix[hero.Position.row, hero.Position.col - 1].isSolid) { draw.DrawInConsole(matrix[hero.Position.row, hero.Position.col], hero.Position.row, hero.Position.col); hero.Move(Direction.left); CheckHeroPosition(); } } else if (pressedKey.Key.Equals(ConsoleKey.RightArrow)) { if (!matrix[hero.Position.row, hero.Position.col + 1].isSolid) { draw.DrawInConsole(matrix[hero.Position.row, hero.Position.col], hero.Position.row, hero.Position.col); hero.Move(Direction.right); CheckHeroPosition(); } } else if (pressedKey.Key.Equals(ConsoleKey.Enter)) { if (nearbyNPC) { foreach (NPC npc in NPCsOfCurrentLevel) { if (Math.Abs(npc.Position.row - hero.Position.row) <= 1 && Math.Abs(npc.Position.col - hero.Position.col) <= 1) { Conversation conversation = new Conversation(); conversation.DrawConversation(hero, npc); draw.DrawMatrixInConsole(matrix); } } } } else if (pressedKey.Key.Equals(ConsoleKey.Escape)) { MenuInGame menuInGame = new MenuInGame(); menuInGame.Menu(hero); if (menuInGame.GetChoice == 3) { LoadSaveGame.Save(hero); } else if (menuInGame.GetChoice == 4) { hero = LoadSaveGame.Load(); } Console.ResetColor(); Console.Clear(); draw.DrawMatrixInConsole(matrix); } }
private void MenuShowHeroStats(Hero hero) { Drawer draw = new Drawer(); Console.ResetColor(); Console.Clear(); draw.DrawString("Name : " + hero.Name, ConsoleColor.Black, 4, 8); draw.DrawImage(hero.Image, ConsoleColor.Black, 5, 4); draw.DrawString("Strength: " + hero.Statistics.Strength, ConsoleColor.Black, 23, 45); draw.DrawString("Dexterity: " + hero.Statistics.Dexterity, ConsoleColor.Black, 25, 45); draw.DrawString("Willpower: " + hero.Statistics.EillPower, ConsoleColor.Black, 27, 45); draw.DrawString("Weapon: " + hero.Weapon.name, ConsoleColor.Black, 10, 45); draw.DrawString("Weapon Damage: " + hero.Weapon.damage, ConsoleColor.Black, 11, 45); draw.DrawString("Magic: " + hero.Weapon.magic.Name, ConsoleColor.Black, 13, 45); draw.DrawString("Magic Damage: " + hero.Weapon.magic.damage, ConsoleColor.Black, 14, 45); draw.DrawString("Magic Damage on Self: " + hero.Weapon.magic.damageOnSelf, ConsoleColor.Black, 15, 45); draw.DrawString("Magic Chance to Stun: " + hero.Weapon.magic.chanceToStun, ConsoleColor.Black, 16, 45); Console.SetCursorPosition(0, 0); Console.ReadKey(); }
public void StartBattle(Hero TheHero, Enemy TheEnemy, bool BossFight, VisualElement[,] matrix, List<NPC> NPCsOfCurrentLevel) { hero = TheHero; enemy = TheEnemy; totalHeroHP = hero.Statistics.HitPoints; currentHeroHP = totalHeroHP; totalEnemyHP = enemy.Statistics.HitPoints; currentEnemyHP = totalEnemyHP; DrawBattle(hero, enemy); while (currentHeroHP > 0 && currentEnemyHP > 0) { ProcessInput(Console.ReadKey()); Thread.Sleep(1000); DrawBattle(hero, enemy); if (escapeSuccessful) { break; } if (currentEnemyHP < 1) { break; } EnemyAttack(); Thread.Sleep(1000); DrawBattle(hero, enemy); enemyIsCrippled = false; } if (currentHeroHP < 1) { // game over TheHero.LevelUp(); hero.Position = new Position(0, 0); Loader load = new Loader(); NPCsOfCurrentLevel.Clear(); matrix = load.LoadLevel(matrix, TheHero, NPCsOfCurrentLevel); } else { if (BossFight) { TheHero.LevelUp(); hero.Position = new Position(0, 0); if (TheHero.level > 3) { // Game compleated } MenuChangeWeapon newWeapon = new MenuChangeWeapon(); newWeapon.GetRandomWeapon(TheHero); Loader load = new Loader(); NPCsOfCurrentLevel.Clear(); matrix = load.LoadLevel(matrix, TheHero, NPCsOfCurrentLevel); } else if (!escapeSuccessful) { DiceRoller dice = new DiceRoller(); if (dice.NewDice(0.5)) { MenuChangeWeapon newWeapon = new MenuChangeWeapon(); newWeapon.GetRandomWeapon(TheHero); } } } }
void DrawBattle(Hero hero, Enemy enemy) { Drawer draw = new Drawer(); Console.BackgroundColor = ConsoleColor.Black; Console.Clear(); int heroLifeBarBlocks = (int)(20 * (double)currentHeroHP / totalHeroHP); int enemyLifeBarBlocks = (int)(20 * (double)currentEnemyHP / totalEnemyHP); if (heroLifeBarBlocks < 0) { heroLifeBarBlocks = 0; } if (enemyLifeBarBlocks < 0) { enemyLifeBarBlocks = 0; } draw.DrawString(hero.Name + " (" + hero.level + ")", ConsoleColor.DarkGray, 2, 5); draw.DrawString(new string(' ', heroLifeBarBlocks), ConsoleColor.DarkRed, 3, 15); draw.DrawString(currentHeroHP + " / " + totalHeroHP, ConsoleColor.DarkRed, 3, 36); draw.DrawImage(hero.Image, ConsoleColor.Black, 5, 5); for (int i = 0; i < 7; i++) { draw.DrawString(boxRow, ConsoleColor.DarkYellow, 40 + i, 10); if (i == 1) { draw.DrawString("Press [A] to Attack", ConsoleColor.DarkYellow, 40 + i, 13); } else if (i == 3) { draw.DrawString("Press [S] to use a Spell", ConsoleColor.DarkYellow, 40 + i, 13); } else if (i == 5) { draw.DrawString("Press [E] to Escape", ConsoleColor.DarkYellow, 40 + i, 13); } } draw.DrawString(enemy.Name, ConsoleColor.DarkGray, 2, 55); draw.DrawString(new string(' ', enemyLifeBarBlocks), ConsoleColor.DarkRed, 3, 65); draw.DrawString(currentEnemyHP + " / " + totalEnemyHP, ConsoleColor.DarkRed, 3, 86); draw.DrawImage(enemy.Image, ConsoleColor.Black, 5, 55); for (int i = 0; i < 7; i++) { draw.DrawString(boxRow, ConsoleColor.DarkYellow, 40 + i, 60); draw.DrawString(message[i], ConsoleColor.DarkYellow, 40 + i, 63); } Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition(0,0); }