Esempio n. 1
0
//--------------------------------------------------------------------
// Name: CheckRowCompletion()
// Desc: Checks to see if any rows are complete. If they are, the row
//       is cleared, and all rows above it are moved down.
//--------------------------------------------------------------------
bool CTetris::CheckRowCompletion( )
{
	int nCount = 0;
	bool bRetVal = false;
	
	//Clear the row which row was completed var
	for(int nIndex=0; nIndex<BLOCKS_PER_TET; nIndex++)
		m_nWhichRowCompleted[nIndex] = 0;
	nIndex=0;//set index back to 0 for reuse
	//I think i can use memcpy(dest,src,count);
	for( int y=0; y<m_nNumofRows; y++ )
	{
		for( int x=0; x<m_nNumofCols; x++ )
		{   //if it's full keep track
			if( m_pBoard[ ConvertToBoardXY(x,y) ].nState == BLOCK_STATE_FULL )
				nCount++;
		}//End for( int x=0; x<m_nNumofCols; x++ )
		if( nCount == m_nNumofCols )
		{//the row is complete 
			//Take care of updating all row information
			m_nRowsCompleted++;
			m_nTotalRowsCompleted++;
			m_nWhichRowCompleted[nIndex++] = y;
			if( nIndex >= BLOCKS_PER_TET ) //cap the nIndex
				nIndex = BLOCKS_PER_TET;
			//Let user do any animation to the row before it is cleared
			AnimRowCompletion(*this, y);
			//Clear the row from memory
			ClearRow(y);
			bRetVal = true;
		}//End if( nCount == m_nNumofCols )
		nCount=0;
	}//End for( int y=0; y<m_nNumofRows; y++ )
	return bRetVal;
}
Esempio n. 2
0
void
Downscaler::SkipToRow(int32_t aRow)
{
  if (mCurrentInLine < aRow) {
    ClearRow();
    do {
      CommitRow();
    } while (mCurrentInLine < aRow);
  }
}
Esempio n. 3
0
	//清除
	void Clear()
	{
		for (int i = 1; i < 10; i++)
		{
			for (int j = 1; j < 10; j++)
			{
				if (SUDOK[i][j].isok)
				{
					ClearRow(i, SUDOK[i][j].result);
					ClearCol(j, SUDOK[i][j].result);
					ClearAra(i, j, SUDOK[i][j].result);
				}
			}
		}
	}
Esempio n. 4
0
	//检查
	void Check()
	{
		for (int i = 1; i < 10; i++)
		{
			for (int k = 1; k < 10; k++)
			{
				int flag = 0;
				int last[2];
				for (int j = 1; j < 10; j++)
				{
					if (SUDOK[i][j].isok && SUDOK[i][j].result == k)
					{
						flag = 0;
						break;
					}
					if (!SUDOK[i][j].isok && SUDOK[i][j].number[k] == k)
					{
						flag++;
						last[0] = i;
						last[1] = j;
					}
				}
				if (flag == 1) comp(last[0], last[1], k);
			}
		}
		for (int j = 1; j < 10; j++)
		{
			for (int k = 1; k < 10; k++)
			{
				int flag = 0;
				int last[2];
				for (int i = 1; i < 10; i++)
				{
					if (SUDOK[i][j].isok && SUDOK[i][j].result == k)
					{
						flag = 0;
						break;
					}
					if (!SUDOK[i][j].isok && SUDOK[i][j].number[k] == k)
					{
						flag++;
						last[0] = i;
						last[1] = j;
					}
				}
				if (flag == 1) comp(last[0], last[1], k);
			}
		}
		//九个宫格循环i,j
		for (int i = 1; i < 10; i += 3)
		{
			for (int j = 1; j < 10; j += 3)
			{
				//尝试每个数字k
				for (int k = 1; k < 10; k++)
				{
					int flag = 0;
					int last[2];
					int first[2];
					bool b_first = false;

					//宫内循环m,n
					for (int m = i - (i - 1) % 3; m < i - (i - 1) % 3 + 3; m++)
					{
						for (int n = j - (j - 1) % 3; n < j - (j - 1) % 3 + 3; n++)
						{
							if (SUDOK[m][n].isok && SUDOK[m][n].result == k) goto end;
							if (!SUDOK[m][n].isok && SUDOK[m][n].number[k] == k)
							{
								flag++;
								if (b_first)
								{
									first[0] = m;
									first[1] = n;
									b_first = false;
								}
								last[0] = m;
								last[1] = n;
							}
						}
					}

					if (flag == 1) comp(last[0], last[1], k);
					//检查两个数字
					if (flag == 2)
					{
						if (last[0] == first[0])
						{
							SUDOK[first[0]][first[1]].isok = true;
							SUDOK[first[0]][last[1]].isok = true;
							ClearRow(first[0], k);
							SUDOK[first[0]][first[1]].isok = false;
							SUDOK[first[0]][last[1]].isok = false;
						}
						if (last[1] == first[1])
						{
							SUDOK[first[0]][first[1]].isok = true;
							SUDOK[last[0]][first[1]].isok = true;
							ClearCol(first[1], k);
							SUDOK[first[0]][first[1]].isok = false;
							SUDOK[last[0]][first[1]].isok = false;
						}
					}
				}
end:;
			}
		}
	}
Esempio n. 5
0
void insert(struct s_sql_query *query, struct s_sql_result *result)
{
   p_ldata Temp;
   FILE * f;
   char filename_data[S_TABLE+strlen(EXTENSION_DATA)-1]; 
   
   char tempValue;
   int i,endOfString;
   long start, row_size;
   
   p_table tbl_struct, cur_col;
   
   printf("\t Insert into table %s\n",getFirstTblName(query));
   
   if(!databaseexist(getFirstDbName(query)))
   {
      result->error_code=MSG_DATABASE_NOT_EXISTS;
      return;
   }
   if(!tableexist(getFirstDbName(query),getFirstTblName(query)))
   {
      result->error_code=MSG_TABLE_NOT_EXIST;
      return;
   }
   
   
   *filename_data = 0;
   
   strcpy(filename_data, PATH_DATA);
   strcat(filename_data, getFirstDbName(query));
   strcat(filename_data, "\\");
   strcat(filename_data, getFirstTblName(query));
   strcat(filename_data, EXTENSION_DATA);
   
   if((f = fopen(filename_data, "a+")))
   {
        start=ftell(f);
        tbl_struct=GetTableDefinition(getFirstDbName(query), getFirstTblName(query));
        
        Temp = query->datalist;
        cur_col=tbl_struct;
        
        while(cur_col && Temp)
        {
            Temp = Temp->next;
            cur_col=cur_col->next;
        }
        if(cur_col||Temp)
        {
           result->error_code=MSG_COLUMN_COUNT_NOT_MATCH;
           return;
        }
        
        /* Size of the complete row? */
        cur_col=tbl_struct;
        row_size=0;
        while(cur_col)
        {
            row_size += cur_col->column.size;
            cur_col=cur_col->next;
        }
        
        Temp = query->datalist;
        cur_col=tbl_struct;
        
        while(cur_col && Temp)
        {
            /* CAST */
            /* END OF CAST */
                        
            if(Temp->data.type==VIDE)
            {
               if( (cur_col->column.flags & FLAG_NULL) == 0)
               { /* COLUMN NOT NULL => DELETE CURRENT ROW */
                   ClearRow(f,start, row_size);
                   result->error_code=MSG_FIELD_CANT_BE_NULL;
                   fclose(f);
                   return;
               } else {
                  tempValue=0;
                  fwrite(&tempValue,sizeof(char),cur_col->column.size,f); /* fill with 0 */
               }
            }
            else if(Temp->data.type==ENTIER)
            {
               if(colType2basicType(cur_col->column.type) != ENTIER)
               { /* WRONG TYPE => FILL WITH 0 */
                  tempValue=0;
                  fwrite(&tempValue,sizeof(char),cur_col->column.size,f); /* fill with 0 */
               } else {
                    tempValue=Temp->data.data.number;
                  for(i=0;i<cur_col->column.size;i++)
                  { /* write until the column is not complete => truncate int */
                     tempValue=Temp->data.data.number%sizeof(char);
                     fwrite(&tempValue,sizeof(char),1,f); 
                     Temp->data.data.number /= sizeof(char);
                  }
               }
            }
            else if(Temp->data.type==FLOTTANT)
            {
                 if(sizeof(double)!=cur_col->column.size) /* need same size, can't truncate */
                 {
                    tempValue=0;
                    fwrite(&tempValue,sizeof(char),cur_col->column.size,f); /* fill with 0 */
                 } else {
                    fwrite(&Temp->data.data.floatNumber,sizeof(double),1,f);
                 }
            }
            else if(Temp->data.type==CHAINE)
            {
               if(colType2basicType(cur_col->column.type) != ENTIER)
               { /* WRONG TYPE => FILL WITH 0 */
                  tempValue=0;
                  fwrite(&tempValue,sizeof(char),cur_col->column.size,f); /* fill with 0 */
               } else {
                  /* copy string until the column is not complete => truncate string */
                  endOfString=0;
                  for(i=0;i<cur_col->column.size;i++)
                  {
                     if((endOfString=0)&&(Temp->data.data.string[i]==0)) endOfString=i;
                     tempValue=endOfString?Temp->data.data.string[endOfString]:Temp->data.data.string[i];
                     fwrite(&tempValue,sizeof(char),1,f);
                     Temp->data.data.number /= sizeof(char);
                  }
               }
            }
            Temp = Temp->next;
            cur_col=cur_col->next;
        } 
        freeTableDefinition(tbl_struct);
        fclose(f);
        result->error_code = MSG_OK;
   } else
        result->error_code = MSG_CANT_ACCESS_TABLE_DATA;
}