asciijump


Предыдущая | Следующая

Хорошая и продуманная лыжная игра. Сайт, кажется, недоступен, но исходный код легко найти в разных местах. У меня были небольшие проблемы с тем, чтобы он работал под моим компьютером Raspberry Pi; см. ниже для инструкций.

A nice and elaborated ski game. The website seems to be unavailable but the source code is easy to find on various places. I had a little trouble making it work under my Raspberry Pi computer; see below for instructions.

Compiling asciijump on a Raspberry Pi

After compiling the game on a Raspberry Pi, I noticed I couldn’t make it work. The package in the distribution doesn’t work either! After a little debugging, I discovered that the file xfnc.c contains a function called xgetline with a little bug. The (wrong) code is the following:

char *xgetline(FILE *fd)
{
	int length = 1;
	int i = 0;
	char *line = NULL;	for (;;) {
		if (length-1 == i) {
			length *=3;
			line = xrealloc(line, length*(sizeof(char)));
		}		line[i] = fgetc(fd);		if (line[i] == EOF) {
			if (i == 0)
				return NULL;
			line[i] = '';
			break;		} else if (line[i] == '\n') {
			if (i == 0)
				return xgetline(fd);
			line[i] = '';
			break;
		}
		i++;
	}	return line;
}

You have to replace it with:

char *xgetline(FILE *fd)
{
	int length = 1;
	int i = 0;
	char *line = NULL;
        int c;	for (;;) {
		if (length-1 == i) {
			length *=3;
			line = xrealloc(line, length*(sizeof(char)));
		}		c = fgetc(fd);		if (c == EOF) {
			if (i == 0)
				return NULL;
			line[i] = '';
			break;		} else if (c == '\n') {
			if (i == 0)
				return xgetline(fd);
			line[i] = '';
			break;
		}
                line[i] = (char) c;
		i++;
	}	return line;
}