Wt examples  3.2.0
Public Member Functions | Private Attributes | Static Private Attributes
ImagesWidget Class Reference

#include <ImagesWidget.h>

Inheritance diagram for ImagesWidget:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 ImagesWidget (Wt::WContainerWidget *parent=0)
int badGuesses () const
void reset ()
void badGuess ()
void hurray ()
bool gameOver ()

Private Attributes

std::vector< Wt::WImage * > hangmanImages_
Wt::WImagehurrayImage_
int badGuesses_

Static Private Attributes

static const int maxGuesses_ = 9

Detailed Description

Definition at line 19 of file ImagesWidget.h.


Constructor & Destructor Documentation

ImagesWidget::ImagesWidget ( Wt::WContainerWidget parent = 0)

Definition at line 15 of file ImagesWidget.C.

{
  for (int i = 0; i <= maxGuesses_; ++i) {
    std::string fname = "icons/hangman";
    fname += boost::lexical_cast<std::string>(i) + ".jpg";
    WImage *theImage = new WImage(fname, this);
    hangmanImages_.push_back(theImage);
    
    // Although not necessary, we can avoid flicker (on konqueror)
    // by presetting the image size.
    theImage->resize(256, 256);
  }

  hurrayImage_ = new WImage("icons/hangmanhurray.jpg", this);

  reset();

  hangmanImages_[0]->hide();
  hangmanImages_.back()->show();
}

Member Function Documentation

void ImagesWidget::badGuess ( )

Definition at line 46 of file ImagesWidget.C.

{
  if (badGuesses_ < (int)hangmanImages_.size() - 1) {
    hangmanImages_[badGuesses_]->hide();
    hangmanImages_[++badGuesses_]->show();
  }
}
int ImagesWidget::badGuesses ( ) const [inline]

Definition at line 24 of file ImagesWidget.h.

{ return badGuesses_; }
bool ImagesWidget::gameOver ( )

Definition at line 54 of file ImagesWidget.C.

{
  return badGuesses_ == maxGuesses_;
}
void ImagesWidget::hurray ( )

Definition at line 59 of file ImagesWidget.C.

void ImagesWidget::reset ( )

Definition at line 36 of file ImagesWidget.C.

{
  badGuesses_ = 0;

  hurrayImage_->hide();
  for(unsigned int i = 0; i < hangmanImages_.size(); ++i)
    hangmanImages_[i]->hide();
  hangmanImages_[0]->show();
}

Member Data Documentation

Definition at line 35 of file ImagesWidget.h.

std::vector<Wt::WImage *> ImagesWidget::hangmanImages_ [private]

Definition at line 32 of file ImagesWidget.h.

Definition at line 33 of file ImagesWidget.h.

const int ImagesWidget::maxGuesses_ = 9 [static, private]

Definition at line 36 of file ImagesWidget.h.


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

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