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 resize(WLength(word_.size() * 1.5, WLength::FontEx), WLength::Auto); 00032 } 00033 00034 bool WordWidget::guess(wchar_t c) 00035 { 00036 bool correct = false; 00037 00038 for(unsigned int i = 0; i < word_.size(); ++i) { 00039 if(word_[i] == c) { 00040 displayedLetters_++; 00041 wordLetters_[i]->setText(std::wstring(1, c)); 00042 correct = true; 00043 } 00044 } 00045 00046 return correct; 00047 } 00048 00049 bool WordWidget::won() 00050 { 00051 return displayedLetters_ == word_.size(); 00052 }
1.7.2