Example #1
0
View::View(QWidget *parent):
    QGraphicsView(parent)
{
    setGeometry(300,300,GS_WIDTH,GS_HEIGHT);
    menu_scene = new GraphicMenu(-width()/2,-height()/2,width(),height(),this);
    board_scene = new GraphicBoard(-width()/2,-height()/2,width(),height(),this);

    QIcon icon(QPixmap(":/Graphic_source/icon.png"));
    setWindowIcon(icon);

    setWindowTitle("Pentago");
    setFixedSize(this->size());//TODO:equally resize
    setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    setCacheMode(QGraphicsView::CacheBackground);
    setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

    connect(menu_scene, SIGNAL(New_game_selected(int)), this, SIGNAL(New_game(int)));
    connect(menu_scene, SIGNAL(Join_game_selected(std::string)), this, SIGNAL(Join_game(std::string)));
    connect(menu_scene, SIGNAL(Host_game_selected(std::string)), this, SIGNAL(Host_game(std::string)));
    connect(menu_scene, SIGNAL(Exit_game_pressed()), this, SLOT(close()));
    connect(menu_scene, SIGNAL(Load_game_selected(std::string)),this,SIGNAL(Load_game(std::string)));

    connect(board_scene, SIGNAL(quadrant_rotated(IView::quadrant,IView::turn)), this, SIGNAL(Rotate(IView::quadrant,IView::turn)));
    connect(board_scene, SIGNAL(Stone_clicked(int, int)), this, SIGNAL(Put_stone(int,int)));
    connect(board_scene, SIGNAL(leave_game()),this,SLOT(on_leave_game()));
    connect(board_scene, SIGNAL(save_game(QString)),this,SLOT(on_save_game(QString)));

    connect(board_scene, SIGNAL(message_sended(QString)), this, SLOT(on_msg_sended(QString)));

    connect(menu_scene, SIGNAL(game_go_to_start()),board_scene, SLOT(clean_board()));
    connect(menu_scene, SIGNAL(game_go_to_start()),board_scene, SLOT(clean_log()));
    Set_control_settings(View::MENU);//it must be called in presenter after view constructing
}
Example #2
0
Game::Game(shared_ptr<IView> _view)
    : userInterface(std::move(_view))
{
    Q_ASSERT(userInterface);

    players.push_back(std::make_unique<Player>("Player 1"));
    players.push_back(std::make_unique<Player>("Player 2"));

    auto v = userInterface.get();

    // connect View to Presenter
    connect(v, SIGNAL(New_game(int)), this, SLOT(new_game(int)));
    connect(v, SIGNAL(Save_game(std::string)), this, SLOT(save_game(std::string)));
    connect(v, SIGNAL(Load_game(std::string)), this, SLOT(load_game(std::string)));
    connect(v, SIGNAL(Host_game(std::string)), this, SLOT(host_game(std::string)));
    connect(v, SIGNAL(Join_game(std::string)), this, SLOT(join_game(std::string)));
    connect(v, SIGNAL(Leave()), this, SLOT(leave()));
    connect(v, SIGNAL(Put_stone(int,int)), this, SLOT(put_stone(int,int)));
    connect(v, SIGNAL(Rotate(IView::quadrant,IView::turn)), this, SLOT(rotate(IView::quadrant,IView::turn)));

    // connect Presenter to View
    connect(this, SIGNAL(draw_stone(int,int,IView::color)),v,SLOT(Draw_stone(int,int,IView::color)));
    connect(this, SIGNAL(set_control_settings(IView::control_setting)),v,SLOT(Set_control_settings(IView::control_setting)));
    connect(this, SIGNAL(message(string)), v, SLOT(Show_message(string)));
}
Example #3
0
Game::Game() {
    players.push_back(unique_ptr<Player>(new Player("Player 1")));
    players.push_back(unique_ptr<Player>(new Player("Player 2")));

    // init View here
    userInterface.reset(new View());
    shared_ptr<View> v = std::dynamic_pointer_cast<View>(userInterface);

    // connect View to Presenter
    connect(v.get(), SIGNAL(New_game(int)), this, SLOT(new_game(int)));
    connect(v.get(), SIGNAL(Save_game(std::string)), this, SLOT(save_game(std::string)));
    connect(v.get(), SIGNAL(Load_game(std::string)), this, SLOT(load_game(std::string)));
    connect(v.get(), SIGNAL(Host_game(std::string)), this, SLOT(host_game(std::string)));
    connect(v.get(), SIGNAL(Join_game(std::string)), this, SLOT(join_game(std::string)));
    connect(v.get(), SIGNAL(Leave()), this, SLOT(leave()));
    connect(v.get(), SIGNAL(Put_stone(int,int)), this, SLOT(put_stone(int,int)));
    connect(v.get(), SIGNAL(Rotate(IView::quadrant,IView::turn)), this, SLOT(rotate(IView::quadrant,IView::turn)));

    // connect Presenter to View
    connect(this, SIGNAL(draw_stone(int,int,IView::color)),v.get(),SLOT(Draw_stone(int,int,IView::color)));
    connect(this, SIGNAL(set_control_settings(IView::control_setting)),v.get(),SLOT(Set_control_settings(IView::control_setting)));
    connect(this, SIGNAL(message(string)), v.get(), SLOT(Show_message(string)));
}