summaryrefslogtreecommitdiff
path: root/sem_3/Programm/jeu_de_la_vie/arch/population_vivante.cpp
blob: 93b328ae8bd5514fe00bdd8a73dfc17be8898ab5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <cstdlib>
#include <exception>
#include "population_vivante.h"

population_vivante::population_vivante(size_t x){
  if ( x > N ) {
    std::cout<<" Erreur, taille de population trop grande"<<std::endl;
  }
  nmax = x;
  vivantes=0;
}

void population_vivante::birth(unsigned int x, unsigned int y) {
  if (vivantes < nmax){
  Cellule tmp(true, x,y);
  pop[vivantes]= tmp;
  vivantes++;
}
else{
  std::cout<<"Erreur, toutes les cellules sont deja vivantes!"
}
}
void population_vivante::death(unsigned int x, unsigned int y){
  for (int i =0; i < vivantes; i ++){
    if ((pop[i].getX == x) && (pop[i].getY==y)) {
      pop[i].setVivante(false);
      for ( int j = i; j < vivantes-1; j ++ ){
        pop[j]= pop[j+1];
      }
      i = vivantes;
      vivantes--;
    }
  }
}
const Cellule& copiecell(unsigned int x, unsigned int y){
    for(int i=0; i< vivantes; i ++){
      if ((pop[i].getX == x) && (pop[i].getY==y)) {
        return pop[i];
      }
    }
  }