2
0

ConsoleInput.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "Sample.h"
  24. /// Console input example.
  25. /// This sample demonstrates:
  26. /// - Implementing a crude text adventure game, which accepts input both through the engine console,
  27. /// and standard input.
  28. class ConsoleInput : public Sample
  29. {
  30. OBJECT(ConsoleInput);
  31. public:
  32. /// Construct.
  33. ConsoleInput(Context* context);
  34. /// Setup after engine initialization and before running the main loop.
  35. virtual void Start();
  36. private:
  37. /// Handle console command event.
  38. void HandleConsoleCommand(StringHash eventType, VariantMap& eventData);
  39. /// Handle frame update event.
  40. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  41. /// Handle ESC key down event to quit the engine.
  42. void HandleEscKeyDown(StringHash eventType, VariantMap& eventData);
  43. /// Print intro message and initialize the game state.
  44. void StartGame();
  45. /// Print game over message.
  46. void EndGame(const String& message);
  47. /// Advance the game state.
  48. void Advance();
  49. /// Handle user input either from the engine console or standard input.
  50. void HandleInput(const String& input);
  51. /// Print text to the engine console and standard output.
  52. void Print(const String& output);
  53. /// Game on flag.
  54. bool gameOn_;
  55. /// Food dispensed flag.
  56. bool foodAvailable_;
  57. /// Whether ate on the previous turn.
  58. bool eatenLastTurn_;
  59. /// Number of turns survived.
  60. int numTurns_;
  61. /// Player's hunger level.
  62. int hunger_;
  63. /// Threat of Urho level.
  64. int urhoThreat_;
  65. };