00001
00002
00003
00004
00005
00006
00007 #include <boost/lexical_cast.hpp>
00008 #include <sstream>
00009
00010 #include <Wt/WBreak>
00011 #include <Wt/WText>
00012 #include <Wt/WTable>
00013 #include <Wt/WTableCell>
00014 #include <Wt/WCssDecorationStyle>
00015
00016 #include "HighScoresWidget.h"
00017 #include "HangmanDb.h"
00018
00019 using namespace std;
00020
00021 HighScoresWidget::HighScoresWidget(const std::wstring &user,
00022 WContainerWidget *parent):
00023 WContainerWidget(parent),
00024 User(user)
00025 {
00026 setContentAlignment(AlignCenter);
00027 setStyleClass("highscores");
00028 }
00029
00030 void HighScoresWidget::update()
00031 {
00032 clear();
00033
00034 WText *title = new WText("Hall of fame", this);
00035 title->decorationStyle().font().setSize(WFont::XLarge);
00036 title->setMargin(10, Top | Bottom);
00037
00038 new WBreak(this);
00039
00040 HangmanDb::Score s = HangmanDb::getUserPosition(User);
00041
00042 std::string yourScore;
00043 if (s.number == 1)
00044 yourScore = "Congratulations! You are currently leading the pack.";
00045 else {
00046 yourScore = "You are currently ranked number "
00047 + boost::lexical_cast<std::string>(s.number)
00048 + ". Almost there !";
00049 }
00050
00051 WText *score = new WText("<p>" + yourScore + "</p>", this);
00052 score->decorationStyle().font().setSize(WFont::Large);
00053
00054 std::vector<HangmanDb::Score> top = HangmanDb::getHighScores(20);
00055
00056 WTable *table = new WTable(this);
00057 new WText("Rank", table->elementAt(0, 0));
00058 new WText("User", table->elementAt(0, 1));
00059 new WText("Games", table->elementAt(0, 2));
00060 new WText("Score", table->elementAt(0, 3));
00061 new WText("Last game", table->elementAt(0, 4));
00062 for(unsigned int i = 0; i < top.size(); ++i) {
00063 new WText(boost::lexical_cast<string>(top[i].number),
00064 table->elementAt(i + 1, 0));
00065 new WText(top[i].user, table->elementAt(i + 1, 1));
00066 new WText(boost::lexical_cast<std::string>(top[i].numgames),
00067 table->elementAt(i+ 1, 2));
00068 new WText(boost::lexical_cast<std::string>(top[i].score),
00069 table->elementAt(i + 1, 3));
00070 new WText(top[i].lastseen, table->elementAt(i + 1, 4));
00071 }
00072
00073 table->resize(WLength(60, WLength::FontEx), WLength());
00074 table->setMargin(20, Top | Bottom);
00075 table->decorationStyle().setBorder(WBorder(WBorder::Solid));
00076
00077
00078
00079
00080 for (int row = 0; row < table->numRows(); ++row) {
00081 for (int col = 0; col < table->numColumns(); ++col) {
00082 WTableCell *cell = table->elementAt(row, col);
00083 cell->setContentAlignment(AlignMiddle | AlignCenter);
00084
00085 if (row == 0)
00086 cell->setStyleClass("highscoresheader");
00087
00088 if (row == s.number)
00089 cell->setStyleClass("highscoresself");
00090 }
00091 }
00092
00093 WText *fineprint
00094 = new WText("<p>For each game won, you gain 20 points, "
00095 "minus one point for each wrong letter guess.<br />"
00096 "For each game lost, you loose 10 points, so you "
00097 "better try hard to guess the word!</p>", this);
00098 fineprint->decorationStyle().font().setSize(WFont::Smaller);
00099 }