Wt examples  3.2.3
Public Member Functions | Private Member Functions | Private Attributes
HangmanGame Class Reference

#include <HangmanGame.h>

Inheritance diagram for HangmanGame:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 HangmanGame (Wt::WContainerWidget *parent=0)
void handleInternalPath (const std::string &internalPath)

Private Member Functions

void onAuthEvent ()
void showGame ()
void showHighScores ()

Private Attributes

Wt::WStackedWidgetmainStack_
HangmanWidgetgame_
HighScoresWidgetscores_
Wt::WContainerWidgetlinks_
Wt::WAnchorbackToGameAnchor_
Wt::WAnchorscoresAnchor_
Session session_

Detailed Description

Definition at line 24 of file HangmanGame.h.


Constructor & Destructor Documentation

HangmanGame::HangmanGame ( Wt::WContainerWidget parent = 0)

Definition at line 21 of file HangmanGame.C.

                                                :
  WContainerWidget(parent),
  game_(0),
  scores_(0)
{
  session_.login().changed().connect(this, &HangmanGame::onAuthEvent);

  Auth::AuthModel *authModel = new Auth::AuthModel(Session::auth(),
                                                   session_.users(), this);
  authModel->addPasswordAuth(&Session::passwordAuth());
  authModel->addOAuth(Session::oAuth());

  Auth::AuthWidget *authWidget = new Auth::AuthWidget(session_.login());
  authWidget->setModel(authModel);
  authWidget->setRegistrationEnabled(true);

  WText *title = new WText("<h1>A Witty game: Hangman</h1>");
  addWidget(title);

  addWidget(authWidget);

  mainStack_ = new WStackedWidget();
  mainStack_->setStyleClass("gamestack");
  addWidget(mainStack_);

  links_ = new WContainerWidget();
  links_->setStyleClass("links");
  links_->hide();
  addWidget(links_);

  backToGameAnchor_ = new WAnchor("/play", "Gaming Grounds", links_);
  backToGameAnchor_->setLink(WLink(WLink::InternalPath, "/play"));

  scoresAnchor_ = new WAnchor("/highscores", "Highscores", links_);
  scoresAnchor_->setLink(WLink(WLink::InternalPath, "/highscores"));

  WApplication::instance()->internalPathChanged()
    .connect(this, &HangmanGame::handleInternalPath);

  authWidget->processEnvironment();
}

Member Function Documentation

void HangmanGame::handleInternalPath ( const std::string &  internalPath)

Definition at line 76 of file HangmanGame.C.

{
  if (session_.login().loggedIn()) {
    if (internalPath == "/play")
      showGame();
    else if (internalPath == "/highscores")
      showHighScores();
    else
      WApplication::instance()->setInternalPath("/play",  true);
  }
}
void HangmanGame::onAuthEvent ( ) [private]

Definition at line 63 of file HangmanGame.C.

{
  if (session_.login().loggedIn()) {  
    links_->show();
    handleInternalPath(WApplication::instance()->internalPath());
  } else {
    mainStack_->clear();
    game_ = 0;
    scores_ = 0;
    links_->hide();
  }
}
void HangmanGame::showGame ( ) [private]
void HangmanGame::showHighScores ( ) [private]

Member Data Documentation

Definition at line 36 of file HangmanGame.h.

Definition at line 33 of file HangmanGame.h.

Definition at line 35 of file HangmanGame.h.

Definition at line 32 of file HangmanGame.h.

Definition at line 34 of file HangmanGame.h.

Definition at line 37 of file HangmanGame.h.

Definition at line 39 of file HangmanGame.h.


The documentation for this class was generated from the following files:

Generated on Thu Nov 1 2012 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1