コード例 #1
0
ファイル: main.cpp プロジェクト: AndreyBelich/SudokuGame
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    GameWidget widget;
    widget.show();
    return a.exec();
}
コード例 #2
0
void MainWindow::play()
{
  Game *g = new Game(ui->serverLineEdit->text(), 995,
         ui->usernameLineEdit->text(),
         ui->passwordLineEdit->text(),
         botPath, this);
  connect(g, SIGNAL(error(Game::Error)),
          this, SLOT(gameError(Game::Error)));
  connect(g, SIGNAL(started(const Player&)),
          this, SLOT(gameStarted(const Player&)));
  connect(g, SIGNAL(waiting(const Player&)),
          this, SLOT(gameWaiting(const Player&)));
  connect(g, SIGNAL(ended(bool)),
          this, SLOT(gameEnded(bool)));

  GameWidget *gw = new GameWidget("Waiting for opponent...", this);
  connect(g, SIGNAL(state(const QString&)),
          &(gw->gameScene()), SLOT(setGameState(const QString&)));
  connect(g, SIGNAL(started(const Player &)),
          gw, SLOT(gameStarted(const Player &)));
  gw->show();

  g->play();
}
コード例 #3
0
void ribi::taba::GameWidget::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  {
    Keys();
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
  const bool verbose{false};

  //Key presses: single key, does the player change direction?
  {
    GameWidget w;
    for (const auto key: Keys().GetAll())
    {
      if (!Keys().IsMovement(key)) continue;
      w.PressKey(key);
      assert(w.GetDirection() == Helper().KeyToDirection(key)
        && "A single key changes the direction of the player");
      w.ReleaseKey(key);
      assert(w.GetDirection() == Helper().KeyToDirection(key)
        && "Releasing the only single key, maintains the direction of the player");
    }
  }
  //Key presses: two keys: does the player keep both if perpendicular
  {
    GameWidget w;
    for (const auto key_a: Keys().GetAll())
    {
      if (!Keys().IsMovement(key_a)) continue;
      for (const auto key_b: Keys().GetAll())
      {
        if (!Keys().IsMovement(key_b)) continue;
        w.PressKey(key_a);
        w.PressKey(key_b);
        if (verbose)
        {
          TRACE(Keys().ToStr(key_a));
          TRACE(Keys().ToStr(key_b));
        }
        if (Keys().IsOpposite(key_a,key_b))
        {
          assert(w.GetDirection() == Helper().KeyToDirection(key_b)
            && "If an opposite key is pressed, change direction to it");
          w.ReleaseKey(key_b);
          assert(w.GetDirection() == Helper().KeyToDirection(key_a)
            && "If that opposite key is released, reverse the player's direction");
          w.ReleaseKey(key_a);
          assert(w.GetDirection() == Helper().KeyToDirection(key_a)
            && "Maintain that player's direction");
        }
        else
        {
          assert(w.GetDirection() == Helper().KeyToDirection(key_b)
            && "If a second perpendicular key is pressed, change direction to it");
          w.ReleaseKey(key_b);
          assert(w.GetDirection() == Helper().KeyToDirection(key_a)
            && "If the primary key is released, make the other key the new primary one");
          w.ReleaseKey(key_a);
          assert(w.GetDirection() == Helper().KeyToDirection(key_a)
            && "Maintain that player's direction");
        }
      }
    }
  }
  TRACE("Finished ribi::taba::GameWidget::Test successfully");
}