Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) TestTicTacToe

 

TestTicTacToe is a tool to test the TicTacToe class.

 

 

 

 

 

Downloads

 

 

 

 

 

 

Older downloads

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./ToolTestTicTacToe/ToolTestTicTacToeDesktop.pro

 

include(../../DesktopApplication.pri)
include(../../Libraries/Boost.pri)
include(../../Libraries/GeneralConsole.pri)
include(../../Libraries/GeneralDesktop.pri)

#Specific, console
include(../../Classes/CppCanvas/CppCanvas.pri)
include(../../Classes/CppDotMatrix/CppDotMatrix.pri)
include(../../Classes/CppGeometry/CppGeometry.pri)
include(../../Classes/CppPlane/CppPlane.pri)
include(../../Classes/CppTextCanvas/CppTextCanvas.pri)
include(../../Classes/CppTicTacToe/CppTicTacToe.pri)
include(../../Classes/CppWidget/CppWidget.pri)

#Specific, desktop
include(../../Classes/CppQtCanvas/CppQtCanvas.pri)
include(../../Classes/CppQtTicTacToeWidget/CppQtTicTacToeWidget.pri)
include(../../Tools/ToolTestTicTacToe/ToolTestTicTacToeDesktop.pri)

SOURCES += qtmain.cpp

 

 

 

 

 

Qt project file: ./ToolTestTicTacToe/ToolTestTicTacToeWebsite.pro

 

QT       += core
QT       -= gui
LIBS += -L/usr/lib -lwt  -lwthttp
#-lwtext
QMAKE_CXXFLAGS += -DNDEBUG
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES +=  \  
    wtmain.cpp \
    ../../Classes/CppTicTacToe/tictactoe.cpp \
    ../../Classes/CppWtTicTacToeWidget/wttictactoewidget.cpp
HEADERS  +=  \
    ../../Classes/CppTicTacToe/tictactoe.h \
    ../../Classes/CppWtTicTacToeWidget/wttictactoewidget.h

 

 

 

 

 

./ToolTestTicTacToe/ToolTestTicTacToeConsole.pri

 

INCLUDEPATH += \
    ../../Tools/ToolTestTicTacToe

SOURCES += \
    ../../Tools/ToolTestTicTacToe/testtictactoemenudialog.cpp

HEADERS += \
    ../../Tools/ToolTestTicTacToe/testtictactoemenudialog.h

RESOURCES += \
    ../../Tools/ToolTestTicTacToe/ToolTestTicTacToe.qrc

OTHER_FILES += \
    ../../Tools/ToolTestTicTacToe/Licence.txt

 

 

 

 

 

./ToolTestTicTacToe/ToolTestTicTacToeDesktop.pri

 

include(../../Tools/ToolTestTicTacToe/ToolTestTicTacToeConsole.pri)

FORMS += \
    ../../Tools/ToolTestTicTacToe/qttesttictactoemenudialog.ui \
    ../../Tools/ToolTestTicTacToe/qttesttictactoemaindialog.ui


SOURCES += \
    ../../Tools/ToolTestTicTacToe/qttesttictactoemenudialog.cpp \
    ../../Tools/ToolTestTicTacToe/qttesttictactoemaindialog.cpp

HEADERS += \
    ../../Tools/ToolTestTicTacToe/qttesttictactoemenudialog.h \
    ../../Tools/ToolTestTicTacToe/qttesttictactoemaindialog.h

 

 

 

 

 

./ToolTestTicTacToe/ToolTestTicTacToeWebsite.pri

 

include(../../Tools/ToolTestTicTacToe/ToolTestTicTacToeConsole.pri)

 

 

 

 

 

./ToolTestTicTacToe/qtmain.cpp

 

//---------------------------------------------------------------------------
/*
TestTicTacToe, tool to test the TicTacToe class
Copyright (C) 2011-2013 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestTicTacToe.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include <QApplication>
#include "qttesttictactoemenudialog.h"
#pragma GCC diagnostic pop

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  ribi::tictactoe::QtTestTicTacToeMenuDialog w;
  w.show();
  return a.exec();
}

 

 

 

 

 

./ToolTestTicTacToe/qttesttictactoemaindialog.h

 

//---------------------------------------------------------------------------
/*
TestTicTacToe, tool to test the TicTacToe class
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestTicTacToe.htm
//---------------------------------------------------------------------------
#ifndef QTTESTTICTACTOEMAINDIALOG_H
#define QTTESTTICTACTOEMAINDIALOG_H

#include <string>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <boost/shared_ptr.hpp>
#include "qthideandshowdialog.h"
#include "tictactoefwd.h"
#pragma GCC diagnostic pop

struct QTableWidget;

namespace Ui {
  class QtTestTicTacToeMainDialog;
}

namespace ribi {
namespace tictactoe {

class QtTestTicTacToeMainDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:
  explicit QtTestTicTacToeMainDialog(
    const boost::shared_ptr<Ai>& player1,
    const boost::shared_ptr<Ai>& player2,
    QWidget *parent = 0
  );
  QtTestTicTacToeMainDialog(const QtTestTicTacToeMainDialog&) = delete;
  QtTestTicTacToeMainDialog& operator=(const QtTestTicTacToeMainDialog&) = delete;
  ~QtTestTicTacToeMainDialog() noexcept;

private:
  Ui::QtTestTicTacToeMainDialog *ui;
  QtCanvas * m_canvas;
  QtTicTacToeWidget * m_tictactoewidget;
  QTimer * m_timer;

  void OnStateChange(QtTicTacToeWidget* w = nullptr);

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif

private slots:
  void OnTick();
  void on_button_restart_clicked();
  void on_button_auto_play_clicked();

};


} //~namespace tictactoe
} //~namespace ribi

#endif // QTTESTTICTACTOEMAINDIALOG_H

 

 

 

 

 

./ToolTestTicTacToe/qttesttictactoemaindialog.cpp

 

//---------------------------------------------------------------------------
/*
TestTicTacToe, tool to test the TicTacToe class
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestTicTacToe.htm
//---------------------------------------------------------------------------
#include "qttesttictactoemaindialog.h"

#include <cassert>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <boost/lexical_cast.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/numeric/conversion/cast.hpp>

#include <QDesktopWidget>
#include <QTimer>

#include "qtaboutdialog.h"
#include "qtcanvas.h"
#include "qttictactoewidget.h"
#include "testtimer.h"
#include "textcanvas.h"
#include "tictactoeais.h"
#include "tictactoewidget.h"
#include "trace.h"
#include "ui_qttesttictactoemaindialog.h"
#pragma GCC diagnostic pop

ribi::tictactoe::QtTestTicTacToeMainDialog::QtTestTicTacToeMainDialog(
  const boost::shared_ptr<Ai>& player1,
  const boost::shared_ptr<Ai>& player2,
  QWidget *parent
) : QtHideAndShowDialog(parent),
    ui(new Ui::QtTestTicTacToeMainDialog),
    m_canvas{},
    m_tictactoewidget(new QtTicTacToeWidget(player1,player2)),
    m_timer(new QTimer(this))
{
  #ifndef NDEBUG
  Test();
  #endif

  ui->setupUi(this);

  {
    assert(ui->verticalLayout);
    ui->verticalLayout->addWidget(m_tictactoewidget);
  }
  {
    assert(ui->verticalLayout);
    assert(!m_canvas);
    m_canvas = new ::ribi::QtCanvas(m_tictactoewidget->GetWidget()->ToTextCanvas());
    ui->verticalLayout->addWidget(m_canvas);
  }

  m_tictactoewidget->m_signal_changed.connect(
    boost::bind(&ribi::tictactoe::QtTestTicTacToeMainDialog::OnStateChange,this,boost::lambda::_1)
  );
  m_tictactoewidget->m_signal_has_winner.connect(
    boost::bind(&ribi::tictactoe::QtTestTicTacToeMainDialog::OnStateChange,this,boost::lambda::_1)
  );

  QObject::connect(this->m_timer,&QTimer::timeout,
    this,&ribi::tictactoe::QtTestTicTacToeMainDialog::OnTick);

  m_timer->setInterval(50);

  //Put the dialog in the screen center
  const QRect screen = QApplication::desktop()->screenGeometry();
  this->move( screen.center() - this->rect().center() );



}

ribi::tictactoe::QtTestTicTacToeMainDialog::~QtTestTicTacToeMainDialog()
{
  delete ui;
  m_timer->stop();
}

void ribi::tictactoe::QtTestTicTacToeMainDialog::OnTick()
{
  if (m_tictactoewidget->GetWidget()->GetWinner() != Winner::no_winner)
  {
    on_button_restart_clicked();
    return;
  }

  const QRect r = m_tictactoewidget->geometry();
  const int x = r.left() + (std::rand() % r.width());
  const int y = r.top()  + (std::rand() % r.height());
  QPoint pos(x,y);
  boost::shared_ptr<QMouseEvent> e(
    new QMouseEvent(
      QEvent::MouseButtonPress,
      pos,
      Qt::LeftButton,
      Qt::LeftButton,
      Qt::NoModifier));
  m_tictactoewidget->mousePressEvent(e.get());
}

void ribi::tictactoe::QtTestTicTacToeMainDialog::OnStateChange(QtTicTacToeWidget*)
{
  //Give feedback
  ui->text->clear();
  //Determine game state
  {
    std::string s = "Winner: ";
    switch (m_tictactoewidget->GetWidget()->GetWinner())
    {
      case Winner::no_winner:
        s+="none";
        break;
      case Winner::player1: s+="player 1 ('X')";
        break;
      case Winner::player2:
        s+="player 2 ('O')";
        break;
      case Winner::draw:
        s+="draw";
        break;
      default: assert(!"Should not get here");
    }
    ui->text->appendPlainText(s.c_str());
  }
  {
    std::string s = "Current active player: ";
    switch (m_tictactoewidget->GetWidget()->GetCurrentPlayer())
    {
      case Player::player1: s+="player 1 ('X')"; break;
      case Player::player2: s+="player 2 ('O')"; break;
      default: assert(!"Should not get here");
    }
    ui->text->appendPlainText(s.c_str());
  }
  ui->text->appendPlainText("Summarized state: "
    + QString::number(m_tictactoewidget->GetWidget()->GetSummarizedState()));

  m_canvas->SetCanvas(m_tictactoewidget->GetWidget()->ToTextCanvas());
}

#ifndef NDEBUG
void ribi::tictactoe::QtTestTicTacToeMainDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
  for (const auto& ai: Ais().GetAll())
  {
    QtTestTicTacToeMainDialog d(ai,nullptr);
    assert(!d.GetVersion().empty());
  }
  for (const auto& ai: Ais().GetAll())
  {
    QtTicTacToeWidget w(nullptr,ai);
    assert(!w.GetVersion().empty());
  }
}
#endif

void ribi::tictactoe::QtTestTicTacToeMainDialog::on_button_restart_clicked()
{
  m_tictactoewidget->Restart();
}

void ribi::tictactoe::QtTestTicTacToeMainDialog::on_button_auto_play_clicked()
{
  if (m_timer->isActive())
  {
    m_timer->stop();
    ui->button_auto_play->setText("&Start auto-play");
  }
  else
  {
    m_timer->start();
    ui->button_auto_play->setText("&Stop auto-play");
  }
}

 

 

 

 

 

./ToolTestTicTacToe/qttesttictactoemenudialog.h

 

#ifndef QTTESTTICTACTOEMENUDIALOG_H
#define QTTESTTICTACTOEMENUDIALOG_H

#include "qthideandshowdialog.h"
#include "tictactoefwd.h"

namespace Ui {
  class QtTestTicTacToeMenuDialog;
}

namespace ribi {
namespace tictactoe {

class QtTestTicTacToeMenuDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:
  explicit QtTestTicTacToeMenuDialog(QWidget *parent = 0);
  QtTestTicTacToeMenuDialog(const QtTestTicTacToeMenuDialog&) = delete;
  QtTestTicTacToeMenuDialog& operator=(const QtTestTicTacToeMenuDialog&) = delete;
  ~QtTestTicTacToeMenuDialog() noexcept;

protected:
  
  void keyPressEvent(QKeyEvent *);

private:
  Ui::QtTestTicTacToeMenuDialog *ui;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif

private slots:
  void on_button_about_clicked();
  void on_button_quit_clicked();
  void on_button_start_clicked();
};

} //~namespace tictactoe
} //~namespace ribi

#endif // QTTESTTICTACTOEMENUDIALOG_H

 

 

 

 

 

./ToolTestTicTacToe/qttesttictactoemenudialog.cpp

 

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include "qttesttictactoemenudialog.h"

#include <QDesktopWidget>
#include <QKeyEvent>

#include "tictactoeais.h"
#include "testtictactoemenudialog.h"
#include "qtaboutdialog.h"
#include "qttesttictactoemaindialog.h"
#include "qthideandshowdialog.h"
#include "trace.h"
#include "testtimer.h"
#include "ui_qttesttictactoemenudialog.h"
#pragma GCC diagnostic pop

ribi::tictactoe::QtTestTicTacToeMenuDialog::QtTestTicTacToeMenuDialog(QWidget *parent) :
    QtHideAndShowDialog(parent),
    ui(new Ui::QtTestTicTacToeMenuDialog)
{
  #ifndef NDEBUG
  Test();
  #endif

  ui->setupUi(this);
}

ribi::tictactoe::QtTestTicTacToeMenuDialog::~QtTestTicTacToeMenuDialog() noexcept
{
  delete ui;
}

void ribi::tictactoe::QtTestTicTacToeMenuDialog::keyPressEvent(QKeyEvent * event)
{
  if (event->key() == Qt::Key_Escape) { close(); return; }
}

void ribi::tictactoe::QtTestTicTacToeMenuDialog::on_button_about_clicked()
{
  About a = TestTicTacToeMenuDialog().GetAbout();
  a.AddLibrary("QtHideAndShowDialog version: " + QtHideAndShowDialog::GetVersion());
  QtAboutDialog d(a);
  d.setWindowIcon(this->windowIcon());
  d.setStyleSheet(this->styleSheet());
  this->ShowChild(&d);
}

void ribi::tictactoe::QtTestTicTacToeMenuDialog::on_button_quit_clicked()
{
  close();
}

void ribi::tictactoe::QtTestTicTacToeMenuDialog::on_button_start_clicked()
{
  QtTestTicTacToeMainDialog d(nullptr,nullptr);
  d.setStyleSheet(this->styleSheet());
  ShowChild(&d);
}

#ifndef NDEBUG
void ribi::tictactoe::QtTestTicTacToeMenuDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  TestTicTacToeMenuDialog();
  for (const auto& ai: Ais().GetAll())
  {
    QtTestTicTacToeMainDialog(nullptr,ai);
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
}
#endif

 

 

 

 

 

./ToolTestTicTacToe/testtictactoemenudialog.h

 

//---------------------------------------------------------------------------
/*
TestTicTacToe, test the TicTacToe classes
Copyright (C) 2008-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl/ToolTestTicTacToe.htm
//---------------------------------------------------------------------------
#ifndef TESTTICTACTOEMENUDIALOG_H
#define TESTTICTACTOEMENUDIALOG_H

#include "menudialog.h"

namespace ribi {

struct TestTicTacToeMenuDialog final : public MenuDialog
{
  TestTicTacToeMenuDialog();
  About GetAbout() const noexcept override;
  Help GetHelp() const noexcept override;
  boost::shared_ptr<const Program> GetProgram() const noexcept override;
  std::string GetVersion() const noexcept override;
  std::vector<std::string> GetVersionHistory() const noexcept override;

  private:
  int ExecuteSpecific(const std::vector<std::string>& argv) noexcept override;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

} //~namespace ribi

#endif // TESTTICTACTOEMENUDIALOG_H

 

 

 

 

 

./ToolTestTicTacToe/testtictactoemenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TestTicTacToe, test the TicTacToe classes
Copyright (C) 2008-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl/ToolTestTicTacToe.htm
//---------------------------------------------------------------------------
#include "testtictactoemenudialog.h"

#include <iostream>

#include "testtimer.h"
#include "trace.h"

#include "richelbilderbeekprogram.h"

ribi::TestTicTacToeMenuDialog::TestTicTacToeMenuDialog()
{
  #ifndef NDEBUG
  Test();
  #endif
}

int ribi::TestTicTacToeMenuDialog::ExecuteSpecific(const std::vector<std::string>& argv) noexcept
{
  const int argc = static_cast<int>(argv.size());
  if (argc != 1)
  {
    std::cout << GetHelp() << '\n';
    return 1;
  }
  return 0;
}

ribi::About ribi::TestTicTacToeMenuDialog::GetAbout() const noexcept
{
  About a(
    "Richel Bilderbeek",
    "TestTicTacToe",
    "tool to test the TicTacToe class",
    "the 15th of Oktober 2013",
    "2011-2015",
    "http://www.richelbilderbeek.nl/ToolTestTicTacToe.htm",
    GetVersion(),
    GetVersionHistory());
  a.AddLibrary("Trace version: " + Trace::GetVersion());
  return a;
}

ribi::Help ribi::TestTicTacToeMenuDialog::GetHelp() const noexcept
{
  return Help(
    this->GetAbout().GetFileTitle(),
    this->GetAbout().GetFileDescription(),
    {

    },
    {

    }
  );
}

boost::shared_ptr<const ribi::Program> ribi::TestTicTacToeMenuDialog::GetProgram() const noexcept
{
  const boost::shared_ptr<const Program> p {
    new ProgramTestTicTacToe
  };
  assert(p);
  return p;
}

std::string ribi::TestTicTacToeMenuDialog::GetVersion() const noexcept
{
  return "1.4";
}

std::vector<std::string> ribi::TestTicTacToeMenuDialog::GetVersionHistory() const noexcept
{
  return {
    "2010-09-17: version 1.0: initial version, use of QTable as board",
    "2010-09-22: version 1.1: use of TicTacToeWidget",
    "2011-01-06: version 1.2: merge with Wt application",
    "2011-01-06: version 1.3: moved TicTacToe and QtTicTacToeWidget to different folders",
    "2013-10-14: version 1.4: conformized to ProjectRichelBilderbeek"
  };
}

#ifndef NDEBUG
void ribi::TestTicTacToeMenuDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
}
#endif

 

 

 

 

 

./ToolTestTicTacToe/wtmain.cpp

 

//---------------------------------------------------------------------------
/*
TestTicTacToe, tool to test the TicTacToe class
Copyright (C) 2010 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestTicTacToe.htm
//---------------------------------------------------------------------------
#include <string>
#include <vector>
//---------------------------------------------------------------------------
#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WEnvironment>
#include <Wt/WEvent>
#include <Wt/WPushButton>
#include <Wt/WMessageBox>
//---------------------------------------------------------------------------
#include "../../Classes/CppWtTicTacToeWidget/wttictactoewidget.h"
//---------------------------------------------------------------------------
struct WtTicTacToeDialog : public Wt::WContainerWidget
{
  WtTicTacToeDialog()
  : m_button_about(new Wt::WPushButton),
    m_button_restart(new Wt::WPushButton),
    m_tictactoe(new WtTicTacToeWidget)
  {
    this->addWidget(m_tictactoe);
    this->addWidget(new Wt::WBreak(this));
    this->addWidget(m_button_restart);
    this->addWidget(m_button_about);
    m_button_about->setText("About");
    m_button_restart->setText("Restart");
    m_tictactoe->m_signal_state_changed.connect(
      boost::bind(
        &WtTicTacToeDialog::OnStateChanged,
        this));
    m_button_about->clicked().connect(
      this,&WtTicTacToeDialog::OnAbout);
    m_button_restart->clicked().connect(
      this,&WtTicTacToeDialog::OnRestart);
  }
  const std::string GetVersion()
  {
    return "1.2";
  }
  static const std::vector<std::string> GetVersionHistory()
  {
    std::vector<std::string> v;
    v.push_back("YYYY-MM-DD: version X.Y: [description]");
    v.push_back("2011-01-06: version 1.2: initial version");
    return v;
  }
  private:
  Wt::WPushButton * const m_button_about;
  Wt::WPushButton * const m_button_restart;
  WtTicTacToeWidget * const m_tictactoe;
  void OnAbout()
  {
    Wt::WMessageBox::show(
      Wt::WString("ToolTestTicTacToe (C) 2010 Richel Bilderbeek"),
      Wt::WString("From http://www.richelbilderbeek.nl/ToolTestTicTacToe.htm"),
      Wt::Ok);
  }
  void OnRestart()
  {
    m_tictactoe->Restart();
  }
  void OnStateChanged()
  {
    switch (m_tictactoe->GetState())
    {
      case TicTacToe::player1:
        m_button_restart->setText("Player 1 has won. Click to restart");
        break;
      case TicTacToe::player2:
        m_button_restart->setText("Player 2 has won. Click to restart");
        break;
      case TicTacToe::draw:
        m_button_restart->setText("Draw. Click to restart");
        break;
      case TicTacToe::no_winner:
        m_button_restart->setText("Restart");
        break;
      default:
        assert(!"Should not get here");
        break;
    }
  }
};
//---------------------------------------------------------------------------
struct WtApplication : public Wt::WApplication
{
  WtApplication(const Wt::WEnvironment& env)
    : Wt::WApplication(env),
    m_dialog(new WtTicTacToeDialog)
  {
    this->setTitle("ToolTestTicTacToe");
    root()->addWidget(m_dialog);
  }
  private:
  WtTicTacToeDialog * const m_dialog;
};
//---------------------------------------------------------------------------
Wt::WApplication *createApplication(
  const Wt::WEnvironment& env)
{
  return new WtApplication(env);
}
//---------------------------------------------------------------------------
int main(int argc, char **argv)
{
  return WRun(argc, argv, &createApplication);
}
//---------------------------------------------------------------------------

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml