public bool Show() { var x = (TCODConsole.root.getWidth() / 2) - (Message.Length / 2 + 2); var width = Math.Max(13, Message.Length + 4); // Two for padding and two for the border var y = (TCODConsole.root.getHeight() / 2) - 3; var height = 6; TCODConsole.root.setForegroundColor(Foreground); TCODConsole.root.setBackgroundColor(Background); TCODConsole.root.printFrame(x, y, width, height, true, TCODBackgroundFlag.Set); TCODConsole.root.print(x + 2, y + 2, Message); TCODConsole.root.print(x + (width / 2) - 4, y + 3, "[Y] / [N]"); TCODConsole.flush(); TCODKey key = null; var character = 'N'; do { key = TCODConsole.waitForKeypress(true); character = char.ToUpper(key.Character); } while(character != 'Y' && character != 'N'); return(character == 'Y'); }
public void Update() { bool endturn; do { TCODKey key = TCODConsole.waitForKeypress(true); endturn = HandleKeyPress(key); Draw(); } while (!endturn && !Exit); if (!Exit) { Map.Update(); Draw(); if (Map.IntensityAt(_player.PosX, _player.PosY) == 0) { if (_turnInDark == 3) { Exit = true; } else { _turnInDark++; } } } }
public string Show() { LongestLine = Math.Max(Message.Length, Options.Max(line => line.Length)); X = (TCODConsole.root.getWidth() / 2) - (Message.Length / 2 + 2); Width = Math.Max(13, LongestLine + 4); // Two for padding and two for the border Y = (TCODConsole.root.getHeight() / 2) - 3; Height = Options.Length + 6; // 2 for border, 2 for padding, 2 for title w/ padding TCODKey key = null; Render(); do { key = TCODConsole.waitForKeypress(true); if (key.KeyCode == TCODKeyCode.Up) { SelectedIndex -= 1; if (SelectedIndex < 0) { SelectedIndex = Options.Length - 1; } } else if (key.KeyCode == TCODKeyCode.Down) { SelectedIndex += 1; if (SelectedIndex >= Options.Length) { SelectedIndex = 0; } } Render(); } while(key.KeyCode != TCODKeyCode.Enter && key.KeyCode != TCODKeyCode.Escape); return(key.KeyCode == TCODKeyCode.Enter ? Options[SelectedIndex] : null); }
private void end() { TCODConsole.root.clear(); TCODConsole.root.setForegroundColor(TCODColor.red); TCODConsole.root.print(35, 25, "You died"); TCODConsole.flush(); TCODConsole.waitForKeypress(true); }
public void Show() { var longestLine = MessageLines.Max(line => line.Length); var x = (TCODConsole.root.getWidth() / 2) - (longestLine / 2 + 2); var width = Math.Max(13, longestLine + 4); // Two for padding and two for the border var y = (TCODConsole.root.getHeight() / 2) - (MessageLines.Length / 2 + 2); var height = MessageLines.Length + 4; // Two for padding and two for the border TCODConsole.root.setForegroundColor(Foreground); TCODConsole.root.setBackgroundColor(Background); TCODConsole.root.printFrame(x, y, width, height, true, TCODBackgroundFlag.Set); for (int i = 0; i < MessageLines.Length; ++i) { TCODConsole.root.print(x + 2, y + 2 + i, MessageLines[i]); } TCODConsole.flush(); TCODConsole.waitForKeypress(true); }
public bool HandleKeyPress(TCODKey key) { bool endTurn = false; #region switch (key.KeyCode) switch (key.KeyCode) { case TCODKeyCode.KeypadZero: break; case TCODKeyCode.KeypadOne: _player.Move(-1, 1); endTurn = true; break; case TCODKeyCode.KeypadTwo: _player.Move(0, 1); endTurn = true; break; case TCODKeyCode.KeypadThree: _player.Move(1, 1); endTurn = true; break; case TCODKeyCode.KeypadFour: _player.Move(-1, 0); endTurn = true; break; case TCODKeyCode.KeypadFive: endTurn = true; break; case TCODKeyCode.KeypadSix: _player.Move(1, 0); endTurn = true; break; case TCODKeyCode.KeypadSeven: _player.Move(-1, -1); endTurn = true; break; case TCODKeyCode.KeypadEight: _player.Move(0, -1); endTurn = true; break; case TCODKeyCode.KeypadNine: _player.Move(1, -1); endTurn = true; break; case TCODKeyCode.KeypadAdd: break; case TCODKeyCode.KeypadSubtract: break; case TCODKeyCode.KeypadMultiply: break; case TCODKeyCode.KeypadDivide: break; case TCODKeyCode.KeypadEnter: break; case TCODKeyCode.KeypadDecimal: endTurn = true; break; case TCODKeyCode.Left: _player.Move(-1, 0); endTurn = true; break; case TCODKeyCode.Right: _player.Move(1, 0); endTurn = true; break; case TCODKeyCode.Up: _player.Move(0, -1); endTurn = true; break; case TCODKeyCode.Down: _player.Move(0, 1); endTurn = true; break; case TCODKeyCode.Alt: break; case TCODKeyCode.Apps: break; case TCODKeyCode.Backspace: break; case TCODKeyCode.Capslock: break; case TCODKeyCode.Char: break; case TCODKeyCode.Control: break; case TCODKeyCode.Delete: break; case TCODKeyCode.Eight: break; case TCODKeyCode.End: break; case TCODKeyCode.Enter: break; case TCODKeyCode.Escape: Exit = true; break; case TCODKeyCode.F1: break; case TCODKeyCode.F2: break; case TCODKeyCode.F3: break; case TCODKeyCode.F4: break; case TCODKeyCode.F5: break; case TCODKeyCode.F6: break; case TCODKeyCode.F7: break; case TCODKeyCode.F8: break; case TCODKeyCode.F9: break; case TCODKeyCode.F10: break; case TCODKeyCode.F11: break; case TCODKeyCode.F12: break; case TCODKeyCode.Five: break; case TCODKeyCode.Four: break; case TCODKeyCode.Home: break; case TCODKeyCode.Insert: break; case TCODKeyCode.Lwin: break; case TCODKeyCode.Nine: break; case TCODKeyCode.NoKey: break; case TCODKeyCode.Numlock: break; case TCODKeyCode.One: break; case TCODKeyCode.Pagedown: break; case TCODKeyCode.Pageup: break; case TCODKeyCode.Pause: break; case TCODKeyCode.Printscreen: break; case TCODKeyCode.Rwin: break; case TCODKeyCode.Scrolllock: break; case TCODKeyCode.Seven: break; case TCODKeyCode.Shift: break; case TCODKeyCode.Six: break; case TCODKeyCode.Space: break; case TCODKeyCode.Tab: break; case TCODKeyCode.Three: break; case TCODKeyCode.Two: break; case TCODKeyCode.Zero: break; } #endregion #region switch (key.Character) switch (key.Character) { #region Movement case 'h': _player.Move(-1, 0); endTurn = true; break; case 'j': _player.Move(0, 1); endTurn = true; break; case 'k': _player.Move(0, -1); endTurn = true; break; case 'l': _player.Move(1, 0); endTurn = true; break; case 'y': _player.Move(-1, -1); endTurn = true; break; case 'u': _player.Move(1, -1); endTurn = true; break; case 'b': _player.Move(-1, 1); endTurn = true; break; case 'n': _player.Move(1, 1); endTurn = true; break; case '.': endTurn = true; break; #endregion case 'd': _player.Inventory.Draw(_root); TCODConsole.flush(); key = TCODConsole.waitForKeypress(true); Item i = _player.Inventory.GetAtLetter(key.Character); _player.Inventory.RemoveAtLetter(key.Character, 1); if (i != null) { i.Drop(_player.PosX, _player.PosY, Map); } break; case 'g': foreach (Item item in Map.GetItemsAt(_player.PosX, _player.PosY)) { item.Get(); _player.Inventory.Add(item); } endTurn = true; break; case 'i': _player.Inventory.Draw(_root); TCODConsole.flush(); TCODConsole.waitForKeypress(true); break; case 'e': _player.Inventory.Draw(_root); TCODConsole.flush(); key = TCODConsole.waitForKeypress(true); i = _player.Inventory.GetAtLetter(key.Character); if (i != null) { _player.Equip(i); } endTurn = true; break; case 'r': _player.Inventory.Draw(_root); TCODConsole.flush(); key = TCODConsole.waitForKeypress(true); i = _player.Inventory.GetAtLetter(key.Character); if (i != null) { i.Use(); _player.Inventory.RemoveAllAtLetter(key.Character); endTurn = true; } break; case '>': if (_player.PosX == Map.Stair.PosX && _player.PosY == Map.Stair.PosY) { _dungeon.GoToMap(_dungeon.CurrentDepth + 1, _player); for (int n = Map.CurrentMonsterNum; n < Map.MaxMonster; n++) { AddMonster(Map); } } break; case '<': if (_player.PosX == Map.StartPosX && _player.PosY == Map.StartPosY) { if (_dungeon.CurrentDepth != 1) { _dungeon.GoToMap(_dungeon.CurrentDepth - 1, _player); } else { Messages.AddMessage("If you go up, you'll exit the Dungeon. Are you sure?"); key = TCODConsole.waitForKeypress(true); if (key.Character == 'Y') { Exit = true; } else if (key.Character != 'N') { Messages.AddMessage("Y or N only"); } } } break; #region Debug case 'w': ShowWall = !ShowWall; break; case 'a': MonsterAI = !MonsterAI; break; case 'z': MonsterDamage = !MonsterDamage; break; case 'q': InfiniteTorch = !InfiniteTorch; break; #endregion } #endregion return(endTurn); }
private void input() { bool moveon = false; while (!moveon && !TCODConsole.isWindowClosed()) { TCODKey key = TCODConsole.waitForKeypress(true); switch (key.KeyCode) { case TCODKeyCode.Up: case TCODKeyCode.KeypadEight: if (player.getPlayerY() > 0 && currentMap.getPassable(player.getPlayerX(), player.getPlayerY() - 1)) { if (currentMap.checkIfMonster(player.getPlayerX(), player.getPlayerY() - 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() && tempMon.getY() == player.getPlayerY() - 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerY(player.getPlayerY() - 1); moveon = true; } break; case TCODKeyCode.Down: case TCODKeyCode.KeypadTwo: if (player.getPlayerY() < 39 && currentMap.getPassable(player.getPlayerX(), player.getPlayerY() + 1)) { if (currentMap.checkIfMonster(player.getPlayerX(), player.getPlayerY() + 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() && tempMon.getY() == player.getPlayerY() + 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerY(player.getPlayerY() + 1); moveon = true; } break; case TCODKeyCode.Left: case TCODKeyCode.KeypadFour: if (player.getPlayerX() > 0 && currentMap.getPassable(player.getPlayerX() - 1, player.getPlayerY())) { if (currentMap.checkIfMonster(player.getPlayerX() - 1, player.getPlayerY())) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() - 1 && tempMon.getY() == player.getPlayerY()) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() - 1); moveon = true; } break; case TCODKeyCode.Right: case TCODKeyCode.KeypadSix: if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() + 1, player.getPlayerY())) { if (currentMap.checkIfMonster(player.getPlayerX() + 1, player.getPlayerY())) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() + 1 && tempMon.getY() == player.getPlayerY()) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() + 1); moveon = true; } break; case TCODKeyCode.KeypadSeven: if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() - 1, player.getPlayerY() - 1)) { if (currentMap.checkIfMonster(player.getPlayerX() - 1, player.getPlayerY() - 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() - 1 && tempMon.getY() == player.getPlayerY() - 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() - 1); player.setPlayerY(player.getPlayerY() - 1); moveon = true; } break; case TCODKeyCode.KeypadNine: if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() + 1, player.getPlayerY() - 1)) { if (currentMap.checkIfMonster(player.getPlayerX() + 1, player.getPlayerY() - 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() + 1 && tempMon.getY() == player.getPlayerY() - 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() + 1); player.setPlayerY(player.getPlayerY() - 1); moveon = true; } break; case TCODKeyCode.KeypadOne: if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() - 1, player.getPlayerY() + 1)) { if (currentMap.checkIfMonster(player.getPlayerX() - 1, player.getPlayerY() + 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() - 1 && tempMon.getY() == player.getPlayerY() + 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() - 1); player.setPlayerY(player.getPlayerY() + 1); moveon = true; } break; case TCODKeyCode.KeypadThree: if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() + 1, player.getPlayerY() + 1)) { if (currentMap.checkIfMonster(player.getPlayerX() + 1, player.getPlayerY() + 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() + 1 && tempMon.getY() == player.getPlayerY() + 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() + 1); player.setPlayerY(player.getPlayerY() + 1); moveon = true; } break; case TCODKeyCode.Char: switch (key.Character) { case 'q': if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()) != null) { if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsWeapon()) { textBox.Add("You looted " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getName() + " for " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality() + " gold"); player.addGold(currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality()); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsArmor()) { textBox.Add("You looted " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getName() + " for " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality() + " gold"); player.addGold(currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality()); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsGold()) { textBox.Add("You picked up " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality() + " gold"); player.addGold(currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality()); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsPotion()) { textBox.Add("You looted " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getName() + " for 10 gold"); player.addGold(10); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } } break; case 'w': if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()) != null) { if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsWeapon()) { textBox.Add("You looted " + player.getWeapon().getName() + " for " + player.getWeapon().getQuality() + " gold"); player.addGold(player.getWeapon().getQuality()); player.setWeapon(currentMap.getItem(player.getPlayerX(), player.getPlayerY())); textBox.Add("You equip " + player.getWeapon().getName()); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsArmor()) { textBox.Add("You looted " + player.getArmor().getName() + " for " + player.getArmor().getQuality() + " gold"); player.addGold(player.getArmor().getQuality()); player.setArmor(currentMap.getItem(player.getPlayerX(), player.getPlayerY())); textBox.Add("You equip " + player.getArmor().getName()); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } } break; case 'e': if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()) != null) { if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsPotion()) { player.setNowHP(player.getNowHP() + (player.getMaxHP() / 2)); textBox.Add("You drink the healing potion, and recover some lost health."); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } } else if (currentMap.getTransision().getX() == player.getPlayerX() && currentMap.getTransision().getY() == player.getPlayerY()) { textBox.Add("You transport yourself into another realm"); Map tmp = new Map(realmStarts[rand.Next(0, realmStarts.Length)] + realmNames[rand.Next(0, realmNames.Length)] + realmNames[rand.Next(0, realmNames.Length)] + ", The " + realmTypes[rand.Next(0, realmTypes.Length)] + " of " + realmTitles[currentMap.getLevel()], currentMap.getLevel() + 1); currentMap = tmp; player.setPlayerX(rand.Next(1, 44)); player.setPlayerY(rand.Next(1, 39)); moveon = true; } break; } break; } } }
public void WaitForAnyKeyPress() { // Wait for a keypress TCODConsole.flush(); TCODConsole.waitForKeypress(true); }
public void Update() { if (Player.TurnTimeout == 0) { var key = TCODConsole.waitForKeypress(true); Point dest = new Point(Player.Position.X, Player.Position.Y); switch (key.KeyCode) { case TCODKeyCode.Escape: Over = true; return; case TCODKeyCode.KeypadFour: case TCODKeyCode.Left: dest.X--; break; case TCODKeyCode.KeypadEight: case TCODKeyCode.Up: dest.Y--; break; case TCODKeyCode.KeypadSix: case TCODKeyCode.Right: dest.X++; break; case TCODKeyCode.KeypadTwo: case TCODKeyCode.Down: dest.Y++; break; case TCODKeyCode.KeypadSeven: dest.X--; dest.Y--; break; case TCODKeyCode.KeypadNine: dest.X++; dest.Y--; break; case TCODKeyCode.KeypadOne: dest.X--; dest.Y++; break; case TCODKeyCode.KeypadThree: dest.X++; dest.Y++; break; case TCODKeyCode.KeypadDecimal: case TCODKeyCode.KeypadFive: if (Player.Stamina < Player.MaxStamina) { Player.Stamina = Math.Min(Player.Stamina + 10, Player.MaxStamina); } if (Player.HP < Player.MaxHP && Game.Current.RNG.Next(8) == 0) { Player.HP = Math.Min(Player.HP + 1, Player.MaxHP); } break; case TCODKeyCode.Enter: if (TCODConsole.isKeyPressed(TCODKeyCode.Alt)) { TCODConsole.setFullscreen(!TCODConsole.isFullscreen()); } break; } if ((dest.X != Player.Position.X || dest.Y != Player.Position.Y) && Player.Stamina > 0) { Player.MoveToPosition(dest); Player.Stamina--; Player.TurnTimeout += 5 - Player.Speed; } } foreach (Character c in Area.Current.Characters) { c.Update(); } foreach (Decal d in Area.Current.Decals) { d.Update(); } if (Player.HP < 1) { Console.WriteLine("GAME OVER"); Draw(); while (true) { if (TCODConsole.waitForKeypress(true).KeyCode == TCODKeyCode.Escape) { Over = true; break; } } } }