Ejemplo n.º 1
0
int user_action(char board1[BOARD_SIZE][BOARD_SIZE], char board2[BOARD_SIZE][BOARD_SIZE], char user) {
	switch (user) {
		case 'a': 
			add_cell(board2) ;
			break ;

		case 'r':
			remove_cell(board2) ;
			break ;

		case 'n':
			apply_rules(board1, board2) ;
			break ;

		case 'q':
			return 0 ;

		case 'p':		
			while (1) {
				apply_rules(board1, board2) ;	
				copy_board(board1, board2) ;
				printf("\033[2J\033[H") ;
				usleep(500000) ;
				print_board(board1) ;			
			}
	}
	return 1 ;
}
Ejemplo n.º 2
0
void	get_cells_lives(t_island *i, t_map *m)
{
	int	lives;
	t_cell *c;

	c = i->first;
	while (c != NULL)
	{
		lives = 0;
		if (m->token[c->x < 1 ? m->rows - 1 : c->x - 1]
				[c->y < 1 ? m->cols - 1 : c->y - 1] == '.')
			lives++;
		if (m->token[c->x + 1 >= m->rows ? m->rows - 1 : c->x + 1]
				[c->y < 1 ? m->cols - 1 : c->y - 1] == '.')
			lives++;
		if (m->token[c->x < 1 ? m->rows - 1 : c->x - 1]
				[c->y + 1 >= m->cols ? m->cols - 1 : c->y + 1])
			lives++;
		if (m->token[c->x + 1 >= m->rows ? m->rows - 1 : c->x + 1]
				[c->y + 1 >= m->cols ? m->cols - 1 : c->y + 1])
			lives++;
		if (lives == 0)
			remove_cell(c, i);
		else
			c->live = lives;
		c = c->next;
	}
}