#include #include #include # //#include //using namespace std ; BITMAP *bufor_ekranu = NULL ; const char * the_dialog[] = { "Zycie", "Marsz", "nico" ,"Inwazja" }; ; void rysuj(int tab[][250][250], int wys, int szer, int bufor, int flaga) ; void zamaluj(int tab[][250][250], int wys, int szer, int x, int y, int bufor, int cos, int flaga) { int xx = (int) (x-50) / (int)(500 / szer); //x i y jest na odwrot :P int yy = (int) (y-50) / (int)(500 / wys); //if(tab[bufor][yy][xx]==2) tab[bufor][yy][xx]=0 ; //else tab[bufor][yy][xx]=cos; tab[bufor][yy-1][xx]=cos; tab[bufor][yy+1][xx]=cos; tab[bufor][yy][xx+1]=cos; tab[bufor][yy][xx-1]=cos; tab[bufor][yy+1][xx+1]=cos; tab[bufor][yy+1][xx-1]=cos; tab[bufor][yy-1][xx+1]=cos; tab[bufor][yy-1][xx-1]=cos; rysuj(tab,wys,szer,bufor,flaga); }; /* 0 - martwa ; 1 - aktywna ; 2 - subaktywna ; */ void zeruj(int tab[][250][250], int wys, int szer) { for(int i=0;i=3 || liczniksub>=3)) tab[nowy][i][j]=2 ; else if(tab[bufor][i][j]==0 &&(licznik>=3 || liczniksub>=3)) tab[nowy][i][j]=1 ; else if(tab[bufor][i][j]==1 &&(licznik==1 || licznik==2 || liczniksub==1 || liczniksub==2)) tab[nowy][i][j]=1 ; else tab[nowy][i][j]=0 ; */ if(tab[bufor][i][j]==1 &&(licznik+liczniksub>=3)) tab[nowy][i][j]=2 ; else if(tab[bufor][i][j]==0 &&(licznik+liczniksub>=3)) tab[nowy][i][j]=1 ; else if(tab[bufor][i][j]==1 &&(licznik+liczniksub==1 || licznik+liczniksub==2)) tab[nowy][i][j]=1 ; else tab[nowy][i][j]=0 ; liczniksub=0 ; } licznik = 0 ; } bufor=nowy ; return ; } void rysuj(int tab[][250][250], int wys, int szer, int bufor, int flaga) { int x=50 ; int y=50 ; int rozmiar_x = 500 / szer ; int rozmiar_y = 500 / wys ; int color ; for(int i=0;i> wys ; cout << "\nPodaj szerokosc siatki (1 - " << max_szer << ") : " << endl ; cin >> szer ; if(wys > max_wys ) wys = max_wys ; if(wys <= 0 ) wys = 1 ; if(szer > max_szer ) szer = max_szer ; if(szer <= 0 ) szer = 1 ;*/ wys = 250 ; szer = 250; int bufor = 0 ; int flaga = 1 ; int colorek ; generuj(tab,wys,szer,2); init(); while (!key[KEY_ESC]) { clear_bitmap(bufor_ekranu); // do_dialog(the_dialog,-1); // if(bufor==1) colorek = makecol(255,0,0) ; colorek = makecol(0,255,0); textprintf_ex(bufor_ekranu, font, 150, 30, colorek,-1,"mouse_x = %-5d", mouse_x); textprintf_ex(bufor_ekranu, font, 270, 30, colorek,-1,"mouse_y = %-5d", mouse_y); rysuj(tab,wys,szer,bufor, flaga); if(key[KEY_ESC]) return 1; if(key[KEY_B]) zycie(tab,wys,szer,bufor,flaga); if(key[KEY_A]) {zeruj(tab,wys,szer);bufor=0;} //menu if(key[KEY_1]) {flaga = 1 ; zeruj(tab,wys,szer);bufor=0;rysuj(tab,wys,szer,bufor,flaga);} if(key[KEY_2]) {flaga = 2 ; zeruj(tab,wys,szer);bufor=0;rysuj(tab,wys,szer,bufor,flaga);} if(key[KEY_3]) {flaga = 4 ; zeruj(tab,wys,szer);bufor=0;rysuj(tab,wys,szer,bufor,flaga);} if(key[KEY_9]) {generuj(tab,wys,szer,flaga);bufor=0;rysuj(tab,wys,szer,bufor,flaga);} if(key[KEY_0]) {zeruj(tab,wys,szer);bufor=0;rysuj(tab,wys,szer,bufor,flaga);} if((mouse_x > 50 && mouse_x < 550) && (mouse_y > 50 && mouse_y < 550) && mouse_b & 1) {zamaluj(tab, wys, szer, mouse_x, mouse_y, bufor, 1, flaga);} if((mouse_x > 50 && mouse_x < 550) && (mouse_y > 50 && mouse_y < 550) && mouse_b & 2) {zamaluj(tab, wys, szer, mouse_x, mouse_y, bufor, 0, flaga);} if(key[KEY_O] && szer > 20) {szer-=10;wys-=10;rysuj(tab,wys,szer,bufor,flaga);} if(key[KEY_P] && szer < 220) {szer+=10;wys+=10;rysuj(tab,wys,szer,bufor,flaga);} if(key[KEY_K] && wys > 20) {wys-=10;} if(key[KEY_L] && wys < 220) {wys+=10;} } deinit(); return 0; } END_OF_MAIN() void init() { int depth, res; allegro_init(); depth = desktop_color_depth(); if (depth == 0) depth = 32; set_color_depth(depth); res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 600, 600, 0, 0); if (res != 0) { allegro_message(allegro_error); exit(-1); } if(!(bufor_ekranu = create_bitmap(600,600))) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("Zamalo pamieci potrzebnej do stworzenia bufora ekranu !\n"); allegro_exit(); } install_timer(); install_keyboard(); install_mouse(); /* add other initializations here */ show_mouse(screen); } void deinit() { clear_keybuf(); /* add other deinitializations here */ }