Wt examples  3.2.0
/home/koen/project/wt/public-git/wt/examples/hangman/ImagesWidget.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 "ImagesWidget.h"
00008 
00009 #include <Wt/WImage>
00010 
00011 using namespace Wt;
00012 
00013 const int ImagesWidget::maxGuesses_ = 9;
00014 
00015 ImagesWidget::ImagesWidget(WContainerWidget *parent)
00016 {
00017   for (int i = 0; i <= maxGuesses_; ++i) {
00018     std::string fname = "icons/hangman";
00019     fname += boost::lexical_cast<std::string>(i) + ".jpg";
00020     WImage *theImage = new WImage(fname, this);
00021     hangmanImages_.push_back(theImage);
00022     
00023     // Although not necessary, we can avoid flicker (on konqueror)
00024     // by presetting the image size.
00025     theImage->resize(256, 256);
00026   }
00027 
00028   hurrayImage_ = new WImage("icons/hangmanhurray.jpg", this);
00029 
00030   reset();
00031 
00032   hangmanImages_[0]->hide();
00033   hangmanImages_.back()->show();
00034 }
00035 
00036 void ImagesWidget::reset()
00037 {
00038   badGuesses_ = 0;
00039 
00040   hurrayImage_->hide();
00041   for(unsigned int i = 0; i < hangmanImages_.size(); ++i)
00042     hangmanImages_[i]->hide();
00043   hangmanImages_[0]->show();
00044 }
00045 
00046 void ImagesWidget::badGuess()
00047 {
00048   if (badGuesses_ < (int)hangmanImages_.size() - 1) {
00049     hangmanImages_[badGuesses_]->hide();
00050     hangmanImages_[++badGuesses_]->show();
00051   }
00052 }
00053 
00054 bool ImagesWidget::gameOver()
00055 {
00056   return badGuesses_ == maxGuesses_;
00057 }
00058 
00059 void ImagesWidget::hurray() 
00060 {
00061   hangmanImages_[badGuesses_]->hide();
00062   hurrayImage_->show();
00063 }

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