Пример #1
0
int main (int argc, char *argv[])
{
  int ghost[3],pacman[3],target[2], number_ghost=0;
  char maze[L][C];
  char ch,path[20] = "maze.txt";
  int i=0,j=0;
  while (number_ghost != 9)
  {
  	//clear_screen();
	load_maze(maze,path);
  	//print_maze(maze);
  	printf ( "\t>>> GHOSTS <<<\n" );
  	printf ( "1.BLINK  2.PINK  3.INKY  4.CLYDE  9.SAIR   \n" );
  	do
  	{  	  
  	  printf ( "Qual o numero do Ghost? = " );
          scanf ("%d", &number_ghost);
  	}while(number_ghost > 4 || number_ghost < 1 || number_ghost == 9  );  
  
  //Lendo cordenadas para o ghost 
  	if (number_ghost != 9)
  	{
		
  		print_maze(maze);
  		read_player(maze,ghost,'3'); 
  		read_player(maze,pacman,'5');
	        switch (number_ghost)
		{
			case 1:
				//void blink(maze,ghost,pacman,target);
				position(maze,pacman,'8');
				target[0] = pacman[0];
				target[1] = pacman[1];
				break;
			case 2:
			//	void pink(maze,ghost,pacman,target);
			//	position(maze,target,'T');
				break;
			case 3:
				ink(red,pacman,target);
				position(maze,target,'8');
				break;
			case 4:
			//	void clyde(maze,ghost,pacman,target);
			//	position(maze,target,'8');
		        	break;

		}	
 	 	
		walking(maze,ghost,target);//mudar os parametros
  		print_maze (maze);
  	}
  }
  return 0;
}
Пример #2
0
/* Lê o ficheiro de configuração dos jogadores
 * Numero de baralhos e jogadores
 */
Config *read_config(char *filename)
{
	char buffer[MAX_LINE_LEN];

	Config *config = NULL;
	config = (Config *) ecalloc((size_t) 1, sizeof(Config));

	FILE *config_file = efopen(filename, "r");

    // Parametros gerais de configuração:
    // Número de jogadores e numero de baralhos
	fgets(buffer, MAX_LINE_LEN, config_file);
	sscanf(buffer, "%d-%d", &(config->num_decks), &(config->num_players));

	if (config->num_decks > 8 || config->num_decks < 4){
		fprintf(stderr, "Erro: número de baralhos invalido.\n");
		exit(EXIT_FAILURE);
	}

	if (config->num_players > 4 || config->num_players < 1) {
		fprintf(stderr, "Erro: número de jogadores invalido.\n");
		exit(EXIT_FAILURE);
	}
    // Leitura dos parâmetros de configuracão de cada jogador
	for (int i=0; fgets(buffer, MAX_LINE_LEN, config_file) != NULL && i < config->num_players; i++)
		config = read_player(buffer, config, i);

	fclose(config_file);

	return config;
}
Пример #3
0
static int get_rank(struct result *result)
{
	if (!result->is_loaded) {
		read_player(&result->player, result->name);
		result->is_loaded = 1;
	}

	return result->player.rank;
}
Пример #4
0
int main(int argc, char **argv)
{
	FILE *file;
	char name[MAX_NAME_LENGTH], clan[MAX_NAME_LENGTH];
	struct player_array array = PLAYER_ARRAY_ZERO;
	unsigned i;

	load_config();
	if (argc != 2) {
		fprintf(stderr, "usage: %s <clan_name>\n", argv[0]);
		return EXIT_FAILURE;
	}

	/* Load players */

	sprintf(path, "%s/clans/%s", config.root, argv[1]);
	if (!(file = fopen(path, "r")))
		return perror(path), EXIT_FAILURE;

	while (fscanf(file, " %s", name) == 1) {
		struct player player;

		if (!read_player(&player, name))
			strcpy(player.clan, argv[1]);
		add_player(&array, &player);
	}

	fclose(file);

	/* Sort players */
	qsort(array.players, array.length, sizeof(*array.players), cmp_player);

	/* Eventually, print them */
	hex_to_string(argv[1], clan);
	print_header(&CTF_TAB, clan, NULL);
	printf("<h2>%s</h2>\n", clan);
	printf("<p>%u member(s)</p>\n", array.length);
	printf("<table><thead><tr><th></th><th>Name</th><th>Clan</th><th>Score</th></tr></thead>\n<tbody>\n");

	for (i = 0; i < array.length; i++)
		html_print_player(&array.players[i], 0);

	printf("</tbody></table>\n");
	print_footer();

	return EXIT_SUCCESS;
}
Пример #5
0
int main(int argc, char **argv)
{
	struct delta delta;
	struct player players[MAX_PLAYERS];
	unsigned i;

	load_config();
	if (argc != 1) {
		fprintf(stderr, "usage: %s\n", argv[0]);
		return EXIT_FAILURE;
	}

	while (scan_delta(&delta)) {
		unsigned length = 0;

		/* Load player (ignore fail) */
		for (i = 0; i < delta.length; i++) {
			if (!read_player(&players[length], delta.players[i].name))
				continue;

			merge_delta(&players[length], &delta.players[i]);
			length++;
		}

		/* Compute their new elos */
		if (make_sens_to_rank(delta.elapsed, players, length))
			update_elos(players, length);

		/* Write the result only if something changed */
		for (i = 0; i < length; i++) {
			if (players[i].is_modified) {
				if (!write_player(&players[i]))
					continue;

				if (players[i].is_modified & IS_MODIFIED_CLAN) {
					printf("%s %s %s\n",
					       players[i].name,
					       players[i].delta->clan,
					       players[i].clan);
				}
			}
		}
	}

	return EXIT_SUCCESS;
}
Пример #6
0
int main(void) {
    World *w = new_world("Adventure In C");
    struct room *current = cached_read_room(w, "start");

    struct player me;
    initPlayer(&me, w);
    read_player(&me);
    push_alias(&me, "l", "look");
    push_alias(&me, "u", "up");
    push_alias(&me, "d", "down");
    push_alias(&me, "lo", "look");  // Just an extra alias
    push_alias(&me, "h", "help");
    push_alias(&me, "ex", "examine");

    me.currentRoom = current;
    printf("%s enters the world.\n\n",me.name);
    look_player(&me);
    loop_player(&me);
}
Пример #7
0
void read_all_ply()
{
	char	str[256];
	creature *ply;
	long	offset;
	FILE	*fp;

	/* open ascii source file */
	fp=fopen(player_file, "r");
	if ( fp == NULL )
	{
		printf("Cannot open %s, player_file\n" );
		return;
	}


	while(!feof(fp)) 
	{
		offset = ftell(fp);
		if (EOF == fscanf(fp, "%s", str)) 
			break;
		fseek(fp, offset, 0); /* 0=SEEK_SET ? */

		if (!strcmp(str, "#begPLY")) {
			ply = (creature *)malloc(sizeof(creature));
			if ( ply )
			{
				zero(ply, sizeof(creature));
				if (read_player(fp, str, ply))
					printf("Error reading ascii player. Continuing.\n");
				else if (save_ply_to_file(str, ply))
					printf("Error saving player %s to binary file\n", ply->name);
				else 
					printf("Player %s converted to binary.\n", ply->name);
				free_crt(ply);
			}
		} 
	}

	return;
}
Пример #8
0
int main(int argc, char **argv)
{
	struct list list = LIST_ZERO;
	size_t length;

	load_config();

	if (argc != 2) {
		fprintf(stderr, "usage: %s <query>\n", argv[0]);
		return EXIT_FAILURE;
	}

	/* No need to search when the query is too long or empty */
	length = strlen(argv[1]);
	if (length > 0 && length < NAME_LENGTH)
		search(argv[1], &list);

	CUSTOM_TAB.name = "Search results";
	CUSTOM_TAB.href = "";
	html_header(&CUSTOM_TAB, "Search results", argv[1]);

	if (list.length == 0) {
		printf("No players found");
	} else {
		struct result *result;

		printf("<table><thead><tr><th></th><th>Name</th><th>Clan</th><th>Score</th></tr></thead><tbody>\n");
		for (result = list.first; result; result = result->next) {
			if (!result->is_loaded)
				read_player(&result->player, result->name);
			html_print_player(&result->player, 1);
		}
		printf("</tbody></table>\n");
	}

	html_footer();

	return EXIT_SUCCESS;
}
Пример #9
0
int main(int argc, char **argv)
{
	DIR *dir;
	struct dirent *dp;
	struct clan_array clans = CLAN_ARRAY_ZERO;
	char path[PATH_MAX];

	load_config();
	if (argc != 1) {
		fprintf(stderr, "usage: %s\n", argv[0]);
		return EXIT_FAILURE;
	}

	/* Build in memory the list of all clans with their members */
	sprintf(path, "%s/players", config.root);
	if (!(dir = opendir(path)))
		return perror(path), EXIT_FAILURE;
	while ((dp = readdir(dir))) {
		struct player player;
		struct clan *clan;

		if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
			continue;
		if (!read_player(&player, dp->d_name))
			continue;
		if (!(clan = get_clan(&clans, &player)))
			continue;
		if (!(add_member(clan, &player)))
			continue;
	}
	closedir(dir);

	write_clan_array(&clans);

	return EXIT_SUCCESS;
}
Пример #10
0
/***********************************************************************
 * Read a universe from 'filename'.
 *
 * We're reading photon ascii. So the basic algorithm is to read
 * 'Photon Ascii Instances' and then switch on the type and read the fields.
 * Ignore unknown instances.
 *
 * RETURNS:
 *	On Success, a universe object is returned.
 *	On Failure, NULL is returned and errbuf contains a error message.
 *
 */
UNIVERSE *Universe_ReadAscii(const char *filename, char *errbuf)
{
	PHASCII_FILE phf;
	PHASCII_INSTANCE pi;
	char errmsg[1000];
	int success;
	UNIVERSE *u;

	ASSERT( filename != NULL );
	ASSERT( errbuf != NULL );

	phf = Phascii_Open(filename, "r");
	if( phf == NULL ) {
		strcpy(errbuf, Phascii_GetError());
		return NULL;
	}

	u = NULL;

	while( pi = Phascii_GetInstance(phf) ) {

		if( Phascii_IsInstance(pi, "ORGANIC") ) {
			success = read_organic(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "BARRIER") ) {
			success = read_barrier(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "ER") ) {
			success = read_er(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "KFMO") ) {
			success = read_kfmo(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "KEYLIST") ) {
			success = read_keylist(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "SPORE") ) {
			success = read_spore(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "CELL") ) {
			success = read_cell(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "ORGANISM") ) {
			success = read_organism(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "PLAYER") ) {
			success = read_player(pi, u, errmsg);

		} else if( Phascii_IsInstance(pi, "UNIVERSE") ) {
			success = read_universe(pi, &u, errmsg);

		} else {
			success = 1;
		}

		Phascii_FreeInstance(pi);

		if( ! success ) {
			sprintf(errbuf, "%s", errmsg);
			Phascii_Close(phf);
			return NULL;
		}
	}

	if( ! Phascii_Eof(phf) ) {
		sprintf(errbuf, "%s\n", Phascii_Error(phf));
		Phascii_Close(phf);
		return NULL;
	}

	Phascii_Close(phf);

	if( u == NULL ) {
		sprintf(errbuf, "%s: No UNIVERSE instance", filename);
		return NULL;
	}

	return u;
}