Advertisement
Korotkodul

playing_field

Nov 25th, 2024 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 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::pair <int, int> *xy = (std::pair <int, int>*)data;
  25.     std::cout << "Pushed: " << (*xy).first << ' ' << (*xy).second << "\n";
  26. }
  27. //free = 1, used = -1
  28. std::string Cell_name = "some cell";
  29.  
  30.  
  31.  
  32.  
  33. struct Cell {
  34.   //int x;
  35.   //int y;
  36.   std::pair <int, int> crd;
  37.   //std::string state;
  38.   Fl_Button *button;
  39.   Cell () {
  40.     //this->x = 0;
  41.     //this->y = 0;
  42.     this->crd.first = 0;
  43.     this->crd.second = 0;
  44.     //this->state = "free";
  45.     this->button = new Fl_Button(0, 0, 0, 0, "");
  46.     this->button->color(FL_WHITE);
  47.   }
  48.   Cell (int X, int Y) {
  49.     //this->x = X;
  50.     //this->y = Y;
  51.     //this->state = "free";
  52.     this->crd.first = X;
  53.     this->crd.second = Y;
  54.     this->button = new Fl_Button(step_from_edge + button_size * X, step_from_edge + button_size * Y, button_size, button_size, "");
  55.     this->button->color(FL_WHITE);
  56.     std::pair <int, int> crd{X, Y};
  57.     this->button->callback(button_callback, (void*)&(this->crd));
  58.   }
  59. };
  60.  
  61. std::vector <std::vector <Cell>> playing_field;
  62.  
  63. // Функция для обработки нажатия кнопки
  64.  
  65.  
  66. int main ()
  67. try
  68. {
  69.   Fl_Window *window = new Fl_Window(window_x_len, window_y_len, "Window");
  70.  
  71.   playing_field.resize(3);
  72.   for (int i = 0; i < 3; ++i) {
  73.     playing_field.resize(3);
  74.   }
  75.   for (int y = 0; y < 3; ++y) {
  76.     for (int x = 0; x < 3; ++x) {
  77.       Cell new_Cell(x, y);
  78.     }
  79.   }
  80.   window->end();
  81.   window->show();
  82.   return Fl::run();
  83. }
  84. catch (std::exception& e)
  85. {
  86.   std::cerr << e.what() << std::endl;
  87.   return 1;
  88. }
  89. catch (...)
  90. {
  91.   std::cerr << "Oops, something went wrong..." << std::endl;
  92.   return 2;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement