main.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // Created by nositelshtanov on 11/11/2023.
  3. //
  4. #include "ttt_meta_session.h"
  5. #include "ttt_simple_session.h"
  6. #define TTT_SMPL_VARIANT "1 - play simple tic tac toe"
  7. #define TTT_META_VARIANT "2 - play meta (super) tic tac toe"
  8. #define TTT_RULES "coordinate is a number from 0 to 8:\n" \
  9. "(0) (1) (2)\n" \
  10. "(3) (4) (5)\n" \
  11. "(6) (7) (8)\n"
  12. #define TTT_GAME_KIND "game kind:"
  13. #define TTT_GAME_KIND_ERR "unknown game type"
  14. #define TTT_ERROR "sorry, an error was occured\n"
  15. #define SIMPLE_TTT 1
  16. #define META_TTT 2
  17. void print_greeting() {
  18. std::cout << TTT_RULES << std::endl;
  19. std::cout << TTT_SMPL_VARIANT << std::endl;
  20. std::cout << TTT_META_VARIANT << std::endl;
  21. }
  22. template <typename sess_type>
  23. void session_start() {
  24. sess_type game;
  25. game.play();
  26. }
  27. int main() {
  28. print_greeting();
  29. try {
  30. int game_king;
  31. std::cout << TTT_GAME_KIND;
  32. std::cin >> game_king;
  33. if (game_king == SIMPLE_TTT) {
  34. session_start<ttt_simple_session>();
  35. } else if (game_king == META_TTT) {
  36. session_start<ttt_meta_session>();
  37. } else {
  38. std::cout << TTT_GAME_KIND_ERR << std::endl;
  39. return 1;
  40. }
  41. } catch (const std::exception& excp) {
  42. std::cout << TTT_ERROR << excp.what() << std::endl;
  43. return 1;
  44. }
  45. return 0;
  46. }