private void RootFrame_Key_Released(VirtualKeys Key, ControlKeyState KeyModifiers) { addLog("Key Released: " + (KeyModifiers > 0 ? (KeyModifiers.ToString() + " + " + Key.ToString()) : Key.ToString())); }
private void RootFrame_Key_Pressed(VirtualKeys Key, ControlKeyState KeyModifiers) { addLog("Key Pressed: " + (KeyModifiers > 0 ? (KeyModifiers.ToString() + " + " + Key.ToString()) : Key.ToString())); // get player movement keys, then make sure the map is walkable if (Key == VirtualKeys.W && _caveMap.IsWalkable(_player.X, _player.Y - 1)) { _player.Y--; } if (Key == VirtualKeys.D && _caveMap.IsWalkable(_player.X + 1, _player.Y)) { _player.X++; } if (Key == VirtualKeys.S && _caveMap.IsWalkable(_player.X, _player.Y + 1)) { _player.Y++; } if (Key == VirtualKeys.A && _caveMap.IsWalkable(_player.X - 1, _player.Y)) { _player.X--; } // move the map frame around if (Key == VirtualKeys.Up) { _mapFrame.Y--; } if (Key == VirtualKeys.Right) { _mapFrame.X++; } if (Key == VirtualKeys.Down) { _mapFrame.Y++; } if (Key == VirtualKeys.Left) { _mapFrame.X--; } // hide, or unhide the console cursor if (Key == VirtualKeys.Tab) { SetCursorVisibility(1, !CursorVisible); addLog("Cursor Visible: " + CursorVisible.ToString()); } // check to see if there's a downfloor. if there is, generate a new map if (KeyModifiers == ControlKeyState.ShiftPressed) { // KEY: SHIFT + . = > if (Key == VirtualKeys.OEMPeriod) { if (_caveMap.DownFloorPosition == _player) { string msg = "Do you wish to drop down a floor? yes/no\n"; using (ConsoleFrame frame = new ConsoleFrame((Width / 2) - (msg.Length / 2), 10, msg.Length, 3)) { frame.SetCursorVisibility(100, true); frame.Write(0, 1, msg, ConsoleColor.White, ConsoleColor.DarkBlue, true); frame.WriteBuffer(); VirtualKeys ans = frame.ReadAsVirtualKey(); if (ans == VirtualKeys.Y) { frame.Clear(); frame.Write(1, 1, "Generating cave...", ConsoleColor.White); frame.WriteBuffer(); _caveMap.Generate(80, 80); _player = _caveMap.UpFloorPosition; } frame.SetCursorVisibility(1, false); } } } } // see if the player wants to quit if (KeyModifiers == ControlKeyState.LeftCtrlPressed || KeyModifiers == ControlKeyState.RightCtrlPressed) { // KEYS: CTRL + Q if (Key == VirtualKeys.Q) { string msg = "Are you sure you want to quit? yes/no\n"; using (ConsoleFrame frame = new ConsoleFrame((Width / 2) - (msg.Length / 2), 10, msg.Length, 3)) { frame.SetCursorVisibility(100, true); frame.Write(0, 1, msg, ConsoleColor.White, ConsoleColor.DarkBlue, true); frame.WriteBuffer(); VirtualKeys ans = frame.ReadAsVirtualKey(); if (ans == VirtualKeys.Y) { Stop(); _caveMap = null; } frame.SetCursorVisibility(1, false); } } } }