mb_veghary
New Member
با سلام خدمت گردانندگان سایت محبوب majidonline
ببخشید من چند سوای درباره بازی شطرنج داشتم که برنامه اش در همین تالار موجود است
توضیحاتی در رابطه با چند خط از برنامه می خواستم
سوالات
1- تابع void coordinate_manager دقیقا چه کاری انجام می دهد اگر می شود با مثالی توضیحی دهید
2-تابع rubber چه کاری انجام می دهد اگر ممکن است این را نیز با مثالی توضیح دهید
3-یک توضیح مختصر نیز درباره تبدیل مختصات در این برنامه بدهید
[void place_pieces (int positions[8][8],int colormap[8][8])
{
int color, i, j;
enum Team {BLACK, WHITE}; //specifying constants
Team turn; //declaring a variable whose 0 value is equal to BLACK and 1 equal to WHITE
turn = BLACK;
for (int y=0; y<8; y++)
for (int x=0; x<8; x++)
{
if ( ((y+1)%2) == 0 )
{
if ( ((x+1)%2) == 0 )
colormap[x][y] = 15;
else
colormap[x][y] = 0;
}
else
{
if ( ((x+1)%2) == 0 )
colormap[x][y] = 0;
else
colormap[x][y] = 15;
}
}//end of 'x' for
for (int Y=0; Y < 8; Y++)
for (int X=0; X < 8; X++)
{
i = X; //will be sent to
j = Y; //coordinate manager
if ( positions[X][Y] >= 1 && positions[X][Y] <= 6 )
turn = WHITE;
color = colormap[X][Y];
coordinate_manager ( &i,&j ); //converting into screen coordinates
switch ( positions[X][Y] )
{
case 1:
case 7: rubber (i,j,color);
draw_pawn (i, j, turn, color);
break;
case 2:
case 8: rubber (i,j,color);
draw_rook (i, j, turn, color);
break;
case 3:
case 9: rubber (i,j,color);
draw_knight (i, j, turn, color);
break;
case 4:
case 10: rubber (i,j,color);
draw_bishop (i, j, turn, color);
break;
case 5:
case 11: rubber (i,j,color);
draw_queen (i, j, turn, color);
break;
case 6:
case 12: rubber (i,j,color);
draw_king (i, j, turn, color);
break;
}//end of draw_piece switch structure
}//end of loop with X
}//end of draw_pieces function
void coordinate_manager (int *x, int *y)
{
if (*x >= 0 && *x <= 7) //to differentiate if the coordinates are to be changed according to board or to the screen
{
*x = (*x * 50) + 21; //row-no = (row-no * horizontal lenght of a box) + distance from left side of screen
*y = (*y * 50) + 21; //converting board coordinates into screen coodinates
}
else
{
*x = (*x - 21) / 50; //converting screen coordinates into board coordinates
*y = (*y - 21) / 50;
}
}//end of coordinate_manager
void rubber(int x,int y, int color)
{
int tempcolor=0;
if ( color == 0 )
tempcolor = 15;
setfillstyle (SOLID_FILL,tempcolor);
bar (x+10,y+10,x+40,y+40); //rubbing the previous contents
}//end of rubber box
ببخشید من چند سوای درباره بازی شطرنج داشتم که برنامه اش در همین تالار موجود است
توضیحاتی در رابطه با چند خط از برنامه می خواستم
سوالات
1- تابع void coordinate_manager دقیقا چه کاری انجام می دهد اگر می شود با مثالی توضیحی دهید
2-تابع rubber چه کاری انجام می دهد اگر ممکن است این را نیز با مثالی توضیح دهید
3-یک توضیح مختصر نیز درباره تبدیل مختصات در این برنامه بدهید
[void place_pieces (int positions[8][8],int colormap[8][8])
{
int color, i, j;
enum Team {BLACK, WHITE}; //specifying constants
Team turn; //declaring a variable whose 0 value is equal to BLACK and 1 equal to WHITE
turn = BLACK;
for (int y=0; y<8; y++)
for (int x=0; x<8; x++)
{
if ( ((y+1)%2) == 0 )
{
if ( ((x+1)%2) == 0 )
colormap[x][y] = 15;
else
colormap[x][y] = 0;
}
else
{
if ( ((x+1)%2) == 0 )
colormap[x][y] = 0;
else
colormap[x][y] = 15;
}
}//end of 'x' for
for (int Y=0; Y < 8; Y++)
for (int X=0; X < 8; X++)
{
i = X; //will be sent to
j = Y; //coordinate manager
if ( positions[X][Y] >= 1 && positions[X][Y] <= 6 )
turn = WHITE;
color = colormap[X][Y];
coordinate_manager ( &i,&j ); //converting into screen coordinates
switch ( positions[X][Y] )
{
case 1:
case 7: rubber (i,j,color);
draw_pawn (i, j, turn, color);
break;
case 2:
case 8: rubber (i,j,color);
draw_rook (i, j, turn, color);
break;
case 3:
case 9: rubber (i,j,color);
draw_knight (i, j, turn, color);
break;
case 4:
case 10: rubber (i,j,color);
draw_bishop (i, j, turn, color);
break;
case 5:
case 11: rubber (i,j,color);
draw_queen (i, j, turn, color);
break;
case 6:
case 12: rubber (i,j,color);
draw_king (i, j, turn, color);
break;
}//end of draw_piece switch structure
}//end of loop with X
}//end of draw_pieces function
void coordinate_manager (int *x, int *y)
{
if (*x >= 0 && *x <= 7) //to differentiate if the coordinates are to be changed according to board or to the screen
{
*x = (*x * 50) + 21; //row-no = (row-no * horizontal lenght of a box) + distance from left side of screen
*y = (*y * 50) + 21; //converting board coordinates into screen coodinates
}
else
{
*x = (*x - 21) / 50; //converting screen coordinates into board coordinates
*y = (*y - 21) / 50;
}
}//end of coordinate_manager
void rubber(int x,int y, int color)
{
int tempcolor=0;
if ( color == 0 )
tempcolor = 15;
setfillstyle (SOLID_FILL,tempcolor);
bar (x+10,y+10,x+40,y+40); //rubbing the previous contents
}//end of rubber box