Ejemplo n.º 1
0
int Board::getTimeForGame() const
{
	if(tilesLeft() == 0)
	{
		return time_for_game;
	}
	else
	{
		if(paused)
			return (int)difftime(pause_start, starttime);
		else
			return (int)difftime(time((time_t *)0), starttime);
	}
}
Ejemplo n.º 2
0
void Board::finish() {
  int x1, y1, x2, y2;
  History h[4];
  bool ready=FALSE;

  while(!ready && getHint_I(x1, y1, x2, y2, h)) {
    mark_x = -1;
    mark_y = -1;
    if(tilesLeft() == 2)
      ready = TRUE;
    marked(x1, y1);
    marked(x2, y2);
    kapp->processEvents();
    usleep(250*1000);
  }
}
Ejemplo n.º 3
0
void Board::finish()
{
	Path p;
	bool ready=false;

	while(!ready && getHint_I(p))
	{
		mark_x = -1;
		mark_y = -1;
		if(tilesLeft() == 2)
			ready = true;
		marked(p.front().x, p.front().y);
		marked(p.back().x, p.back().y);
		kapp->processEvents();
		usleep(250*1000);
	}
}
Ejemplo n.º 4
0
bool Board::solvable(bool norestore)
{
	int *oldfield = 0;

	if(!norestore)
	{
		oldfield = new int [x_tiles() * y_tiles()];
		memcpy(oldfield, field, x_tiles() * y_tiles() * sizeof(int));
	}

	Path p;
	while(getHint_I(p))
	{
		kdFatal(getField(p.front().x, p.front().y) != getField(p.back().x, p.back().y))
			<< "Removing unmateched tiles: (" << p.front().x << ", " << p.front().y << ") => "
			<< getField(p.front().x, p.front().y) << " (" << p.back().x << ", " << p.back().y << ") => "
            << getField(p.back().x, p.back().y) << endl;
		setField(p.front().x, p.front().y, EMPTY);
		setField(p.back().x, p.back().y, EMPTY);
		//if(gravityFlag())
		//{
		//	gravity(p.front().x, false);
		//	gravity(p.back().x, false);
		//}
	}

	int left = tilesLeft();

	if(!norestore)
	{
		memcpy(field, oldfield, x_tiles() * y_tiles() * sizeof(int));
		delete [] oldfield;
	}

	return (bool)(left == 0);
}
Ejemplo n.º 5
0
bool Board::solvable(bool norestore) {
  int x1, y1, x2, y2;
  History h[4];
  int *oldfield = 0;
 
  if(!norestore) {
    oldfield = (int *)malloc(x_tiles() * y_tiles() * sizeof(int));
    memcpy(oldfield, field, x_tiles() * y_tiles() * sizeof(int));
  }

  while(getHint_I(x1, y1, x2, y2, h)) {
    setField(x1, y1, EMPTY);
    setField(x2, y2, EMPTY);
  }
  
  int left = tilesLeft();

  if(!norestore) {
    memcpy(field, oldfield, x_tiles() * y_tiles() * sizeof(int));
    free(oldfield);  
  }

  return (bool)(left == 0);
}
Ejemplo n.º 6
0
int Board::getTimeForGame() {
  if(tilesLeft() == 0) 
    return time_for_game;
  else
    return (int)(time((time_t *)0) - starttime);
}