Exemplo n.º 1
0
/**
 * Create a bomb.
 */
Cube *
cube_new_bomb()
{
	Cube *cube;

	cube = cube_new(rand() % 4);
	cube->type = CTYPE_BOMB;

	return cube;
}
Exemplo n.º 2
0
/**
 * Create a medic.
 */
Cube *
cube_new_medic()
{
	Cube *cube;

	cube = cube_new(0);
	cube->type = CTYPE_MEDIC;

	return cube;
}
Exemplo n.º 3
0
/**
 * Create a rock, random color.
 */
Cube *
cube_new_rock()
{
	Cube *cube;

	cube = cube_new(rand() % 4);
	cube->type = CTYPE_ROCK;

	return cube;
}
Exemplo n.º 4
0
/**
 * Shortcut to assign the type directly.
 */
Cube *
cube_new_type(byte start_pos, int type)
{
	Cube *cube;

	cube = cube_new(start_pos);
	cube->type = type;

	return cube;
}
Exemplo n.º 5
0
static void add_cube(struct labyrinth *l, char *type)
{
    l->cubes = realloc(l->cubes,
                       (l->cube_cnt + 1) * sizeof(*(l->cubes)));

    if (l->cubes == NULL) {
        perror("realloc");
        exit(EXIT_FAILURE);
    }

    l->cubes[l->cube_cnt] = cube_new(type);
    l->cube_cnt++;
}
Exemplo n.º 6
0
/**
 * Core function for generating cubes. It takes an argument to know the
 * maximum type to allow in the pick.
 */
Cube *
cube_new_random_max(int max)
{
	Cube *cube;
	int r;
	
	/* Start at a random position. */
	r = rand();
	cube = cube_new(r % 4);

	/* Random type. (skipping the first blank) */
	r = rand();
	cube->type = 1 + r % max;

	return cube;
}
Exemplo n.º 7
0
/**
 * Core function for generating cubes. It takes an argument to know the
 * maximum type to allow in the pick.
 */
Cube *
cube_new_random_mask(unsigned int mask)
{
	Cube *cube;
	int r;

	/* Start at a random position. */
	r = rand();
	cube = cube_new(r % 4);

	/* Random type, according to the mask */
	do {
		r = crm[rand() % crm_len];
	} while ((mask & 1 << r) == 0);

	cube->type = r;

	return cube;
}