Exemplo n.º 1
0
int Game::tick()
{
  if(stopped_) {
    return -1;
  }

  removePiece(piece_, px_, py_);
  int ny = py_ - 1;

  if(!doesPieceFit(piece_, px_, ny)) {
    // Must finish off with this piece
    placePiece(piece_, px_, py_);
    if(py_ >= board_height_) {
      // you lose.
      stopped_ = true;
      return -1;
    } else {
      int rm = collapse();
      generateNewPiece();
      return rm;
    }
  } else {
    placePiece(piece_, px_, ny);
    py_ = ny;
    return 0;
  }
}
Exemplo n.º 2
0
bool Game::drop()
{
    removePiece(piece_, px_, py_);
    int ny = py_;

    while(true)
    {
        --ny;
        score_ += 1 + (linesCleared_ / 100);
        if(!doesPieceFit(piece_, px_, ny))
        {
            break;
        }
    }

    ++ny;
    //	placePiece(piece_, px_, ny);
    if(ny == py_)
    {
        return false;
    }
    else
    {
        sy_ = py_;
        py_ = ny;
        counter = 16;
        tick();
        return true;
    }
}
Exemplo n.º 3
0
void Game::dropShadowPiece()
{
	removePiece(shadowPiece_, sx_, sy_);
	int ny = sy_;
	sx_ = px_;
	while(true) 
	{
		--ny;
		if(!doesPieceFit(shadowPiece_, sx_, ny))
		  break;
	}

	++ny;

	for(int r = 0; r < 4; ++r) 
	{
		for(int c = 0; c < 4; ++c) 
		{
			if(shadowPiece_.isOn(r, c))
				get(ny-r, sx_+c) = shadowPiece_.getColourIndex();
		}
	}

	if(ny != sy_)
	  sy_ = ny;
}
Exemplo n.º 4
0
int Game::tick()
{
	if(stopped_) 
	{
		return -1;
	}

	removePiece(piece_, px_, py_);
	int ny = py_ - 1;

	if(!doesPieceFit(piece_, px_, ny)) 
	{
		// Must finish off with this piece
		placePiece(piece_, px_, py_);
		if(py_ >= board_height_) 
		{
	    	// you lose.
	    	stopped_ = true;
	    	return -1;
		} 
		else
		{
	    	int rm = collapse();
			int level = 1 + linesCleared_ / 10;
			switch (rm)
			{
				case 0:
					score_ += 10 * level;
					break;
				case 1:
					score_ += rm * 100 * level;
					break;
				case 2:
				 	score_ += rm * 300 * level;
					break;
				case 3:
				 	score_ += rm * 500 * level;
					break;
				case 4:
				 	score_ += rm * 800 * level;
					break;
			}
			linesCleared_ += rm;
	    	generateNewPiece();
	    	return rm;
		}
	}
	else 
	{
		placePiece(piece_, px_, ny);
		py_ = ny;
		return 0;
	}
}
Exemplo n.º 5
0
bool Game::rotateCCW() 
{
  removePiece(piece_, px_, py_);
  Piece npiece = piece_.rotateCCW();
  if(doesPieceFit(npiece, px_, py_)) {
    placePiece(npiece, px_, py_);
    piece_ = npiece;
    return true;
  } else {
    placePiece(piece_, px_, py_);
    return false;
  }
}
Exemplo n.º 6
0
bool Game::moveRight()
{
  int nx = px_ + 1;

  removePiece(piece_, px_, py_);
  if(doesPieceFit(piece_, nx, py_)) {
    placePiece(piece_, nx, py_);
    px_ = nx;
    return true;
  } else {
    placePiece(piece_, px_, py_);
    return false;
  }
}
Exemplo n.º 7
0
bool Game::moveLeft()
{
  // Most of the piece movement methods work like this:
  //  1. remove the piece from the board.
  // 	2. does the piece fit in its new configuration?
  //	3a. if yes, add it to the board in its new configuration.
  //	3b. if no, put it back where it was.
  // Simple and sort of silly, but satisfactory.

  int nx = px_ - 1;

  removePiece(piece_, px_, py_);
  if(doesPieceFit(piece_, nx, py_)) {
    placePiece(piece_, nx, py_);
    px_ = nx;
    return true;
  } else {
    placePiece(piece_, px_, py_);
    return false;
  }
}
Exemplo n.º 8
0
bool Game::drop()
{
  removePiece(piece_, px_, py_);
  int ny = py_;

  while(true) {
    --ny;
    if(!doesPieceFit(piece_, px_, ny)) {
      break;
    }
  }

  ++ny;
  placePiece(piece_, px_, ny);
	
  if(ny == py_) {
    return false;
  } else {
    py_ = ny;
    return true;
  }
}
Exemplo n.º 9
0
int Game::tick()
{
    if(stopped_)
    {
        return -1;
    }

    int returnVal;
    int level =  linesCleared_/100;
    if (level > 12)
        level = 12;

    removePiece(piece_, px_, py_);
    markBlocksForClearing();
    returnVal = collapse();
    moveClearBar();
    if (counter < COUNTER_SPACE - level)
    {
        counter++;
        placePiece(piece_, px_, py_);
        return returnVal;
    }

    if (py_ == board_height_ + 2 && atTheTop < 16)
    {
        atTheTop++;
        placePiece(piece_, px_, py_);
        return returnVal;
    }
    atTheTop = 0;
    counter = 0;
    int ny = py_ - 1;

    if(!doesPieceFit(piece_, px_, ny))
    {
        // Must finish off with this piece
        placePiece(piece_, px_, py_);
        if(py_ >= board_height_ + 1)
        {
            // you lose.
            stopped_ = true;
            return -1;
        }
        else
        {
            // break piece and keep moving down if need be

            // The right side can drop more
            if(get(ny-2, px_+1) != -1 && get(ny-2, px_+2) == -1)
            {
                dropPiece(0);
                counter = COUNTER_SPACE;
            }
            else if(get(ny-2, px_+1) == -1 && get(ny-2, px_+2) != -1)
            {
                dropPiece(1);
                counter = COUNTER_SPACE;
            }
            generateNewPiece();
            return returnVal;
        }
    }
    else
    {
        placePiece(piece_, px_, ny);
        sy_ = py_;
        py_ = ny;
        return returnVal;
    }
}