Beispiel #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;
  }
}
Beispiel #2
0
void Game::reset()
{
	stopped_ = false;
	std::fill(board_, board_ + (board_width_*(board_height_+4)), -1);
	linesCleared_ = 0;
	score_ = 0;
	generateNewPiece();
}
Beispiel #3
0
void Game::reset()
{
  stopped_ = false;
  std::fill(board_, board_ + (board_width_*(board_height_+4)), -1);
  generateNewPiece();

  rr = 0;
}
Beispiel #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;
	}
}
Beispiel #5
0
Game::Game(int width, int height)
  : board_width_(width)
	, board_height_(height)
	, stopped_(false)
	, linesCleared_(0)
	, score_(0)
{
  int sz = board_width_ * (board_height_+4);

  board_ = new int[ sz ];
  std::fill(board_, board_ + sz, -1);
  generateNewPiece();
}
Beispiel #6
0
Game::Game(int width, int height)
    : board_width_(width)
    , board_height_(height)
    , stopped_(false)
    , linesCleared_(0)
    , score_(0)
    , numBlocksCleared(0)
    , counter(0)
{
    int sz = board_width_ * (board_height_+4);
    board_ = new int[ sz ];
    std::fill(board_, board_ + sz, -1);
    nextPiece = PIECES[ rand() % 6 ];
    generateNewPiece();
}
Beispiel #7
0
Game::Game(int width, int height)
  : board_width_(width)
  , board_height_(height)
  , stopped_(false)
{
  int sz = board_width_ * (board_height_+4);

  board_ = new int[ sz ];
  std::fill(board_, board_ + sz, -1);
  generateNewPiece();

  rr = 0;
  for(int i=0; i<4; i++){
    rem[i] = -1;
  }
}
Beispiel #8
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;
    }
}