squadron Temat założony przez niniejszego użytkownika |
Szachy - problem z zamianą figur przy biciu » 2012-02-08 15:15:46 Witam ! Mam problem z szachami :/ Wstawiam kod problem jest taki że chce aby 2 figury których zmienne mam wpisane w a1,b1-a2,b2 zamieniły się miejscami w tablicy bierki. Wiem że kod nie jest najwyższych lotów :) Proszę o sugestie i pomoc. #include <iostream> #include <cstdlib> #include <allegro.h> #define WIDTH 800 #define HEIGHT 800
BITMAP * bufor; BITMAP * plansza; BITMAP * pionek; BITMAP * pionekb; BITMAP * wieza; BITMAP * wiezab; BITMAP * skoczek; BITMAP * skoczekb; BITMAP * goniec; BITMAP * goniecb; BITMAP * hetman; BITMAP * hetmanb; BITMAP * krol; BITMAP * krolb;
bool stan = false; int zID( int ID ); int a1 = 0, a2 = 0, b1 = 0, b2 = 0; int mx = 0, my = 0, mb = 0; int ticks = 0, dupa = 0; bool wyjscie = false; int ID = 0, ID1 = 100; int x = 0, y = 0; char test[ 8 ][ 8 ] = { '0' }; char bierki[ 8 ][ 8 ] = { 'w', 's', 'g', 'h', 'k', 'g', 's', 'w', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'W', 'S', 'G', 'H', 'K', 'G', 'S', 'W', };
void timerproc() { ticks++; }
int pole()
{ if( mx >= 32 && mx <= 32 + 95 && my >= 32 && my <= 32 + 92 && mb & 1 ) ID1 = 0; else if( mx >= 125 && mx <= 125 + 95 && my >= 32 && my <= 32 + 92 && mb & 1 ) ID1 = 1; else if( mx >= 217 && mx <= 217 + 95 && my >= 32 && my <= 32 + 92 && mb & 1 ) ID1 = 2; else if( mx >= 310 && mx <= 310 + 95 && my >= 32 && my <= 32 + 92 && mb & 1 ) ID1 = 3; else if( mx >= 403 && mx <= 403 + 95 && my >= 32 && my <= 32 + 92 && mb & 1 ) stan = true, ID1 = 4; else if( mx >= 496 && mx <= 496 + 95 && my >= 32 && my <= 32 + 92 && mb & 1 ) stan = true, ID1 = 5; else if( mx >= 589 && mx <= 589 + 95 && my >= 32 && my <= 32 + 92 && mb & 1 ) stan = true, ID1 = 6; else if( mx >= 682 && mx <= 682 + 95 && my >= 32 && my <= 32 + 92 && mb & 1 ) stan = true, ID1 = 7; else if( mx >= 32 && mx <= 32 + 95 && my >= 125 && my <= 125 + 92 && mb & 1 ) stan = true, ID1 = 10; else if( mx >= 125 && mx <= 125 + 95 && my >= 125 && my <= 125 + 92 && mb & 1 ) stan = true, ID1 = 11; else if( mx >= 217 && mx <= 217 + 95 && my >= 125 && my <= 125 + 92 && mb & 1 ) stan = true, ID1 = 12; else if( mx >= 310 && mx <= 310 + 95 && my >= 125 && my <= 125 + 92 && mb & 1 ) stan = true, ID1 = 13; else if( mx >= 403 && mx <= 403 + 95 && my >= 125 && my <= 125 + 92 && mb & 1 ) stan = true, ID1 = 14; else if( mx >= 496 && mx <= 496 + 95 && my >= 125 && my <= 125 + 92 && mb & 1 ) stan = true, ID1 = 15; else if( mx >= 589 && mx <= 589 + 95 && my >= 125 && my <= 125 + 92 && mb & 1 ) stan = true, ID1 = 16; else if( mx >= 682 && mx <= 682 + 95 && my >= 125 && my <= 125 + 92 && mb & 1 ) stan = true, ID1 = 17; else if( mx >= 32 && mx <= 32 + 95 && my >= 217 && my <= 217 + 92 && mb & 1 ) stan = true, ID1 = 20; else if( mx >= 125 && mx <= 125 + 95 && my >= 217 && my <= 217 + 92 && mb & 1 ) stan = true, ID1 = 21; else if( mx >= 217 && mx <= 217 + 95 && my >= 217 && my <= 217 + 92 && mb & 1 ) stan = true, ID1 = 22; else if( mx >= 310 && mx <= 310 + 95 && my >= 217 && my <= 217 + 92 && mb & 1 ) stan = true, ID1 = 23; else if( mx >= 403 && mx <= 403 + 95 && my >= 217 && my <= 217 + 92 && mb & 1 ) stan = true, ID1 = 24; else if( mx >= 496 && mx <= 496 + 95 && my >= 217 && my <= 217 + 92 && mb & 1 ) stan = true, ID1 = 25; else if( mx >= 589 && mx <= 589 + 95 && my >= 217 && my <= 217 + 92 && mb & 1 ) stan = true, ID1 = 26; else if( mx >= 682 && mx <= 682 + 95 && my >= 217 && my <= 217 + 92 && mb & 1 ) stan = true, ID1 = 27; else if( mx >= 32 && mx <= 32 + 95 && my >= 310 && my <= 310 + 92 && mb & 1 ) stan = true, ID1 = 30; else if( mx >= 125 && mx <= 125 + 95 && my >= 310 && my <= 310 + 92 && mb & 1 ) stan = true, ID1 = 31; else if( mx >= 217 && mx <= 217 + 95 && my >= 310 && my <= 310 + 92 && mb & 1 ) stan = true, ID1 = 32; else if( mx >= 310 && mx <= 310 + 95 && my >= 310 && my <= 310 + 92 && mb & 1 ) stan = true, ID1 = 33; else if( mx >= 403 && mx <= 403 + 95 && my >= 310 && my <= 310 + 92 && mb & 1 ) stan = true, ID1 = 34; else if( mx >= 496 && mx <= 496 + 95 && my >= 310 && my <= 310 + 92 && mb & 1 ) stan = true, ID1 = 35; else if( mx >= 589 && mx <= 589 + 95 && my >= 310 && my <= 310 + 92 && mb & 1 ) stan = true, ID1 = 36; else if( mx >= 682 && mx <= 682 + 95 && my >= 310 && my <= 310 + 92 && mb & 1 ) stan = true, ID1 = 37; else if( mx >= 32 && mx <= 32 + 95 && my >= 403 && my <= 403 + 92 && mb & 1 ) stan = true, ID1 = 40; else if( mx >= 125 && mx <= 125 + 95 && my >= 403 && my <= 403 + 92 && mb & 1 ) stan = true, ID1 = 41; else if( mx >= 217 && mx <= 217 + 95 && my >= 403 && my <= 403 + 92 && mb & 1 ) stan = true, ID1 = 42; else if( mx >= 310 && mx <= 310 + 95 && my >= 403 && my <= 403 + 92 && mb & 1 ) stan = true, ID1 = 43; else if( mx >= 403 && mx <= 403 + 95 && my >= 403 && my <= 403 + 92 && mb & 1 ) stan = true, ID1 = 44; else if( mx >= 496 && mx <= 496 + 95 && my >= 403 && my <= 403 + 92 && mb & 1 ) stan = true, ID1 = 45; else if( mx >= 589 && mx <= 589 + 95 && my >= 403 && my <= 403 + 92 && mb & 1 ) stan = true, ID1 = 46; else if( mx >= 682 && mx <= 682 + 95 && my >= 403 && my <= 403 + 92 && mb & 1 ) stan = true, ID1 = 47; else if( mx >= 32 && mx <= 32 + 95 && my >= 496 && my <= 496 + 92 && mb & 1 ) stan = true, ID1 = 50; else if( mx >= 125 && mx <= 125 + 95 && my >= 496 && my <= 496 + 92 && mb & 1 ) stan = true, ID1 = 51; else if( mx >= 217 && mx <= 217 + 95 && my >= 496 && my <= 496 + 92 && mb & 1 ) stan = true, ID1 = 52; else if( mx >= 310 && mx <= 310 + 95 && my >= 496 && my <= 496 + 92 && mb & 1 ) stan = true, ID1 = 53; else if( mx >= 403 && mx <= 403 + 95 && my >= 496 && my <= 496 + 92 && mb & 1 ) stan = true, ID1 = 54; else if( mx >= 496 && mx <= 496 + 95 && my >= 496 && my <= 496 + 92 && mb & 1 ) stan = true, ID1 = 55; else if( mx >= 589 && mx <= 589 + 95 && my >= 496 && my <= 496 + 92 && mb & 1 ) stan = true, ID1 = 56; else if( mx >= 682 && mx <= 682 + 95 && my >= 496 && my <= 496 + 92 && mb & 1 ) stan = true, ID1 = 57; else if( mx >= 32 && mx <= 32 + 95 && my >= 589 && my <= 589 + 92 && mb & 1 ) stan = true, ID1 = 60; else if( mx >= 125 && mx <= 125 + 95 && my >= 589 && my <= 589 + 92 && mb & 1 ) stan = true, ID1 = 61; else if( mx >= 217 && mx <= 217 + 95 && my >= 589 && my <= 589 + 92 && mb & 1 ) stan = true, ID1 = 62; else if( mx >= 310 && mx <= 310 + 95 && my >= 589 && my <= 589 + 92 && mb & 1 ) stan = true, ID1 = 63; else if( mx >= 403 && mx <= 403 + 95 && my >= 589 && my <= 589 + 92 && mb & 1 ) stan = true, ID1 = 64; else if( mx >= 496 && mx <= 496 + 95 && my >= 589 && my <= 589 + 92 && mb & 1 ) stan = true, ID1 = 65; else if( mx >= 589 && mx <= 589 + 95 && my >= 589 && my <= 589 + 92 && mb & 1 ) stan = true, ID1 = 66; else if( mx >= 682 && mx <= 682 + 95 && my >= 589 && my <= 589 + 92 && mb & 1 ) stan = true, ID1 = 67; else if( mx >= 32 && mx <= 32 + 95 && my >= 682 && my <= 682 + 92 && mb & 1 ) stan = true, ID1 = 70; else if( mx >= 125 && mx <= 125 + 95 && my >= 682 && my <= 682 + 92 && mb & 1 ) stan = true, ID1 = 71; else if( mx >= 217 && mx <= 217 + 95 && my >= 682 && my <= 682 + 92 && mb & 1 ) stan = true, ID1 = 72; else if( mx >= 310 && mx <= 310 + 95 && my >= 682 && my <= 682 + 92 && mb & 1 ) stan = true, ID1 = 73; else if( mx >= 403 && mx <= 403 + 95 && my >= 682 && my <= 682 + 92 && mb & 1 ) stan = true, ID1 = 74; else if( mx >= 496 && mx <= 496 + 95 && my >= 682 && my <= 682 + 92 && mb & 1 ) stan = true, ID1 = 75; else if( mx >= 589 && mx <= 589 + 95 && my >= 682 && my <= 682 + 92 && mb & 1 ) stan = true, ID1 = 76; else if( mx >= 682 && mx <= 682 + 95 && my >= 682 && my <= 682 + 92 && mb & 1 ) stan = true, ID1 = 77; if( mb == 0 ) stan = false; }
void init() { allegro_init(); install_mouse(); install_keyboard(); set_color_depth( 32 ); set_gfx_mode( GFX_AUTODETECT_WINDOWED, WIDTH, HEIGHT, 0, 0 ); install_int( timerproc, 30 ); }
void load() { show_mouse( screen ); unscare_mouse(); bufor = create_bitmap( WIDTH, HEIGHT ); plansza = load_bitmap( "plansza.bmp", NULL ); pionek = load_bmp( "pionek.bmp", NULL ); pionekb = load_bmp( "pionekb.bmp", NULL ); wieza = load_bmp( "wieza.bmp", NULL ); wiezab = load_bmp( "wiezab.bmp", NULL ); skoczek = load_bmp( "skoczek.bmp", NULL ); skoczekb = load_bmp( "skoczekb.bmp", NULL ); goniec = load_bmp( "goniec.bmp", NULL ); goniecb = load_bmp( "goniecb.bmp", NULL ); hetman = load_bmp( "hetman.bmp", NULL ); hetmanb = load_bmp( "hetmanb.bmp", NULL ); krol = load_bmp( "krol.bmp", NULL ); krolb = load_bmp( "krolb.bmp", NULL ); }
void myszka() { if( mx != mouse_x || my != mouse_y || mb != mouse_b ) { mx = mouse_x; my = mouse_y; mb = mouse_b; } };
void draw()
{ clear_to_color( bufor, makecol( 255, 0, 255 ) ); masked_blit( plansza, bufor, 0, 0, 0, 0, WIDTH, HEIGHT ); for( int i = 0; i <= 7; i++ ) { for( int j = 0; j <= 7; j++ ) { ID = i * 10 + j; zID( ID ); if( bierki[ i ][ j ] == 'w' ) masked_blit( wieza, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 's' ) masked_blit( skoczek, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 'g' ) masked_blit( goniec, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 'h' ) masked_blit( hetman, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 'k' ) masked_blit( krol, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 'p' ) masked_blit( pionek, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 'P' ) masked_blit( pionekb, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 'W' ) masked_blit( wiezab, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 'S' ) masked_blit( skoczekb, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 'G' ) masked_blit( goniecb, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 'H' ) masked_blit( hetmanb, bufor, 0, 0, x, y, 92, 92 ); else if( bierki[ i ][ j ] == 'K' ) masked_blit( krolb, bufor, 0, 0, x, y, 92, 92 ); } } blit( bufor, screen, 0, 0, 0, 0, WIDTH, HEIGHT ); }
int zID( int ID ) { if( ID == 0 ) x = 32, y = 32; if( ID == 1 ) x = 125, y = 32; if( ID == 2 ) x = 217, y = 32; if( ID == 3 ) x = 310, y = 32; if( ID == 4 ) x = 403, y = 32; if( ID == 5 ) x = 496, y = 32; if( ID == 6 ) x = 589, y = 32; if( ID == 7 ) x = 682, y = 32; if( ID == 10 ) x = 32, y = 125; if( ID == 11 ) x = 125, y = 125; if( ID == 12 ) x = 217, y = 125; if( ID == 13 ) x = 310, y = 125; if( ID == 14 ) x = 403, y = 125; if( ID == 15 ) x = 496, y = 125; if( ID == 16 ) x = 589, y = 125; if( ID == 17 ) x = 682, y = 125; if( ID == 20 ) x = 32, y = 217; if( ID == 21 ) x = 125, y = 217; if( ID == 22 ) x = 217, y = 217; if( ID == 23 ) x = 310, y = 217; if( ID == 24 ) x = 403, y = 217; if( ID == 25 ) x = 496, y = 217; if( ID == 26 ) x = 589, y = 217; if( ID == 27 ) x = 682, y = 217; if( ID == 30 ) x = 32, y = 310; if( ID == 31 ) x = 125, y = 310; if( ID == 32 ) x = 217, y = 310; if( ID == 33 ) x = 310, y = 310; if( ID == 34 ) x = 403, y = 310; if( ID == 35 ) x = 496, y = 310; if( ID == 36 ) x = 589, y = 310; if( ID == 37 ) x = 682, y = 310; if( ID == 40 ) x = 32, y = 403; if( ID == 41 ) x = 125, y = 403; if( ID == 42 ) x = 217, y = 403; if( ID == 43 ) x = 310, y = 403; if( ID == 44 ) x = 403, y = 403; if( ID == 45 ) x = 496, y = 403; if( ID == 46 ) x = 589, y = 403; if( ID == 47 ) x = 682, y = 403; if( ID == 50 ) x = 32, y = 496; if( ID == 51 ) x = 125, y = 496; if( ID == 52 ) x = 217, y = 496; if( ID == 53 ) x = 310, y = 496; if( ID == 54 ) x = 403, y = 496; if( ID == 55 ) x = 496, y = 496; if( ID == 56 ) x = 589, y = 496; if( ID == 57 ) x = 682, y = 496; if( ID == 60 ) x = 32, y = 589; if( ID == 61 ) x = 125, y = 589; if( ID == 62 ) x = 217, y = 589; if( ID == 63 ) x = 310, y = 589; if( ID == 64 ) x = 403, y = 589; if( ID == 65 ) x = 496, y = 589; if( ID == 66 ) x = 589, y = 589; if( ID == 67 ) x = 682, y = 589; if( ID == 70 ) x = 32, y = 682; if( ID == 71 ) x = 125, y = 682; if( ID == 72 ) x = 217, y = 682; if( ID == 73 ) x = 310, y = 682; if( ID == 74 ) x = 403, y = 682; if( ID == 75 ) x = 496, y = 682; if( ID == 76 ) x = 589, y = 682; if( ID == 77 ) x = 682, y = 682; }
void wylicz() { a1 = ID1 / 10; b1 = ID1 % 10; }
void wylicz2() { a2 = ID1 / 10; b2 = ID1 % 10; }
void bicie1() { bierki[ a2 ][ b2 ] = bierki[ a1 ][ b1 ]; } void logic() { if( key[ KEY_ESC ] ) wyjscie = true; }
void release() { destroy_bitmap( plansza ); destroy_bitmap( bufor ); allegro_exit(); }
int main() { int klik = 0; init(); load(); while( !wyjscie ) { draw(); myszka(); if( klik == 0 ) { pole(); if( ID1 != 100 ) { wylicz(); ID1 = 100; klik++; } } else if( klik > 0 ) { pole(); if( ID1 != 100 ) { wylicz2(); klik = 0; ID1 = 100; } } while( ticks > 0 ) { logic(); ticks--; } } release(); return 0; } END_OF_MAIN();
|