Пример #1
0
/**
 * @param computer the computer player to initialise
 **/
enum input_result get_computer_player(struct player * computer)
{
    /* initialise all variables that are part of the struct to sensible
     * values */
    strncpy(computer->name, "Computer", NAMELEN);
	computer->thiscolor = get_rand_color();
	computer->counters = 0;
	computer->type = COMPUTER;

    return SUCCESS;
}
Пример #2
0
int
create_client (int fd)
{
	struct robot *r;

	if (fd == -1)
		return 0;
	if (!(r = (struct robot *) malloc (sizeof(struct robot))))
		return 0;
	memset (r, 0, sizeof (*r));

	/* place each robot in a different quadrant.  */
	r->x = ((quad & 1) ? 0 : 500) + 500 * (random() / (double) RAND_MAX);
	r->y = ((quad & 2) ? 0 : 500) + 500 * (random() / (double) RAND_MAX);
	quad++;

	r->color[0] = get_rand_color();
	r->color[1] = get_rand_color();
	r->color[2] = get_rand_color();

	fds[current_robots].fd = fd;
	all_robots[current_robots++] = r;
	return 1;
}
Пример #3
0
/**
 * @param human the human player to initialise
 **/
enum input_result get_human_player(struct player* human)
{
    /* placeholder return value. You should prompt the user
     * for their name and then initialise all other values in the
     * player struct to sensible values.
     */
	puts("Enter your name:");
    if(fgets(human->name, NAMELEN, stdin) == NULL)	//get user input
		return feof(stdin) ? RTM : FAILURE;

	int len = strlen(human->name);
	if(len == 1)	return RTM;	//enter on a newline
	human->name[len-1] = '\0';

    //read_rest_of_line();
    human->thiscolor = get_rand_color();
	human->counters = 0;
	human->type = HUMAN;

    return SUCCESS;
}