#include <HangmanGame.h>

Public Member Functions | |
| HangmanGame (Wt::WContainerWidget *parent=0) | |
| void | handleInternalPath (const std::string &internalPath) |
Private Member Functions | |
| void | onLogin () |
| void | showLogin () |
| void | showGame () |
| void | showHighScores () |
Private Attributes | |
| Wt::WStackedWidget * | mainStack_ |
| LoginWidget * | login_ |
| HangmanWidget * | game_ |
| HighScoresWidget * | scores_ |
| Wt::WAnchor * | backToGameAnchor_ |
| Wt::WAnchor * | scoresAnchor_ |
| Session | session_ |
Definition at line 25 of file HangmanGame.h.
| HangmanGame::HangmanGame | ( | Wt::WContainerWidget * | parent = 0 ) |
Definition at line 21 of file HangmanGame.C.
: WContainerWidget(parent), game_(0), scores_(0) { WVBoxLayout *layout = new WVBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); this->setLayout(layout); WText *title = new WText("<h1>A Witty game: Hangman</h1>"); layout->addWidget(title); mainStack_ = new WStackedWidget(this); mainStack_->setStyleClass("gamestack"); layout->addWidget(mainStack_, 1, AlignJustify | AlignMiddle); mainStack_->addWidget(login_ = new LoginWidget(&session_)); login_->loggedIn().connect(this, &HangmanGame::onLogin); WContainerWidget *links = new WContainerWidget(); links->setStyleClass("links"); layout->addWidget(links); backToGameAnchor_ = new WAnchor("/play", "Gaming Grounds", links); backToGameAnchor_->setRefInternalPath("/play"); backToGameAnchor_->setStyleClass("link"); scoresAnchor_ = new WAnchor("/highscores", "Highscores", links); scoresAnchor_->setRefInternalPath("/highscores"); scoresAnchor_->setStyleClass("link"); WApplication::instance()->internalPathChanged() .connect(this, &HangmanGame::handleInternalPath); showLogin(); }
| void HangmanGame::handleInternalPath | ( | const std::string & | internalPath ) |
Definition at line 58 of file HangmanGame.C.
{
if (internalPath == "/play" && session_.user())
showGame();
else if (internalPath == "/highscores")
showHighScores();
else
showLogin();
}
| void HangmanGame::onLogin | ( | ) | [private] |
Definition at line 90 of file HangmanGame.C.
{
WApplication *app = WApplication::instance();
std::string path = app->internalPath();
if (path != "/highscores" && path != "/play")
app->setInternalPath("/play", true);
else
handleInternalPath(path);
}
| void HangmanGame::showGame | ( | ) | [private] |
Definition at line 101 of file HangmanGame.C.
{
if (!game_) {
game_ = new HangmanWidget(session_.user()->name,
session_.dictionary(),
mainStack_);
game_->updateScore().connect(&session_, &Session::addToScore);
}
mainStack_->setCurrentWidget(game_);
backToGameAnchor_->show();
scoresAnchor_->show();
backToGameAnchor_->addStyleClass("selected-link");
scoresAnchor_->removeStyleClass("selected-link");
}
| void HangmanGame::showHighScores | ( | ) | [private] |
Definition at line 75 of file HangmanGame.C.
{
if (!scores_)
scores_ = new HighScoresWidget(&session_, mainStack_);
mainStack_->setCurrentWidget(scores_);
scores_->update();
backToGameAnchor_->show();
scoresAnchor_->show();
backToGameAnchor_->removeStyleClass("selected-link");
scoresAnchor_->addStyleClass("selected-link");
}
| void HangmanGame::showLogin | ( | ) | [private] |
Definition at line 68 of file HangmanGame.C.
{
mainStack_->setCurrentWidget(login_);
backToGameAnchor_->hide();
scoresAnchor_->hide();
}
Wt::WAnchor* HangmanGame::backToGameAnchor_ [private] |
Definition at line 37 of file HangmanGame.h.
HangmanWidget* HangmanGame::game_ [private] |
Definition at line 35 of file HangmanGame.h.
LoginWidget* HangmanGame::login_ [private] |
Definition at line 34 of file HangmanGame.h.
Wt::WStackedWidget* HangmanGame::mainStack_ [private] |
Definition at line 33 of file HangmanGame.h.
HighScoresWidget* HangmanGame::scores_ [private] |
Definition at line 36 of file HangmanGame.h.
Wt::WAnchor* HangmanGame::scoresAnchor_ [private] |
Definition at line 38 of file HangmanGame.h.
Session HangmanGame::session_ [private] |
Definition at line 40 of file HangmanGame.h.
1.7.2