VirtScreen::VirtScreen(World * const world_, Player * const player_) :
        w(world_),
        player(player_),
        settings(home_path + "freg.ini", QSettings::IniFormat),
        previousCommand(settings.value("last_command", "moo").toString())
{
    connect(     w, SIGNAL(Notify(QString)), SLOT(Notify(QString)),
        Qt::DirectConnection);
    connect(player, SIGNAL(Notify(QString)), SLOT(Notify(QString)),
        Qt::DirectConnection);
    connect(player, SIGNAL(ShowFile(QString)), SLOT(DisplayFile(QString)));
    connect(player, SIGNAL(GetFocus(int *, int *, int *)),
        SLOT(ActionXyz(int *, int *, int *)), Qt::DirectConnection);

    connect(     w, SIGNAL(GetString(QString &)),
        SLOT(PassString(QString &)), Qt::DirectConnection);
    connect(player, SIGNAL(GetString(QString &)),
        SLOT(PassString(QString &)), Qt::DirectConnection);

    connect(player, SIGNAL(Updated()), SLOT(UpdatePlayer()),
        Qt::DirectConnection);
    connect(w, SIGNAL(UpdatedAll()), SLOT(UpdateAll()),
        Qt::DirectConnection);
    connect(w, SIGNAL(Moved(int)), SLOT(Move(int)),
        Qt::DirectConnection);
    connect(w, SIGNAL(Updated(int, int, int)), SLOT(Update(int, int, int)),
        Qt::DirectConnection);
    connect(w, SIGNAL(UpdatedAround(int, int, int, int)),
        SLOT(UpdateAround(int, int, int, int)),
        Qt::DirectConnection);
    connect(w, SIGNAL(UpdatesEnded()), SLOT(UpdatesEnd()),
        Qt::DirectConnection);

    connect(player, SIGNAL(Destroyed()), SLOT(DeathScreen()),
        Qt::DirectConnection );
}
Exemple #2
0
void updateSnake(SnakeHead * snake) {
	drawSpaceSnake(snake);
	snake->lastPos = snake->pos;
	snake->lastDirection = snake->direction;
	/* This function will get the next position, check if is a hit, score or move, and call the right function */
	switch (snake->direction)
	{
	case NORTH:
		snake->pos.Y -= 1;
		break;
	case SOUTH:
		snake->pos.Y += 1;
		break;
	case EAST:
		snake->pos.X += 1;
		break;
	case WEST:
		snake->pos.X -= 1;
		break;
	}
	/* Update the snake body */
	SnakeBody * tmp = snake->next;
	if (tmp != NULL)
	{
		tmp->lastPos = tmp->pos;
		tmp->lastDirection = tmp->direction;
		tmp = tmp->next;
		while (tmp != NULL)
		{
			/* LastPosition of every block */
			tmp->lastPos = tmp->pos;
			tmp->lastDirection = tmp->direction;
			tmp = tmp->next;
		}

		/* Updates the body positions */
 		tmp = snake->next;
		tmp->pos = snake->lastPos;
		tmp->direction = snake->lastDirection;
		if (tmp->next != NULL)
		{
			tmp = tmp->next;
			while (tmp != NULL)
			{
				tmp->pos = tmp->prev->lastPos;
				tmp->direction = tmp->prev->lastDirection;
				tmp = tmp->next;
			}
		}
		
	}

	if ((snake->nextPosSymbol != ' ') && (snake->nextPosSymbol != FRUIT))
	{
		// Implement Death Functions
		DeathScreen(snake);
		while (!_kbhit())
		{
			continue;
		}
		exit(0);
	}
	if (snake->nextPosSymbol == FRUIT)
	{
		addScore(snake);
		snake->digesting = true;
	}
	drawSnake(snake);
}