Пример #1
0
void getHumanMove()
{
  int x=3 ;
  int ch;
        while(TRUE)
  {
    gotoxy(x*6 +4, 2);
    ch = (int)getch();
    switch(ch)
    {
      case 75:/*LEFT*/
        if(x>0)
          x--;
        break;
      case 77:/*RIGHT*/
        if(x<(X_BOARD-1))
          x++;
        break;
      case 27:/*ESC*/
        textcolor(7);
        textbackground(0);
        clrscr();
        printf("Thank You For Playing 4 in line by Cheok Yan Cheng!\n");
        exit(0);
        break;
      case 32:/*SPACE*/
        if(humanMove(x))
        {
          drawPiece();
          return;
        }
        else
        {
          gotoxy(1,20);
          textcolor(4);
          cprintf("OOPs! Wrong Move! \n");
        }
    }
        }
}
Пример #2
0
/// @brief Handle events
///
/// @param Event Pointer to event
void SquareApp::OnEvent(SDL_Event* Event) {
	switch (Event->type) {
		case SDL_QUIT:
			std::cout << "Quitting!" << std::endl;
			running = false;
			break;
		case SDL_KEYDOWN:
			KeyPress(Event->key.keysym);
			break;
		case SDL_MOUSEBUTTONDOWN:
			mouseDown = true;
			mdsx = Event->button.x;
			mdsy = Event->button.y;
			break;
		case SDL_MOUSEMOTION:
			if (mouseDown) {
				mouseDragging = true;
				xOffset += (Event->motion.x - mdsx);
				yOffset += (Event->motion.y - mdsy);
				mdsx = Event->motion.x;
				mdsy = Event->motion.y;
			}
			else {
				mouseDragging = false;
			}
			break;
		case SDL_MOUSEBUTTONUP:
			mouseDown = false;
			if (currentPosition.CurrentPlayer() == Player::ONE && mouseDragging == false) {
				Move mv = humanMove(Event);
				std::cout << "Move: " << mv.x << "; " << mv.y << std::endl;
				currentPosition = currentPosition.moveResult(mv);
			}
			mouseDragging = false;
			break;
		default:
			std::cout << Event->type << std::endl;
			break;
	}
}
Пример #3
0
void Human::move(int x, int y)
{
  humanMove(ptr, x, y);
}
Пример #4
0
void GameWall::addGame(ChessGame* game)
{
	Q_ASSERT(game != nullptr);

	QWidget* widget = new QWidget(this);

	ChessClock* clock[2] = { new ChessClock(), new ChessClock() };
	QHBoxLayout* clockLayout = new QHBoxLayout();
	for (int i = 0; i < 2; i++)
	{
		clock[i] = new ChessClock();
		clockLayout->addWidget(clock[i]);

		Chess::Side side = Chess::Side::Type(i);
		clock[i]->setPlayerName(side.toString());
	}
	clockLayout->insertSpacing(1, 20);

	BoardScene* scene = new BoardScene();
	BoardView* view = new BoardView(scene);

	QVBoxLayout* mainLayout = new QVBoxLayout();
	mainLayout->addLayout(clockLayout);
	mainLayout->addWidget(view);
	mainLayout->setContentsMargins(0, 0, 0, 0);

	widget->setLayout(mainLayout);
	layout()->addWidget(widget);

	game->lockThread();
	connect(game, SIGNAL(fenChanged(QString)),
		scene, SLOT(setFenString(QString)));
	connect(game, SIGNAL(moveMade(Chess::GenericMove, QString, QString)),
		scene, SLOT(makeMove(Chess::GenericMove)));
	connect(game, SIGNAL(humanEnabled(bool)),
		view, SLOT(setEnabled(bool)));

	for (int i = 0; i < 2; i++)
	{
		ChessPlayer* player(game->player(Chess::Side::Type(i)));

		if (player->isHuman())
			connect(scene, SIGNAL(humanMove(Chess::GenericMove, Chess::Side)),
				player, SLOT(onHumanMove(Chess::GenericMove, Chess::Side)));

		clock[i]->setPlayerName(player->name());
		connect(player, SIGNAL(nameChanged(QString)),
			clock[i], SLOT(setPlayerName(QString)));

		clock[i]->setInfiniteTime(player->timeControl()->isInfinite());

		if (player->state() == ChessPlayer::Thinking)
			clock[i]->start(player->timeControl()->activeTimeLeft());
		else
			clock[i]->setTime(player->timeControl()->timeLeft());

		connect(player, SIGNAL(startedThinking(int)),
			clock[i], SLOT(start(int)));
		connect(player, SIGNAL(stoppedThinking()),
			clock[i], SLOT(stop()));
	}

	scene->setBoard(game->pgn()->createBoard());
	scene->populate();

	foreach (const Chess::Move& move, game->moves())
		scene->makeMove(move);

	game->unlockThread();

	view->setEnabled(!game->isFinished() &&
			 game->playerToMove()->isHuman());
	m_games[game] = widget;

	cleanupWidgets();
}