Esempio n. 1
0
MainScene::MainScene(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainScene),
    m_time_counter(new QTimer(this)),
    m_who_am_i(NOT_PLAYER),
    m_click(new QSound(":/sounds/click.wav"))
{
    ui->setupUi(this);
    connect(ui->transferButton, SIGNAL(clicked(bool)),
            this, SLOT(toChangeTurn()));
    connect(ui->menuButton, SIGNAL(clicked(bool)),
            this, SIGNAL(shouldSetting()));
    connect(ui->undoButton, SIGNAL(clicked(bool)),
            this, SLOT(toSendUndo()));
    connect(ui->giveupButton, SIGNAL(clicked(bool)),
            this, SLOT(toSendGiveup()));
    connect(ui->transferButton, SIGNAL(clicked(bool)),
            m_click, SLOT(play()));
    connect(ui->menuButton, SIGNAL(clicked(bool)),
            m_click, SLOT(play()));
    connect(ui->undoButton, SIGNAL(clicked(bool)),
            m_click, SLOT(play()));
    connect(ui->giveupButton, SIGNAL(clicked(bool)),
            m_click, SLOT(play()));

    connect(this, SIGNAL(remainingTimeChanged(int)),
            this, SLOT(updateRemaining(int)));

    m_time_counter->setInterval(TIMER_INTERVAL);
    connect(m_time_counter, SIGNAL(timeout()),
            this, SLOT(reduceRemaining()));

    connect(ui->boardView, SIGNAL(won()),
            this, SIGNAL(gameWon()));
    connect(ui->boardView, SIGNAL(lost()),
            this, SIGNAL(gameLost()));
    connect(ui->boardView, SIGNAL(finished(bool)),
            this, SIGNAL(gameFinished(bool)));
    connect(ui->boardView, SIGNAL(placed(QPoint,bool,bool)),
            this, SIGNAL(shouldPlace(QPoint,bool,bool)));
}
Esempio n. 2
0
void MinefieldModel::movePlayer(int x, int y)
{
    int newX = _player->x() + x;
    int newY = _player->y() + y;

    if (newX >= 1 && newX <= _boardSize &&
        newY >= 1 && newY <= _boardSize)
    {
        if (_gameBoard[newX][newY] != Empty)
        {
            emit gameLost();
        }
        else
        {
            setPlayer(newX, newY);
        }

    }

    emit refresh();
}
Esempio n. 3
0
void GameManager::handleGameEvents(const Uint8* events)
{
	if(events[BLOCK_DISAPPEARED])
	{

		blockCount -= events[BLOCK_DISAPPEARED];
	}

	if(events[BALLS_DEPLETED])
	{
		gameLost();
	}

	if(events[NEW_GAME])
	{
		visible = true;
		pause = false;
		this->resetLevel();
	}

	if(events[PAUSE_GAME])
	{
		pause = true;
	}

	if(events[RESUME_GAME])
	{
		pause = false;
	}

	if(events[QUIT_GAME])
	{
		visible = false;
		this->resetLevel();
	}
}
Esempio n. 4
0
void GameEngine::startNewGame()
{
    if(m_lives->getLives() && !m_player)
    {
        if(m_gamequeue->empty())
        {
            cleanup();
            showGameWon();
        }
        else
        {
            if(!gameLost())
            {
                m_mtx = new CubeMatrix;
                m_mtx->fillLevel(*m_gamequeue->back());
            }
            m_player = new Racket(100,520);
            m_ball = new Ball(120,400,qreal(3),qreal(-M_PI/2));
            m_player->setFlag(QGraphicsItem::ItemIsFocusable);
            m_player->setFocus();
            setGameLost(false);
        }
    }
}
Esempio n. 5
0
BOOL Game::update()
{
	BOOL updateObjects = FALSE;
	BOOL checkForWinning = FALSE;
	BOOL checkForLosing = FALSE;
	BOOL checkCollisions = FALSE;
	BOOL stopMovement = TRUE;

	switch (itsCurrentState)
	{
		case GAMESTATE_PREGAME :
			// since the pregame section is so different, we will call our own method
			pregameUpdate();
			break;
		case GAMESTATE_INPROGRESS :
			updateObjects = TRUE;
			checkForWinning = TRUE;
			checkForLosing = TRUE;
			checkCollisions = TRUE;
			stopMovement = FALSE;
			break;
		case GAMESTATE_WON :
		{
			updateObjects = TRUE;
			Room *room = itsPlayer->getRoom();
			// we need to change the walls a color for that ending flashiness
			if (itsLastTickTime - itsWinTime >= theWinAnimationLength)
			{	
				for (UINT i=0;i<room->getWalls()->length();i++)
				{
					Wall *wall = (Wall *)(room->getWalls()->elementAt(i));
					wall->setChangesColor(FALSE);
				}
			}
			else
			{
				// since the player will be holding the chalice, we can tell
				// the walls to change colors, and they will change to the color
				// of the chalice, which will make them appear to animate
				for (UINT i=0;i<room->getWalls()->length();i++)
				{
					Wall *wall = (Wall *)(room->getWalls()->elementAt(i));
					wall->setChangesColor(TRUE,1);
				}
			}
			// hack to put the player in the right place for the ending
			itsPlayer->setX(Game::theScreenHeight-64);
			itsPlayer->setY(Game::theScreenWidth/2-16);
		}
		break;
		case GAMESTATE_LOST :
			updateObjects = TRUE;
			stopMovement = FALSE;
			break;
		case GAMESTATE_PAUSED :
			stopMovement = FALSE;
			break;
	}

	theEventDispatcher.update(itsLastTickTime);


	if (updateObjects)
	{
		SimpleArray *objects = NULL;
		if (itsWorld != NULL)
		objects = itsWorld->getObjects();
		for (UINT i=0;i<objects->length();i++)
		{
			((GameObject *)(objects->elementAt(i)))->update(itsLastTickTime);
			if (stopMovement)
			{
				((GameObject *)(objects->elementAt(i)))->stopMoving(itsLastTickTime);
			}
		}
		for (i=0;i<itsWorld->getRooms()->length();i++)
		{
			((Room *)(itsWorld->getRooms()->elementAt(i)))->checkForObjectsLeaving();
		}
	}
	if (checkForWinning && gameWon())
	{
		itsNewStateRequest.itsNewState = GAMESTATE_WON;
		itsNewStateRequest.isActiveRequest = TRUE;
	}
	if (checkForLosing && gameLost())
	{
		itsNewStateRequest.itsNewState = GAMESTATE_LOST;
		itsNewStateRequest.isActiveRequest = TRUE;
	}
	if (checkCollisions)
		return checkForCollisions();
	else
		return TRUE;
}