Advertisement
Korotkodul

playing_field_1

Nov 25th, 2024 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <stdexcept>
  4. #include <string>
  5. #include <vector>
  6.  
  7. #include <FL/Fl.H>
  8. #include <FL/Fl_Window.H>
  9. #include <FL/Fl_Button.H>
  10.  
  11. #include <Graph_lib/Graph.h>
  12. #include <Graph_lib/Simple_window.h>
  13.  
  14. using namespace Graph_lib;
  15.  
  16. int window_x_len = 600;
  17. int window_y_len = 400;
  18. int step_from_edge = 50;
  19. int button_size = 100;
  20.  
  21. void button_callback(Fl_Widget *widget, void *data) {
  22.     //std::string *label = (std::string*)data;
  23.     //std::cout << "Pushed: " << *label << std::endl;
  24.     //std::cout << "CB " << data << std::endl;
  25.     std::pair <int, int> *xy = (std::pair <int, int>*)data;
  26.     std::cout << "Pushed: " << (*xy).first << ' ' << (*xy).second << "\n";
  27.  
  28. }
  29. //free = 1, used = -1
  30.  
  31.  
  32.  
  33.  
  34. struct Cell {
  35.   //int x;
  36.   //int y;
  37.   std::pair <int, int> crd;
  38.   //std::string state;
  39.   Fl_Button *button;
  40.   Cell(const Cell & ) = delete;
  41.   // Cell( Cell & ) = delete;
  42.   // operator= ()
  43.  
  44.   Cell () {
  45.     //this->x = 0;
  46.     //this->y = 0;
  47.     this->crd.first = 0;
  48.     this->crd.second = 0;
  49.     //this->state = "free";
  50.     this->button = new Fl_Button(0, 0, 0, 0, "");
  51.     this->button->color(FL_WHITE);
  52.     //std::cout << "Cell "  << std::endl;
  53.   }
  54.   Cell (int X, int Y) {
  55.     //this->x = X;
  56.     //this->y = Y;
  57.     //this->state = "free";
  58.     this->crd.first = X;
  59.     this->crd.second = Y;
  60.     this->button = new Fl_Button(step_from_edge + button_size * X, step_from_edge + button_size * Y, button_size, button_size, "");
  61.     this->button->color(FL_WHITE);
  62.     this->button->callback(button_callback, (void*)&(this->crd));
  63.     //std::cout << "Cell " << X << Y << std::endl;
  64.  
  65.   }
  66.   ~Cell() {
  67.     delete this->button;
  68.   }
  69. };
  70. //0-ничего, 1-крестик,2 - нолик
  71.  
  72. std::vector <std::vector <Cell*>> playing_field;
  73.  
  74.  
  75. int main ()
  76. try
  77. {
  78.   Fl_Window *window = new Fl_Window(100,400,window_x_len, window_y_len , "Window");
  79.  
  80.   playing_field.resize(3);
  81.   for (int i = 0; i < 3; ++i) {
  82.     playing_field[i].resize(3);
  83.   }
  84.   for (int y = 0; y < 3; ++y) {
  85.     for (int x = 0; x < 3; ++x) {
  86.       // Cell new_Cell(x, y);
  87.       // Cell new_Cell = new Cell(x, y);
  88.       playing_field[y][x] = new Cell(x, y);
  89.     }
  90.   }
  91.   window->end();
  92.   window->show();
  93.   return Fl::run();
  94. }
  95. catch (std::exception& e)
  96. {
  97.   std::cerr << e.what() << std::endl;
  98.   return 1;
  99. }
  100. catch (...)
  101. {
  102.   std::cerr << "Oops, something went wrong..." << std::endl;
  103.   return 2;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement