static void Main(string[] args) { Console.SetWindowSize(121, 22); buffer = new ConsoleBuffer(width, height, height - 4); ConsoleKeyInfo k; do { pl = new Player(); level = 1; inCombat = false; buffer.ClearBox(); Introduccion(); Level.StartLevel(GetRoomsPerLevel()); lvlLayout = Level.GetListOfRooms(); pl.currentRoom = lvlLayout[0]; MainScreen(); if (pl.IsDead()) { buffer.Print(43, 10, "--HAS MUERTO--"); } else { buffer.Print(41, 10, "--TE HAS RENDIDO--"); } buffer.Print(39, 11, "pulsa r para reiniciar"); buffer.PrintScreen(); k = Console.ReadKey(); } while (k.Key == ConsoleKey.R); }
public static bool DrawMap() { int miniMapx = pl.currentRoom.GetPosX() * 2; int miniMapy = pl.currentRoom.GetPosY() * 2; ConsoleKeyInfo keyInfo; do { for (int i = 0; i < lvlLayout.Count; i++) { if (lvlLayout[i].IsVisible() != 0) { int xx = (lvlLayout[i].GetPosX()) * 2 - miniMapx + (width - 20) / 2; int yy = (-lvlLayout[i].GetPosY()) * 2 + miniMapy + height / 2; if (xx >= 1 && xx < width - 21 && yy >= 2 && yy < height - 1) { if (lvlLayout[i].IsVisible() == 2) { if (pl.currentRoom.GetPosX() == lvlLayout[i].GetPosX() && pl.currentRoom.GetPosY() == lvlLayout[i].GetPosY()) { buffer.Print(xx, yy, "O"); } else if (lvlLayout[i].GetType() == typeof(RoomGema)) { buffer.Print(xx, yy, "Z"); } else if (lvlLayout[i].GetType() == typeof(RoomExit)) { buffer.Print(xx, yy, "S"); } else if (lvlLayout[i].GetType() == typeof(RoomClosed)) { buffer.Print(xx, yy, "T"); } else if (lvlLayout[i].GetType() == typeof(RoomBless)) { buffer.Print(xx, yy, "B"); } else { buffer.Print(xx, yy, "X"); } if (lvlLayout[i].GetNorthRoom() != null) { if (yy >= 3) { buffer.Print(xx, yy - 1, "|"); } } if (lvlLayout[i].GetSouthRoom() != null) { if (yy < height - 2) { buffer.Print(xx, yy + 1, "|"); } } if (lvlLayout[i].GetWestRoom() != null) { if (xx > 0) { buffer.Print(xx - 1, yy, "-"); } } if (lvlLayout[i].GetEastRoom() != null) { if (xx < width - 22) { buffer.Print(xx + 1, yy, "-"); } } } else { if (pl.currentRoom.GetPosX() == lvlLayout[i].GetPosX() && pl.currentRoom.GetPosY() == lvlLayout[i].GetPosY()) { throw new Exception("Sala invisible en propia localización"); } else { buffer.Print(xx, yy, "?"); } if (lvlLayout[i].IsVisible() == 3) { if (lvlLayout[i].GetNorthRoom() != null) { if (yy >= 3) { buffer.Print(xx, yy - 1, "|"); } } if (lvlLayout[i].GetSouthRoom() != null) { if (yy < height - 2) { buffer.Print(xx, yy + 1, "|"); } } if (lvlLayout[i].GetWestRoom() != null) { if (xx > width - 19) { buffer.Print(xx - 1, yy, "-"); } } if (lvlLayout[i].GetEastRoom() != null) { if (xx < width - 2) { buffer.Print(xx + 1, yy, "-"); } } } } } } } buffer.Print(1, 0, "MAP"); buffer.Print(71, 0, "Usa flechas para mover mapa"); buffer.Print(1, 2, "O -> Tu"); buffer.Print(1, 3, "T, Z, B -> Especial"); buffer.Print(1, 4, "S -> Salida"); buffer.Print(101, 0, "Planta: " + -(level - 1)); buffer.PrintBackground(); buffer.PrintScreen(); keyInfo = Console.ReadKey(); switch (keyInfo.Key) { case ConsoleKey.DownArrow: miniMapy -= 2; break; case ConsoleKey.UpArrow: miniMapy += 2; break; case ConsoleKey.LeftArrow: miniMapx -= 2; break; case ConsoleKey.RightArrow: miniMapx += 2; break; } } while (keyInfo.Key == ConsoleKey.RightArrow || keyInfo.Key == ConsoleKey.LeftArrow || keyInfo.Key == ConsoleKey.UpArrow || keyInfo.Key == ConsoleKey.DownArrow); return(true); }
public static void Combate(Enemigo ene) { StartCombate(); buffer.InsertText("¡Ha aparecido un " + ene.GetName() + "!"); BackgroundCombat(); string[] comandos = { "atacar", "defender", "huir", "consumir", "habilidad" }; bool huir = false; int itemHuir = -1; while (!(pl.IsDead() || ene.IsDead() || huir)) { Console.SetCursorPosition(1, 18); string decide = Console.ReadLine().ToLower(); buffer.InsertText(""); buffer.InsertText(decide); if (decide.Equals(comandos[0])) { Attack(pl, ene); } else if (decide.Equals(comandos[1])) { buffer.InsertText("Te has puesto en guardia"); AtaqueDirigidoA(ene, pl, -2); } else if (decide.Equals(comandos[2])) { float rand = (float)CustomMath.RandomUnit(); float probHuida = (pl.GetMaldicion(3)) ? 0.25f + pl.GetSpeed() / (float)(2 * (pl.GetSpeed() + ene.GetSpeed())) : 0.25f + pl.GetSpeed() / (float)(pl.GetSpeed() + ene.GetSpeed()); if (rand < probHuida) { buffer.InsertText("¡Has huido!"); huir = true; } else { if (pl.GetMaldicion(3) && rand < (probHuida - 0.25f) * 2 + 0.25f) { buffer.InsertText("Notas como las piernas no te responden y eres incapaz de moverte"); } else { buffer.InsertText("¡No has podido huir!"); AtaqueDirigidoA(ene, pl); } } } else if (decide.Equals(comandos[3])) { int i = Comando.ConsumeItemCombat(); if (i > -1) { if (pl.GetBag()[i].GetType() == typeof(ItemScroll)) { ItemScroll itemScroll = (ItemScroll)pl.GetBag()[i]; if (itemScroll.GetId() == 1) { itemHuir = i; huir = true; } } if (itemHuir == -1) { pl.ConsumeItem(i); AtaqueDirigidoA(ene, pl); } } } else if (decide.Equals(comandos[4])) { buffer.InsertText("¿Que habilidad quieres usar?"); buffer.InsertText("[0]-> Ataque Veloz [1]-> Golpe Aplastador [2]-> Curación Menor [3]-> MegaGolpe [4]-> Dardos Mágicos"); buffer.Print(1, buffer.height - 2, ">"); BackgroundCombat(); Console.SetCursorPosition(2, Program.buffer.height - 2); bool obj = int.TryParse(Console.ReadLine(), out int num); if (!obj) { Program.buffer.InsertText("Solo acepta numeros"); } else if (num >= 0 && num <= 4) { bool used = true; if (num == 0 && pl.GetMana() - 10 >= 0) { pl.SetMana(pl.GetMana() - 10); } else if (num == 1 && pl.GetMana() - 5 >= 0) { pl.SetMana(pl.GetMana() - 5); } else if (num == 2 && pl.GetMana() - 5 >= 0) { pl.SetMana(pl.GetMana() - 5); } else if (num == 3 && pl.GetMana() - 10 >= 0) { pl.SetMana(pl.GetMana() - 10); } else if (num == 4 && pl.GetMana() - 10 >= 0) { pl.SetMana(pl.GetMana() - 10); } else { buffer.InsertText("No tienes suficiente maná"); used = false; } if (used) { Attack(pl, ene, num); } } else { Program.buffer.InsertText("Ese número no es válido"); } } else { buffer.InsertText("Comando no valido"); } BackgroundCombat(); } if (pl.IsDead()) { buffer.InsertText("Has muerto..."); } else if (ene.IsDead()) { buffer.InsertText(""); int exp = 5 + 3 * ene.GetLevel(); buffer.InsertText("¡Has derrotado a " + ene.GetName() + "!"); int money = CustomMath.RandomIntNumber(5 + 5 * Program.GetLevel(), 5 + 2 * Program.GetLevel()); buffer.InsertText("Has conseguido " + money + " monedas"); pl.GainMoney(money); pl.currentRoom.ene = null; } if (huir && itemHuir == -1) { ene.RestoreHealth(); pl.currentRoom.SetVisible(1); switch (pl.lastRoom) { case 0: Comando.MoveNorth(); break; case 1: Comando.MoveWest(); break; case 2: Comando.MoveSouth(); break; case 3: Comando.MoveEast(); break; default: throw new Exception("Error a la hora de huir"); } } else if (huir) { ene.RestoreHealth(); pl.ConsumeItem(itemHuir); } buffer.InsertText("pulsa cualquier boton para continuar"); BackgroundCombat(); Console.ReadKey(); }