Пример #1
0
/*
 * must_telep:
 *	Must I teleport; i.e., is there anywhere I can move without
 * being eaten?
 */
static bool
must_telep(void)
{
	int x, y;
	static COORD newpos;

#ifdef FANCY
	if (Stand_still && Num_robots > 1 && eaten(&My_pos))
		return true;
#endif

	for (y = -1; y <= 1; y++) {
		newpos.y = My_pos.y + y;
		if (newpos.y <= 0 || newpos.y >= Y_FIELDSIZE)
			continue;
		for (x = -1; x <= 1; x++) {
			newpos.x = My_pos.x + x;
			if (newpos.x <= 0 || newpos.x >= X_FIELDSIZE)
				continue;
			if (Field[newpos.y][newpos.x] > 0)
				continue;
			if (!eaten(&newpos))
				return false;
		}
	}
	return true;
}
Пример #2
0
/*
 * do_move:
 *	Execute a move
 */
static bool
do_move(int dy, int dx)
{
	static COORD newpos;

	newpos.y = My_pos.y + dy;
	newpos.x = My_pos.x + dx;
	if (newpos.y <= 0 || newpos.y >= Y_FIELDSIZE ||
	    newpos.x <= 0 || newpos.x >= X_FIELDSIZE ||
	    Field[newpos.y][newpos.x] > 0 || eaten(&newpos)) {
		if (Running) {
			Running = false;
			leaveok(stdscr, false);
			move(My_pos.y, My_pos.x);
			refresh();
		}
		else {
			putchar(CTRL('G'));
			reset_count();
		}
		return false;
	}
	else if (dy == 0 && dx == 0)
		return true;
	mvaddch(My_pos.y, My_pos.x, ' ');
	My_pos = newpos;
	mvaddch(My_pos.y, My_pos.x, PLAYER);
	if (!jumping())
		refresh();
	return true;
}
Пример #3
0
void Apple::tick(Game & game)
{
  const Vector snakePos = game.getWorld().getSnake().getHeadPos();
  // We've been eaten by the snake
  if(snakePos == myPos)
    eaten(game);
  else
    doTick(game);
}
Пример #4
0
void Character::die() {
	emit(eaten());
}