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

#include <WordWidget.h>

Inheritance diagram for WordWidget:
[legend]

Public Member Functions

 WordWidget ()
 
std::string word () const
 
void init (const std::string &word)
 
bool guess (char c)
 
bool won ()
 

Private Attributes

std::vector< Wt::WText * > wordLetters_
 
std::string word_
 
unsigned displayedLetters_ = 0
 

Detailed Description

Definition at line 13 of file WordWidget.h.

Constructor & Destructor Documentation

◆ WordWidget()

WordWidget::WordWidget ( )

Definition at line 11 of file WordWidget.C.

12{
13 addStyleClass("wordcontainer");
14}
Wt::Auth::Dbo::UserDatabase< AuthInfo > UserDatabase
Definition Session.h:22

Member Function Documentation

◆ guess()

bool WordWidget::guess ( char  c)

Definition at line 29 of file WordWidget.C.

30{
31 bool correct = false;
32
33 for (std::size_t i = 0; i < word_.size(); ++i) {
34 if(word_[i] == c) {
36 wordLetters_[i]->setText(std::string(1, c));
37 correct = true;
38 }
39 }
40
41 return correct;
42}
std::vector< Wt::WText * > wordLetters_
Definition WordWidget.h:26
unsigned displayedLetters_
Definition WordWidget.h:29
std::string word_
Definition WordWidget.h:27

◆ init()

void WordWidget::init ( const std::string &  word)

Definition at line 16 of file WordWidget.C.

17{
18 word_ = word;
20
21 clear();
22 wordLetters_.clear();
23 for (const char ch : word_) {
24 auto c = addNew<Wt::WText>("-");
25 wordLetters_.push_back(c);
26 }
27}
std::string word() const
Definition WordWidget.h:18

◆ won()

bool WordWidget::won ( )

Definition at line 44 of file WordWidget.C.

45{
46 return displayedLetters_ == word_.size();
47}

◆ word()

std::string WordWidget::word ( ) const
inline

Definition at line 18 of file WordWidget.h.

18{ return word_; }

Member Data Documentation

◆ displayedLetters_

unsigned WordWidget::displayedLetters_ = 0
private

Definition at line 29 of file WordWidget.h.

◆ word_

std::string WordWidget::word_
private

Definition at line 27 of file WordWidget.h.

◆ wordLetters_

std::vector<Wt::WText*> WordWidget::wordLetters_
private

Definition at line 26 of file WordWidget.h.


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