protected void OnKeyDownHandler(object sender, System.Windows.Input.KeyEventArgs e) { // this function is called after a keyboard signal from the user // first, do everything that base Page class wants to do base.OnKeyDown(e); currentSession.CurrentKey = e.Key.ToString(); if (!Movable) { return; // sometimes we don't want the player to move (e.g. when battling or selling items) } if (IgnoreNextKey) // see GameSession.LocationEvents for explanation { IgnoreNextKey = false; return; } // AvailableMoves[0..3] -> WSAD if ((e.Key == Key.Up || e.Key == Key.W) && currentSession.AvailableMoves[0]) { MovePlayer("up"); } if ((e.Key == Key.Down || e.Key == Key.S) && currentSession.AvailableMoves[1]) { MovePlayer("down"); } if ((e.Key == Key.Left || e.Key == Key.A) && currentSession.AvailableMoves[2]) { MovePlayer("left"); } if ((e.Key == Key.Right || e.Key == Key.D) && currentSession.AvailableMoves[3]) { MovePlayer("right"); } if ((e.Key == Key.Escape)) { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "savegame"; // Default file name dlg.DefaultExt = ".bin"; // Default file extension dlg.Filter = "Text documents (.bin)|*.bin"; // Filter files by extension Nullable <bool> result = dlg.ShowDialog(); if (result == true) { try { currentSession.SaveGame(dlg.FileName); pageData.CountItems(); IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(dlg.FileName + ".pgd", FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, pageData); stream.Close(); } catch (Exception exc) { AddConsoleText(exc.Message); } } } if (e.Key == Key.I) { AddConsoleText("Currently you have the following items:"); currentSession.ListAllItemsTips(); } if (e.Key == Key.U) { AddConsoleText("Currently you know the following skills:"); foreach (Skill sk in currentSession.currentPlayer.ListOfSkills) { AddConsoleText(sk.PublicName); } } }