Chtěl bych poradit, je to jenom zkušební verze bez ukazatelů. Snaha o "Hru života" na konzoli, bohužel ovšem nemohu najít proč se mi při druhém běhu, vlastně "vše ztratí". Děkuji za brzkou odpověď.
struct Pair
{
char znak;
int x;
int y;
bool alive;
};
////////////////////////////////////////
Pair pole[CoorX][CoorY];
////////////////////////////////////////
void Game::Play(){
int ix,iy,cx,cy,poc,cy2,cx2;
while(true){
system("cls");
for(iy =0;iy < CoorY; iy++){
for(ix =0;ix < CoorX; ix++){
if(!pole[ix][iy].alive){
pole[ix][iy].znak = ' ';
}
if(pole[ix][iy].alive){
pole[ix][iy].znak = 'X';
}
cout << pole[ix][iy].znak;
}
cout << endl;
}
cout << "Dobehl okruh a cele se to posralo" << endl;
Wait(1);
for(iy =0;iy < CoorY; iy++){
for(ix=0;ix < CoorX; ix++){
poc = 0;
if((pole[ix][iy].alive)){
cy = iy-1;
cx = ix-1;
cy2 = cy+2;
cx2 = cx+2;
if(iy == 0 ){cy += 1;cy2-=1; }
if(ix == 0 ){cx += 1;cx2-=1; }
if(ix == CoorX){ cx2-=1;}
if(iy == CoorY){ cy2-=1;}
for(;cy < cy2;cy++){
for(;cx <cx2;cx++){
if(cy != iy && cx != ix){
cout << "(" << cx << "," << cy << ")";
if((pole[cx][cy].znak = 'X')){
poc = poc + 1;
}
}
}
}
if(poc < 2){pole[ix][iy].alive=false; cout << "MALO POPULACE";}
if(poc > 3){pole[ix][iy].alive=false; cout << "PRELIDNENO";}
if(poc == 3 ||poc == 2){}
}
if(pole[ix][iy].alive == false){
cy = iy-1;
cx = ix-1;
cy2 = cy+2;
cx2 = cx+2;
if(iy == 0 ){cy += 1;cy2-=1; }
if(ix == 0 ){cx += 1;cx2-=1; }
if(ix == CoorX){ cx2-=1;}
if(iy == CoorY){ cy2-=1;}
for(; cy < cy2;cy++){
for(;cx <cx2;cx++){
if(cy != iy && cx != ix){
if(pole[cx][cy].alive == true){
poc += 1;
cout << "TROLOLO";
}
}
}
}
if(poc == 3){pole[ix][iy].alive=true;}
}
}
}
Wait(10);
}
}
void Game::Wait(double seconds){
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}