Advertisement
kolbka_

Untitled

Dec 12th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. #include <boost/config.hpp>
  2. #include <regex>
  3. #include "../include/view.h"
  4. struct BOOST_SYMBOL_VISIBLE view_pretty : abstract_view {
  5. private:
  6.     static const int width_field = 50;
  7.     static const int heigth_field = 30;
  8.     static const int height_cell = 5;
  9.     static const int width_cell = 3;
  10.     static void print_cell_border() {
  11.         std::cout << "  ";
  12.         for (int j = 0; j < width_field; j++) {
  13.             if (j % height_cell == 0) {
  14.                 std::cout << "+";
  15.             } else {
  16.                 std::cout << "-";
  17.             }
  18.         }
  19.         std::cout << "+" << std::endl;
  20.     }
  21.  
  22.     void print_inside_cell(int cur_x, int cur_y) const {
  23.         if (pointer_game->map[cur_x / height_cell][cur_y / width_cell] ==
  24.             tictactoe::OptionalPlayer::X) {
  25.             if (cur_y % width_cell == 1) {
  26.                 std::cout << " \\/ ";
  27.             } else {
  28.                 std::cout << " /\\ ";
  29.             }
  30.         } else if (pointer_game->map[cur_x / height_cell][cur_y / width_cell] ==
  31.                    tictactoe::OptionalPlayer::O) {
  32.             std::cout << " @@ ";
  33.         } else {
  34.             std::cout << "    ";
  35.         }
  36.     }
  37.  
  38. public:
  39.     void print_map() const final {
  40.         int digit_coordinate_outside_map = 9;
  41.         for (int i = 0; i <= heigth_field; i++) {
  42.             if (i % width_cell == 0) {
  43.                 print_cell_border();
  44.             } else {
  45.                 if (i % width_cell == 1) {
  46.                     std::cout << digit_coordinate_outside_map << " ";
  47.                     digit_coordinate_outside_map--;
  48.                 } else {
  49.                     std::cout << "  ";
  50.                 }
  51.                 for (int j = 0; j < width_field; j++) {
  52.                     if (j % height_cell == 0) {
  53.                         std::cout << "|";
  54.                     } else {
  55.                         print_inside_cell(j, i);
  56.                         j += width_cell;
  57.                     }
  58.                 }
  59.                 std::cout << "|" << std::endl;
  60.             }
  61.         }
  62.         char letter = 'a';
  63.         std::cout << "  ";
  64.         for (int i = 0; i <= width_field; i++) {
  65.             if (i % height_cell == 2) {
  66.                 std::cout << letter;
  67.                 letter += 1;
  68.             } else {
  69.                 std::cout << " ";
  70.             }
  71.         }
  72.         std::cout << std::endl;
  73.     }
  74.  
  75.     std::pair<int, int> parse_line(std::string &line) final {
  76.         std::regex preset(R"(^[\s]*[a-z]{1}[0-9]{1}[\s]*$)");
  77.         if (std::regex_match(line, preset)) {
  78.             std::stringstream buffer;
  79.             buffer << line;
  80.             std::string new_line;
  81.             buffer >> new_line;
  82.             if (new_line[0] <= 'j' && new_line[0] >= 'a' &&
  83.                 new_line[1] >= '0' && new_line[1] <= '9') {
  84.                 return {new_line[0] - 'a', '9' - new_line[1]};
  85.             }
  86.         }
  87.         return {INT32_MAX, INT32_MAX};
  88.     }
  89. };
  90. // NOLINTNEXTLINE
  91. extern "C" BOOST_SYMBOL_EXPORT view_pretty view;
  92. // NOLINTNEXTLINE
  93. view_pretty view;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement