Exemplo n.º 1
0
void GenericTetrix::updateBoard(int x1,int y1,int x2, int y2,
                                int dontUpdateBlanks)
{
    int i,j;
    int tmp;

    if (x1 > x2) {
        tmp = x2;
        x2  = x1;
        x1  = tmp;
    }
    if (y1 > y2) {
        tmp = y2;
        y2  = y1;
        y1  = tmp;
    }
    if (x1 < 0)
        x1 = 0;
    if (x2 >= width)
        x2 = width - 1;
    if (y1 < 0)
        y1 = 0;
    if (y2 >= height)
        y2 = height - 1;
    for(i = y1 ; i <= y2 ; i++)
        for(j = x1 ; j <=  x2 ; j++)
	    if (!dontUpdateBlanks || board(j,height - i - 1) != 0)
                draw(j,height - i - 1,board(j,height - i - 1));
    showPiece();        // Remember to update piece correctly!!!!
}
Exemplo n.º 2
0
void GenericTetris::showBoard()
{
    int i,j;

    showPiece();
    for(i = Height - nClearLines - 1 ; i >= 0 ; i--)
        for(j = 0 ; j < Width ; j++)
		    if (board[j][i] != 0)
		        draw(j,i,board[j][i]);
}
Exemplo n.º 3
0
void GenericTetrix::showBoard()
{
    int i,j;

    showPiece();
    for(i = height - nClearLines - 1 ; i >= 0 ; i--)
        for(j = 0 ; j < width ; j++)
            if (board(j,i) != 0)
                draw(j,i,board(j,i));
}
Exemplo n.º 4
0
void ResultViewPic::doSetCurrentCount( int c )
{
  Q_UNUSED( c );

  if ( c > 0 ) {
    int select = KRandom::number( mPieces.count() );
    Q_ASSERT( select < int( mPieces.count() ) );

    QRect piece = mPieces[ select ];
    QValueList<QRect>::Iterator it = mPieces.at( select );
    mPieces.erase( it );

    showPiece( piece );
  }

  if ( c == totalCount() ) {
    for( unsigned int i = 0; i < mPieces.count(); ++i ) {
      showPiece( mPieces[ i ] );
    }
  }

  setSummary();
}
Exemplo n.º 5
0
void GenericTetris::newPiece()
{
    currentPiece = nextPiece;
    if (showNext)
        eraseNextPiece();
    nextPiece.setRandomType(gameType());
    if (showNext)
        showNextPiece();
    currentLine = Height - 1 + currentPiece.getMinY();
    currentPos  = Width/2 + 1;
    if (!canMoveTo(currentPos,currentLine)) {
	currentLine = -1;
        gameOver();
    } else {
        showPiece();
    }
}
Exemplo n.º 6
0
void GenericTetris::updateBoard(int x1,int y1,int x2, int y2)
{
    int i,j;
    int tmp;

    if (x1 > x2) {
        tmp = x2;
        x2  = x1;
        x1  = tmp;
    }
    if (y1 > y2) {
        tmp = y2;
        y2  = y1;
        y1  = tmp;
    }
    for(i = y1 ; i <= y2 ; i++)
        for(j = x1 ; j <=  x2 ; j++)
           draw(j,Height - i - 1,board[j][Height - i - 1]);
    showPiece();        // Remember to update piece correctly!!!!
}
Exemplo n.º 7
0
void savePiece(int index,int offset,char* h,int len,SaveState* state)
{
	int i;
	pthread_mutex_lock(&g_isSeed_lock);		//做种后不需要再存分片
	i=g_isSeed;
	pthread_mutex_unlock(&g_isSeed_lock);
	if(i==2)return;

	if(state->index<0||offset==0)
	{
		if(offset!=0)return;
		state->index=index;
		state->offset=offset;
	}
	if(len>16384)
	{
		printf("收取数据过大:%d\n",len);
		pthread_mutex_lock(&g_bitmap_lock);
		g_piece_state[state->index].sockfd=-1;
		pthread_mutex_unlock(&g_bitmap_lock);
		state->index=-1;
		return;
	}
	if(index==state->index&&offset==state->offset)
	{
		printf("save piece: index: %d  offset: %d  len: %d\n",index,offset,len);
		if(index*g_torrentmeta->piece_len+offset+len>g_filelen)
		{
			printf("长度越界%d\n",index*g_torrentmeta->piece_len+offset+len);
			return;
		}
		pthread_mutex_lock(&g_f_lock);
		fseek(g_f,index*g_torrentmeta->piece_len+offset,SEEK_SET);
		if((i=fwrite(h,len,1,g_f))!=1)
		{
			printf("写入文件错误%d\n",i);
			pthread_mutex_unlock(&g_f_lock);
			exit(-1);
		}
		g_downloaded+=len;
		g_left-=1;
		pthread_mutex_unlock(&g_f_lock);
		//memcpy(g_filedata+index*g_torrentmeta->piece_len+offset,h,len);

		state->offset+=len;
		if(state->offset >= g_piece_state[index].len)	//该片已经完成
		{
			printf("==完成分片:%d==\n",state->index);
			state->index=-1;
			pthread_mutex_lock(&g_bitmap_lock);
			setbit(&g_bitmap[index/8],8-index%8);
			g_piece_state[index].isDone=1;
			pthread_mutex_unlock(&g_bitmap_lock);
			pthread_mutex_lock(&g_f_lock);
			fflush(g_f);
			pthread_mutex_unlock(&g_f_lock);
			showPiece(index);	//告诉所有人我有了该分片
			//检查是否所有的分片都已经完成
			int i=0;
			int count=0;
			pthread_mutex_lock(&g_bitmap_lock);
			for(i=0;i<g_num_pieces;i++)
			{
				if(!g_piece_state[i].isDone)
				{
					count++;
					printf("0");
				}
				else printf("1");
			}
			printf("\n");
			pthread_mutex_unlock(&g_bitmap_lock);
			if(count > 0 && count <= g_num_pieces/100 && count <= 20)	//1/100进入最后阶段
			{
				if(end_game_mode == 0){
					end_game_mode = 1;
					pthread_mutex_lock(&g_bitmap_lock);
					//最后阶段,向所有peer发送未完成的分片请求
					printf("Enter Last_Game Mode ...\n");
					for(i = 0;i < g_num_pieces;i++){
						printf("[Last_Game] Public request for Piece:%d \n",i);
						if(!g_piece_state[i].isDone){
							publicRequest(i);
						}
					}
					pthread_mutex_unlock(&g_bitmap_lock);
				}else{
					//最后阶段模式下,当收到一个完整的块,向其他peer发送cancel消息
					publicCancel(index);
				}
			}
			if(count==0)		//全部完成
			{
				printf("!!!!接收完毕,开始做种!!!!\n");
				pthread_mutex_lock(&g_isSeed_lock);
				g_isSeed=2;
				pthread_mutex_unlock(&g_isSeed_lock);
			}
		}
	}
	else		//子该分片顺序错误,放弃该分片上的数据
	{
		if(state->index!=index)return;		//其它分片	可以忽略
		pthread_mutex_lock(&g_bitmap_lock);
		g_piece_state[state->index].sockfd=-1;
		pthread_mutex_unlock(&g_bitmap_lock);
		state->index=-1;
		printf("子分片乱序\n");
	}
}
Exemplo n.º 8
0
void Game::showHoldPiece()
{
	if(!firstTimeHolding)
		showPiece(getHoldPiece(), 40, 70.25);
}
Exemplo n.º 9
0
void Game::showNextPiece()
{
	showPiece(getNextPiece(), 460, 70.25);
}