Exemplo n.º 1
0
void Game::handleEvents()
{
	SDL_Event event;
	while(SDL_PollEvent(&event) != 0)
	{
		if(event.type == SDL_QUIT)
		{
			running = false;
		}
		if((event.type == SDL_MOUSEBUTTONDOWN) && (event.button.button == SDL_BUTTON_RIGHT)){
			rightMouseRemoveBet(event);
		}
		if((event.type == SDL_MOUSEBUTTONDOWN) && (event.button.button == SDL_BUTTON_LEFT))
		{
			clearButtonsMODE();
			nullBetAndWin();
			handleRollButton(event);
			handleClearButton(event);
			handleNewGameButton(event);
			handleSoundsButtons(event);
			handleHelpButton(event);
			handleBackToGameButton(event);
			handleStatsMenuButton(event);
			leftMouseSetBet(event);

		}
	}
	record.recordCredit(player.showCredit());
}
Exemplo n.º 2
0
/**
  * Constructor for MainWindow. It will initialize the entire board and create the necessary starting elements for the game
  */
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    //Global variables
    hasFinished = false; //Has the game finished?
    cellsRevealed = 0; //Number of current cells revealed
    flagsFlagged = 0; //Number of flags that have been flagged
    minesFlagged = 0; //Number of mines that have been flagged
    hasStarted = false; //If the game has started yet
    currentTime = 0; //The current time in seconds

    ui->setupUi(this);

    //Layout designs
    ui->mineContainer->setSpacing(0); //Forces the board cells to be spaced next to each other

    //Timer for the number of seconds that has passed by
    timer = new QTimer();

    //The display of the number of flags that have been put up (Mines left to solve)
    ui->lcdFlagCount->setDigitCount(2);
    ui->lcdFlagCount->display ( NUMBER_OF_MINES - flagsFlagged );

    //Initialize statuses
    // 0 = Empty, 1 = flagged, 2 = ?
    for ( int i = 0; i < 10; i++)
    {
        for ( int j = 0; j < 10; j++)
            mineStatus[i][j] = 0;
    }

    //Connect the UI elements
    connect(ui->actionHelp, SIGNAL(triggered()), this, SLOT(handleHelpButton()));
    connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(handleAboutButton()));
    connect(ui->action_Reset, SIGNAL(triggered()), this, SLOT(reset()));
    connect(ui->smileyFace, SIGNAL(clicked()), this, SLOT(handleSmileyFace()));
    connect(ui->actionTop_Ten, SIGNAL(triggered()), this, SLOT(handleTopTen()));
    connect(timer, SIGNAL(timeout()), this, SLOT(updateTimer()));

    //Now handle the actual game.. enough of this extra feature stuff. Now for the real deal!
    game = new Minesweeper();

    //We will need to map the click to an object's coordinates
    signalMapper = new QSignalMapper(this);
    signalMapper2 = new QSignalMapper(this);

    //Generate all the buttons for the game
    for( int i = 0; i < 10; i++)
    {
        for( int j = 0; j < 10; j++ )
        {
            MineSweeperButton* button = new MineSweeperButton("");

            //Button Styling
            button->setAttribute(Qt::WA_LayoutUsesWidgetRect); //Forces Mac OS X styled minesweeper to look like linux/windows
            button->setMaximumHeight(30);
            button->setMaximumWidth(30);
            button->setIcon (QIcon(QString(":/images/not_flat_button.png")));
            button->setIconSize (QSize(30,30));

            //Actually add the button to the container
            ui->mineContainer->addWidget(button, i, j);
            QString coordinates = QString::number(i)+","+QString::number(j); //Coordinate of the button
            //Map the coordinates to a particular MineSweeperButton
            signalMapper->setMapping(button, coordinates);
            signalMapper2->setMapping(button, coordinates);

            //Connections for the buttons
            connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
            connect(button, SIGNAL(rightButtonClicked()), signalMapper2, SLOT(map()));
            connect(button, SIGNAL(pressed()), this, SLOT(handleButtonPressed()));
            connect(button, SIGNAL(released()), this, SLOT(handleButtonReleased()));
        }
    }

    //Connect the signal mapper to this class so that we can handle its clicks
    connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(revealCell(QString))); //Left click
    connect(signalMapper2, SIGNAL(mapped(QString)), this, SLOT(hasRightClicked(QString))); //Right click
}