Wt examples 4.7.1
Public Member Functions | Private Attributes | List of all members
WordWidget Class Reference

#include <WordWidget.h>

Inheritance diagram for WordWidget:
Inheritance graph
[legend]

Public Member Functions

 WordWidget ()
 
std::wstring word () const
 
void init (const std::wstring &word)
 
bool guess (wchar_t c)
 
bool won ()
 

Private Attributes

std::vector< WText * > wordLetters_
 
std::wstring word_
 
unsigned displayedLetters_
 

Detailed Description

Definition at line 15 of file WordWidget.h.

Constructor & Destructor Documentation

◆ WordWidget()

WordWidget::WordWidget ( )

Definition at line 13 of file WordWidget.C.

13 :
14 WContainerWidget()
15{
16 addStyleClass("wordcontainer");
17}

Member Function Documentation

◆ guess()

bool WordWidget::guess ( wchar_t  c)

Definition at line 32 of file WordWidget.C.

33{
34 bool correct = false;
35
36 for(unsigned int i = 0; i < word_.size(); ++i) {
37 if(word_[i] == c) {
39 wordLetters_[i]->setText(std::wstring(1, c));
40 correct = true;
41 }
42 }
43
44 return correct;
45}
unsigned displayedLetters_
Definition: WordWidget.h:31
std::vector< WText * > wordLetters_
Definition: WordWidget.h:28
std::wstring word_
Definition: WordWidget.h:29

◆ init()

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

Definition at line 19 of file WordWidget.C.

20{
21 word_ = word;
23
24 clear();
25 wordLetters_.clear();
26 for(unsigned int i = 0; i < word_.size(); ++i) {
27 WText *c = this->addWidget(std::make_unique<WText>("-"));
28 wordLetters_.push_back(c);
29 }
30}
std::wstring word() const
Definition: WordWidget.h:20

◆ won()

bool WordWidget::won ( )

Definition at line 47 of file WordWidget.C.

48{
49 return displayedLetters_ == word_.size();
50}

◆ word()

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

Definition at line 20 of file WordWidget.h.

20{ return word_; }

Member Data Documentation

◆ displayedLetters_

unsigned WordWidget::displayedLetters_
private

Definition at line 31 of file WordWidget.h.

◆ word_

std::wstring WordWidget::word_
private

Definition at line 29 of file WordWidget.h.

◆ wordLetters_

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

Definition at line 28 of file WordWidget.h.


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

Generated on Fri May 6 2022 for the C++ Web Toolkit (Wt) by doxygen 1.9.3