예제 #1
0
//creates a new player in a given game
struct player *newPlayer( struct game *gm )
{	struct player *pl = &(gm->players[ gm->no_players ] );
	initialisePlayer( pl );	
	gm->no_players++;
	gm->no_lplayers++;
	return pl;
}
void getInitialPosition(Cell board[BOARD_HEIGHT][BOARD_WIDTH],Player * player,char * token){

	Position position;
	Direction direction;
	token = strtok(NULL, DELIMS);

	/*- get 'y' -*/
	if(is_int(token)){
		position.y= atoi(token);
		token = strtok(NULL,DELIMS);

	}
	else
	{
		printf("INVALID INPUT\n");
	}

	/*- get 'x' -*/
	if(is_int(token)){
		position.x = atoi(token);
		token = strtok(NULL,DELIMS);
	}
	else
	{
		printf("INVALID INPUT\n");
	}

	/*- get 'direction' -*/
	if(strcmp(token,"west") == 0)
	{
		direction = WEST;
	}
	else if(strcmp(token,"south") == 0)
	{
		direction = SOUTH;
	}
	else if(strcmp(token,"east") == 0)
	{
		direction = EAST;
	}
	else if(strcmp(token,"north") == 0)
	{
		direction = NORTH;
	}
	else
	{
		printf("Please enter the direction correctl (north,east,south,west).\n");
	}


	/* initialise player position on the board */
	initialisePlayer(player,&position,direction);

	if(placePlayer(board,position) == TRUE)
	{
		position.x = player->position.x;
		position.y = player->position.y;
		player->direction = direction;
		direction = atoi(token);
	}
	else{
		printf("INVALID INPUT\n");
	}
}