Wt examples  3.3.6
Public Member Functions | Private Member Functions | Private Attributes | List of all members
HangmanGame Class Reference

#include <HangmanGame.h>

Inheritance diagram for HangmanGame:
Inheritance graph
[legend]

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::WStackedWidget * mainStack_
 
HangmanWidgetgame_
 
HighScoresWidgetscores_
 
Wt::WContainerWidget * links_
 
Wt::WAnchor * backToGameAnchor_
 
Wt::WAnchor * scoresAnchor_
 
Session session_
 

Detailed Description

Definition at line 24 of file HangmanGame.h.

Constructor & Destructor Documentation

§ HangmanGame()

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

Definition at line 21 of file HangmanGame.C.

21  :
22  WContainerWidget(parent),
23  game_(0),
24  scores_(0)
25 {
26  session_.login().changed().connect(this, &HangmanGame::onAuthEvent);
27 
28  Auth::AuthModel *authModel = new Auth::AuthModel(Session::auth(),
29  session_.users(), this);
30  authModel->addPasswordAuth(&Session::passwordAuth());
31  authModel->addOAuth(Session::oAuth());
32 
33  Auth::AuthWidget *authWidget = new Auth::AuthWidget(session_.login());
34  authWidget->setModel(authModel);
35  authWidget->setRegistrationEnabled(true);
36 
37  WText *title = new WText("<h1>A Witty game: Hangman</h1>");
38  addWidget(title);
39 
40  addWidget(authWidget);
41 
42  mainStack_ = new WStackedWidget();
43  mainStack_->setStyleClass("gamestack");
44  addWidget(mainStack_);
45 
46  links_ = new WContainerWidget();
47  links_->setStyleClass("links");
48  links_->hide();
49  addWidget(links_);
50 
51  backToGameAnchor_ = new WAnchor("/play", "Gaming Grounds", links_);
52  backToGameAnchor_->setLink(WLink(WLink::InternalPath, "/play"));
53 
54  scoresAnchor_ = new WAnchor("/highscores", "Highscores", links_);
55  scoresAnchor_->setLink(WLink(WLink::InternalPath, "/highscores"));
56 
57  WApplication::instance()->internalPathChanged()
58  .connect(this, &HangmanGame::handleInternalPath);
59 
60  authWidget->processEnvironment();
61 }
Wt::WAnchor * backToGameAnchor_
Definition: HangmanGame.h:36
Session session_
Definition: HangmanGame.h:39
Wt::Auth::AbstractUserDatabase & users()
Definition: Session.C:208
Wt::WStackedWidget * mainStack_
Definition: HangmanGame.h:32
static const Wt::Auth::AuthService & auth()
Definition: Session.C:213
HangmanWidget * game_
Definition: HangmanGame.h:33
static const std::vector< const Wt::Auth::OAuthService * > & oAuth()
Definition: Session.C:223
Wt::Auth::Login & login()
Definition: Session.h:32
Wt::WAnchor * scoresAnchor_
Definition: HangmanGame.h:37
Wt::WContainerWidget * links_
Definition: HangmanGame.h:35
HighScoresWidget * scores_
Definition: HangmanGame.h:34
static const Wt::Auth::AbstractPasswordService & passwordAuth()
Definition: Session.C:218
void handleInternalPath(const std::string &internalPath)
Definition: HangmanGame.C:76
void onAuthEvent()
Definition: HangmanGame.C:63

Member Function Documentation

§ handleInternalPath()

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

Definition at line 76 of file HangmanGame.C.

77 {
78  if (session_.login().loggedIn()) {
79  if (internalPath == "/play")
80  showGame();
81  else if (internalPath == "/highscores")
83  else
84  WApplication::instance()->setInternalPath("/play", true);
85  }
86 }
void showHighScores()
Definition: HangmanGame.C:88
Session session_
Definition: HangmanGame.h:39
void showGame()
Definition: HangmanGame.C:100
Wt::Auth::Login & login()
Definition: Session.h:32

§ onAuthEvent()

void HangmanGame::onAuthEvent ( )
private

Definition at line 63 of file HangmanGame.C.

64 {
65  if (session_.login().loggedIn()) {
66  links_->show();
67  handleInternalPath(WApplication::instance()->internalPath());
68  } else {
69  mainStack_->clear();
70  game_ = 0;
71  scores_ = 0;
72  links_->hide();
73  }
74 }
Session session_
Definition: HangmanGame.h:39
Wt::WStackedWidget * mainStack_
Definition: HangmanGame.h:32
HangmanWidget * game_
Definition: HangmanGame.h:33
Wt::Auth::Login & login()
Definition: Session.h:32
Wt::WContainerWidget * links_
Definition: HangmanGame.h:35
HighScoresWidget * scores_
Definition: HangmanGame.h:34
void handleInternalPath(const std::string &internalPath)
Definition: HangmanGame.C:76

§ showGame()

void HangmanGame::showGame ( )
private

Definition at line 100 of file HangmanGame.C.

101 {
102  if (!game_) {
105  }
106 
107  mainStack_->setCurrentWidget(game_);
108 
109  backToGameAnchor_->addStyleClass("selected-link");
110  scoresAnchor_->removeStyleClass("selected-link");
111 }
Wt::WAnchor * backToGameAnchor_
Definition: HangmanGame.h:36
std::string userName() const
Definition: Session.C:148
Session session_
Definition: HangmanGame.h:39
Wt::WStackedWidget * mainStack_
Definition: HangmanGame.h:32
HangmanWidget * game_
Definition: HangmanGame.h:33
Wt::WAnchor * scoresAnchor_
Definition: HangmanGame.h:37
void addToScore(int s)
Definition: Session.C:156
Wt::Signal< int > & scoreUpdated()
Definition: HangmanWidget.h:25

§ showHighScores()

void HangmanGame::showHighScores ( )
private

Definition at line 88 of file HangmanGame.C.

89 {
90  if (!scores_)
92 
93  mainStack_->setCurrentWidget(scores_);
94  scores_->update();
95 
96  backToGameAnchor_->removeStyleClass("selected-link");
97  scoresAnchor_->addStyleClass("selected-link");
98 }
Wt::WAnchor * backToGameAnchor_
Definition: HangmanGame.h:36
Session session_
Definition: HangmanGame.h:39
Wt::WStackedWidget * mainStack_
Definition: HangmanGame.h:32
Wt::WAnchor * scoresAnchor_
Definition: HangmanGame.h:37
HighScoresWidget * scores_
Definition: HangmanGame.h:34

Member Data Documentation

§ backToGameAnchor_

Wt::WAnchor* HangmanGame::backToGameAnchor_
private

Definition at line 36 of file HangmanGame.h.

§ game_

HangmanWidget* HangmanGame::game_
private

Definition at line 33 of file HangmanGame.h.

§ links_

Wt::WContainerWidget* HangmanGame::links_
private

Definition at line 35 of file HangmanGame.h.

§ mainStack_

Wt::WStackedWidget* HangmanGame::mainStack_
private

Definition at line 32 of file HangmanGame.h.

§ scores_

HighScoresWidget* HangmanGame::scores_
private

Definition at line 34 of file HangmanGame.h.

§ scoresAnchor_

Wt::WAnchor* HangmanGame::scoresAnchor_
private

Definition at line 37 of file HangmanGame.h.

§ session_

Session HangmanGame::session_
private

Definition at line 39 of file HangmanGame.h.


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

Generated on Thu Jan 12 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.12