Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <stdexcept>
- #include <string>
- #include <vector>
- #include <FL/Fl.H>
- #include <FL/Fl_Window.H>
- #include <FL/Fl_Button.H>
- #include <Graph_lib/Graph.h>
- #include <Graph_lib/Simple_window.h>
- using namespace Graph_lib;
- int window_x_len = 600;
- int window_y_len = 400;
- int step_from_edge = 50;
- int button_size = 100;
- void button_callback(Fl_Widget *widget, void *data) {
- //std::string *label = (std::string*)data;
- //std::cout << "Pushed: " << *label << std::endl;
- //std::cout << "CB " << data << std::endl;
- std::pair <int, int> *xy = (std::pair <int, int>*)data;
- std::cout << "Pushed: " << (*xy).first << ' ' << (*xy).second << "\n";
- }
- //free = 1, used = -1
- struct Cell {
- //int x;
- //int y;
- std::pair <int, int> crd;
- //std::string state;
- Fl_Button *button;
- Cell(const Cell & ) = delete;
- // Cell( Cell & ) = delete;
- // operator= ()
- Cell () {
- //this->x = 0;
- //this->y = 0;
- this->crd.first = 0;
- this->crd.second = 0;
- //this->state = "free";
- this->button = new Fl_Button(0, 0, 0, 0, "");
- this->button->color(FL_WHITE);
- //std::cout << "Cell " << std::endl;
- }
- Cell (int X, int Y) {
- //this->x = X;
- //this->y = Y;
- //this->state = "free";
- this->crd.first = X;
- this->crd.second = Y;
- this->button = new Fl_Button(step_from_edge + button_size * X, step_from_edge + button_size * Y, button_size, button_size, "");
- this->button->color(FL_WHITE);
- this->button->callback(button_callback, (void*)&(this->crd));
- //std::cout << "Cell " << X << Y << std::endl;
- }
- ~Cell() {
- delete this->button;
- }
- };
- //0-ничего, 1-крестик,2 - нолик
- std::vector <std::vector <Cell*>> playing_field;
- int main ()
- try
- {
- Fl_Window *window = new Fl_Window(100,400,window_x_len, window_y_len , "Window");
- playing_field.resize(3);
- for (int i = 0; i < 3; ++i) {
- playing_field[i].resize(3);
- }
- for (int y = 0; y < 3; ++y) {
- for (int x = 0; x < 3; ++x) {
- // Cell new_Cell(x, y);
- // Cell new_Cell = new Cell(x, y);
- playing_field[y][x] = new Cell(x, y);
- }
- }
- window->end();
- window->show();
- return Fl::run();
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- return 1;
- }
- catch (...)
- {
- std::cerr << "Oops, something went wrong..." << std::endl;
- return 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement