📄 function.c
字号:
{ if((x == x0 - 1) && y == y0) { return try_move(x0, y0, x, y, screen, qipan_screen); } } } return -1; }//马的运动规则int horse_rules(int x0, int y0 ,int x, int y, SDL_Surface *screen, SDL_Surface *qipan_screen){ if(x >=0 && x<=9 && y >= 0 && y <= 8) { if((x == (x0 + 2) && y == (y0 + 1) ) || (x == (x0 + 2) && y == (y0 - 1) )) { if(qipan[x0+1][y0] == 0) { return try_move(x0, y0, x, y, screen, qipan_screen); } } else if ((x == (x0 - 2) && y == (y0 + 1) ) || (x == (x0 - 2) && y == (y0 -1) )) { if(qipan[x0-1][y0] == 0) { return try_move(x0, y0, x, y, screen, qipan_screen); } } else if((x == (x0 + 1) && y == (y0 - 2) ) || (x == (x0 - 1) && y == (y0 - 2))) { if(qipan[x0][y0-1] == 0) { return try_move(x0, y0, x, y, screen, qipan_screen); } } else if((x == (x0 + 1) && y == (y0 + 2) ) || (x == (x0 - 1) && y == (y0 + 2) )) { if(qipan[x0][y0+1] == 0) { return try_move(x0, y0, x, y, screen, qipan_screen); } } } return -1;}//象的运动规则int elf_rules(int x0, int y0 ,int x, int y, SDL_Surface *screen, SDL_Surface *qipan_screen){ if(x >=0 && x<= 9 && y >= 0 && y<= 8) { if((x0 <= 4 && x > 4) || (x0 > 4 && x <=4)) return -1; if(x == (x0 - 2) && y ==(y0 - 2)) { if(qipan[x0-1][y0-1] == 0) { return try_move(x0, y0, x, y, screen, qipan_screen); } } else if(x == (x0 + 2) && y == (y0 - 2)) { if(qipan[x0+1][y0-1] == 0) { return try_move(x0, y0, x, y, screen, qipan_screen); } } else if(x == (x0 - 2) && y == (y0 + 2)) { if(qipan[x0-1][y0+1] == 0) { return try_move(x0, y0, x, y, screen, qipan_screen); } } else if( x == (x0 + 2) && y == (y0 + 2)) { if(qipan[x0+1][y0+1] == 0) { return try_move(x0, y0, x, y, screen, qipan_screen); } } } return -1; }//士的运动规则int nurse_rules(int x0, int y0 ,int x, int y, SDL_Surface *screen, SDL_Surface *qipan_screen){ if((y >= 3 && y <= 5) && ((x >= 0 && x <= 2) || (x >= 7 && x <= 9))) { if(x == (x0 + 1) && y == (y0 + 1) || x == (x0 + 1) && y == (y0 - 1) || x == (x0 - 1) && y == (y0 + 1) || x == (x0 - 1) && y == (y0 - 1)) { return try_move(x0, y0, x, y, screen, qipan_screen); } } return -1;}//将帅的运动规则int master_rules(int x0, int y0 ,int x, int y, SDL_Surface *screen, SDL_Surface *qipan_screen){ if((y >= 3 && y <= 5) && ((x >= 0 && x <= 2) || (x >= 7 && x <= 9))) { if(x == (x0 + 1) && y == y0 || x == x0 && y == (y0 - 1) || x == (x0 - 1) && y == y0 || x == x0 && y == (y0 +1)) { if((qipan[x][y] != 0) && !friend(qipan[x0][y0] ,qipan[x][y]) || qipan[x][y] == 0) { move(x0, y0, x, y, screen, qipan_screen); return 0; } } } return -1;}//移动,吃子int move(int x0,int y0, int x, int y, SDL_Surface *screen, SDL_Surface *qipan_screen){ display_qizi(x, y, &qizi[qipan[x0][y0]], screen, qipan_screen); SDL_Rect clip; clip.x = y0*60+10; clip.y = x0*60+10; clip.w = 60; clip.h = 60; display_surface( clip.x, clip.y, qipan_screen, screen, &clip ); qipan[x][y] = qipan[x0][y0]; qipan[x0][y0] = 0;}int try_move(int x0,int y0, int x, int y, SDL_Surface *screen, SDL_Surface *qipan_screen){ if((qipan[x][y] != 0) && !friend(qipan[x0][y0] ,qipan[x][y]) || qipan[x][y] == 0) { if (qipan[x][y] == RC_MAS || qipan[x][y] == BC_MAS) { move(x0, y0, x, y, screen, qipan_screen); return 1; } else { move(x0, y0, x, y, screen, qipan_screen); return 0; } } return -1; }void flash_qizi(int x0, int y0, SDL_Surface *screen){ int i, j; int startx = y0*60+10; int starty = x0*60+10;/* Here p is the address to the pixel we want to set */ int w = qizi[qipan[x0][y0]].image->w; int centerx = startx + w / 2; int centery = starty + w / 2; Uint32 red_color = SDL_MapRGB(screen->format, 255, 0, 0); for(i = 0; i < w; i++) { for(j = 0; j < w; j++) { if(sqrt(pow(startx+i - centerx, 2) + pow(starty+j - centery, 2)) > w / 2 + 3) { putpixel(screen, startx+i, starty+j, red_color); } } }} void change_to(int x0,int y0, int x, int y, SDL_Surface *screen, SDL_Surface *qipan_screen){ SDL_Rect clip; clip.x = y0*60+10; clip.y = x0*60+10; clip.w = 60; clip.h = 60; display_surface( clip.x, clip.y, qipan_screen, screen, &clip ); display_qizi(x0, y0, &qizi[qipan[x0][y0]], screen, qipan_screen); flash_qizi(x, y, screen);}Uint32 getpixel(SDL_Surface *surface, int x, int y){ int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to retrieve */ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: return *p; case 2: return *(Uint16 *)p; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) return p[0] << 16 | p[1] << 8 | p[2]; else return p[0] | p[1] << 8 | p[2] << 16; case 4: return *(Uint32 *)p; default: return 0; //shouldn't happen, but avoids warnings }}void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel){ int bpp = surface->format->BytesPerPixel; // Here p is the address to the pixel we want to set Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: *p = pixel; break; case 2: *(Uint16 *)p = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *(Uint32 *)p = pixel; break; }}void start_again(SDL_Surface *qipan_screen, SDL_Surface *screen){ init_qipan(); display_qipan(qipan_screen , screen);}void display_end(SDL_Surface *screen){ SDL_Surface *end; end = (SDL_Surface *)load_image(END); display_surface(185,275,end,screen,NULL); if( SDL_Flip( screen ) == -1 ) { return ; } SDL_FreeSurface( end );}void display_window(SDL_Surface *screen){ SDL_Surface *window; window = (SDL_Surface *)load_image(WINDOW); display_surface(550,0,window,screen,NULL); if( SDL_Flip( screen ) == -1 ) { return ; } SDL_FreeSurface( window );}void display_start1(SDL_Surface *screen){ SDL_Surface *start; start = (SDL_Surface *)load_image(START1); display_surface(615,400,start,screen,NULL); if( SDL_Flip( screen ) == -1 ) { return ; } SDL_FreeSurface( start );}void display_start2(SDL_Surface *screen){ SDL_Surface *start; start = (SDL_Surface *)load_image(START2); display_surface(615,400,start,screen,NULL); if( SDL_Flip( screen ) == -1 ) { return ; } SDL_FreeSurface( start );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -