00001
00002
00003
00004
00005
00006
00007 #include <WText>
00008 #include <WTable>
00009 #include <WTableCell>
00010 #include <WStackedWidget>
00011 #include <WCssDecorationStyle>
00012
00013 #include "HangmanGame.h"
00014 #include "LoginWidget.h"
00015 #include "HangmanWidget.h"
00016 #include "HighScoresWidget.h"
00017
00018 HangmanGame::HangmanGame(WContainerWidget *parent):
00019 WTable(parent)
00020 {
00021 resize(WLength(100, WLength::Percentage), WLength());
00022
00023 WText *title = new WText(L"A Witty game: Hangman", elementAt(0,0));
00024 title->decorationStyle().font().setSize(WFont::XXLarge);
00025
00026
00027 elementAt(0, 0)->setContentAlignment(AlignTop | AlignCenter);
00028
00029
00030
00031 MainStack = new WStackedWidget(elementAt(1, 0));
00032 MainStack->setPadding(20);
00033
00034 MainStack->addWidget(Login = new LoginWidget());
00035 Login->loginSuccessful.connect(SLOT(this, HangmanGame::play));
00036
00037
00038
00039
00040 BackToGameText = new WText(L" Gaming Grounds ", elementAt(2, 0));
00041 BackToGameText->decorationStyle().setCursor(WCssDecorationStyle::Pointer);
00042 BackToGameText->clicked.connect(SLOT(this, HangmanGame::showGame));
00043
00044 ScoresText = new WText(L" Highscores ", elementAt(2, 0));
00045 ScoresText->decorationStyle().setCursor(WCssDecorationStyle::Pointer);
00046 ScoresText->clicked.connect(SLOT(this, HangmanGame::showHighScores));
00047
00048 elementAt(2, 0)->setContentAlignment(AlignTop | AlignCenter);
00049
00050 doLogin();
00051 }
00052
00053 void HangmanGame::doLogin()
00054 {
00055 MainStack->setCurrentWidget(Login);
00056 BackToGameText->hide();
00057 ScoresText->hide();
00058 }
00059
00060 void HangmanGame::play(std::wstring user, Dictionary dict)
00061 {
00062
00063 Game = new HangmanWidget(user, dict, MainStack);
00064
00065 MainStack->addWidget(Scores = new HighScoresWidget(user));
00066
00067 BackToGameText->show();
00068 ScoresText->show();
00069
00070 showGame();
00071 }
00072
00073 void HangmanGame::showHighScores()
00074 {
00075 MainStack->setCurrentWidget(Scores);
00076 Scores->update();
00077 BackToGameText->decorationStyle().font().setWeight(WFont::NormalWeight);
00078 ScoresText->decorationStyle().font().setWeight(WFont::Bold);
00079 }
00080
00081 void HangmanGame::showGame()
00082 {
00083 MainStack->setCurrentWidget(Game);
00084 BackToGameText->decorationStyle().font().setWeight(WFont::Bold);
00085 ScoresText->decorationStyle().font().setWeight(WFont::NormalWeight);
00086 }