Wt examples  3.2.0
/home/koen/project/wt/public-git/wt/examples/hangman/WordWidget.C
Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2011 Emweb bvba, Heverlee, Belgium
00003  *
00004  * See the LICENSE file for terms of use.
00005  */
00006 
00007 #include "WordWidget.h"
00008 
00009 #include <Wt/WText>
00010 
00011 using namespace Wt;
00012 
00013 WordWidget::WordWidget(WContainerWidget *parent) :
00014   WContainerWidget(parent)
00015 {
00016   addStyleClass("wordcontainer");
00017 }
00018 
00019 void WordWidget::init(const std::wstring &word)
00020 {
00021   word_ = word;
00022   displayedLetters_ = 0;
00023 
00024   clear();
00025   wordLetters_.clear();
00026   for(unsigned int i = 0; i < word_.size(); ++i) {
00027     WText *c = new WText("-", this);
00028     wordLetters_.push_back(c);
00029   }
00030 }
00031 
00032 bool WordWidget::guess(wchar_t c)
00033 {
00034   bool correct = false;
00035 
00036   for(unsigned int i = 0; i < word_.size(); ++i) {
00037     if(word_[i] == c) {
00038       displayedLetters_++;
00039       wordLetters_[i]->setText(std::wstring(1, c));
00040       correct = true;
00041     }
00042   }
00043 
00044   return correct;
00045 }
00046 
00047 bool WordWidget::won()
00048 {
00049   return displayedLetters_ == word_.size();
00050 }

Generated on Tue Nov 29 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1