Wt examples  4.10.3
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
HangmanWidget Class Reference

#include <HangmanWidget.h>

Inheritance diagram for HangmanWidget:
[legend]

Public Member Functions

 HangmanWidget (const std::string &name)
 
Wt::Signal< int > & scoreUpdated ()
 

Private Member Functions

void registerGuess (char c)
 
void newGame ()
 

Private Attributes

Wt::WText * title_ = nullptr
 
WordWidgetword_ = nullptr
 
ImagesWidgetimages_ = nullptr
 
LettersWidgetletters_ = nullptr
 
Wt::WText * statusText_ = nullptr
 
Wt::WComboBox * language_ = nullptr
 
Wt::WPushButton * newGameButton_ = nullptr
 
Wt::Signal< intscoreUpdated_
 
std::string name_
 
int badGuesses_ = 0
 

Detailed Description

Definition at line 19 of file HangmanWidget.h.

Constructor & Destructor Documentation

◆ HangmanWidget()

HangmanWidget::HangmanWidget ( const std::string &  name)
explicit

Definition at line 27 of file HangmanWidget.C.

28 : name_(name)
29{
30 setContentAlignment(AlignmentFlag::Center);
31
32 title_ = addNew<WText>(tr("hangman.readyToPlay"));
33
37
40
42 language_->addItem(tr("hangman.englishWords").arg(18957));
43 language_->addItem(tr("hangman.dutchWords").arg(1688));
44
46
47 newGameButton_ = addNew<WPushButton>(tr("hangman.newGame"));
48 newGameButton_->clicked().connect(this, &HangmanWidget::newGame);
49
50 letters_->hide();
51}
Wt::Auth::Dbo::UserDatabase< AuthInfo > UserDatabase
Definition Session.h:22
std::string name_
void registerGuess(char c)
LettersWidget * letters_
Wt::WText * statusText_
Wt::WComboBox * language_
ImagesWidget * images_
Wt::WText * title_
WordWidget * word_
Wt::WPushButton * newGameButton_
Wt::Signal< char > & letterPushed()

Member Function Documentation

◆ newGame()

void HangmanWidget::newGame ( )
private

Definition at line 53 of file HangmanWidget.C.

54{
55 WString title(tr("hangman.guessTheWord"));
56 title_->setText(title.arg(name_));
57
58 language_->hide();
59 newGameButton_->hide();
60
61 /*
62 * Choose a new secret word and reset the game
63 */
64 auto dictionary = static_cast<Dictionary>(language_->currentIndex());
66 letters_->reset();
67 badGuesses_ = 0;
69 statusText_->setText("");
70}
std::string randomWord(Dictionary dictionary)
Definition Dictionary.C:14
Dictionary
Definition Dictionary.h:13
void showImage(int index)
void init(const std::string &word)
Definition WordWidget.C:16

◆ registerGuess()

void HangmanWidget::registerGuess ( char  c)
private

Definition at line 72 of file HangmanWidget.C.

73{
74 if (badGuesses_ < MaxGuesses) {
75 bool correct = word_->guess(c);
76
77 if (!correct) {
80 }
81 }
82
83 if (badGuesses_ == MaxGuesses) {
84 WString status = tr("hangman.youHang");
85 statusText_->setText(status.arg(word_->word()));
86
87 letters_->hide();
88 language_->show();
89 newGameButton_->show();
90
91 scoreUpdated_.emit(-10);
92 } else if (word_->won()) {
93 statusText_->setText(tr("hangman.youWin"));
95
96 letters_->hide();
97 language_->show();
98 newGameButton_->show();
99
100 scoreUpdated_.emit(20 - badGuesses_);
101 }
102}
Wt::Signal< int > scoreUpdated_
static const int HURRAY
bool guess(char c)
Definition WordWidget.C:29
std::string word() const
Definition WordWidget.h:18
bool won()
Definition WordWidget.C:44

◆ scoreUpdated()

Wt::Signal< int > & HangmanWidget::scoreUpdated ( )
inline

Definition at line 24 of file HangmanWidget.h.

24{ return scoreUpdated_; }

Member Data Documentation

◆ badGuesses_

int HangmanWidget::badGuesses_ = 0
private

Definition at line 41 of file HangmanWidget.h.

◆ images_

ImagesWidget* HangmanWidget::images_ = nullptr
private

Definition at line 30 of file HangmanWidget.h.

◆ language_

Wt::WComboBox* HangmanWidget::language_ = nullptr
private

Definition at line 34 of file HangmanWidget.h.

◆ letters_

LettersWidget* HangmanWidget::letters_ = nullptr
private

Definition at line 31 of file HangmanWidget.h.

◆ name_

std::string HangmanWidget::name_
private

Definition at line 39 of file HangmanWidget.h.

◆ newGameButton_

Wt::WPushButton* HangmanWidget::newGameButton_ = nullptr
private

Definition at line 35 of file HangmanWidget.h.

◆ scoreUpdated_

Wt::Signal<int> HangmanWidget::scoreUpdated_
private

Definition at line 37 of file HangmanWidget.h.

◆ statusText_

Wt::WText* HangmanWidget::statusText_ = nullptr
private

Definition at line 33 of file HangmanWidget.h.

◆ title_

Wt::WText* HangmanWidget::title_ = nullptr
private

Definition at line 27 of file HangmanWidget.h.

◆ word_

WordWidget* HangmanWidget::word_ = nullptr
private

Definition at line 29 of file HangmanWidget.h.


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