Commit 98fa762

mo khan <mo@mokhan.ca>
2014-12-31 04:25:46
extract cell print.
1 parent 9a5516a
src/cell.c
@@ -20,3 +20,7 @@ int cell_alive(Cell *cell) {
 void cell_change_life(Cell *cell, bool alive) {
   cell->alive = alive;
 }
+
+void cell_print(Cell *cell) {
+  printf("%s", cell->alive ? "X" : " ");
+}
src/cell.h
@@ -7,3 +7,4 @@ typedef struct {
 Cell* cell_create(int number_of_cells);
 int cell_alive(Cell *cell);
 void cell_change_life(Cell *cell, bool alive);
+void cell_print(Cell *cell);
src/main.c
@@ -3,7 +3,6 @@
 #include <unistd.h>
 #include <time.h>
 #include "world.h"
-#include "display.h"
 
 void clear_screen(){
   system("clear");
src/world.c
@@ -92,6 +92,7 @@ World* world_random(int width, int height){
 
 World* world_evolve(World *world) {
   World *new_world = world_create(world->width, world->height);
+
   for (int i = 0; i < world_number_of_cells(world); i++) {
     int neighbours = world_neighbours(world, i);
     if (world->cells[i*sizeof(Cell)].alive == true) {
@@ -106,7 +107,7 @@ World* world_evolve(World *world) {
 void world_print(World *world) {
   for (int i = 0; i < world_number_of_cells(world); i++) {
     if (i % world->width == 0) { printf("\n"); }
-    printf("%s", world->cells[i].alive ? "X" : " ");
+    cell_print(&world->cells[i]);
   }
   printf("\n");
 }