示例#1
0
void SpaceShip::checkCollision(Terrain terrain) {
	if (getY() < terrain.terrainHeight) {
		Point *bottomPoints = getPositions();
        
		if (bottomPoints[3].y <= terrain.getHight(bottomPoints[3].x)) {
			loseGame();
		} else if (abs(bottomPoints[0].y - bottomPoints[1].y) < 3) {
			if (bottomPoints[0].y <= terrain.getHight(bottomPoints[0].x)
                || bottomPoints[2].y
                <= terrain.getHight(bottomPoints[2].x)) {
				if (abs(bottomPoints[1].y - terrain.getHight(bottomPoints[1].x))
                    < 2) {
					winGame();
				} else {
					loseGame();
				}
			}
		} else {
			if (bottomPoints[0].y <= terrain.getHight(bottomPoints[0].x)
                || bottomPoints[1].y <= terrain.getHight(bottomPoints[1].x)
                || bottomPoints[2].y
                <= terrain.getHight(bottomPoints[2].x)) {
				loseGame();
			}
		}
	}
}
示例#2
0
void PingPong::update(float dt)
{
	if (GameMode::Inst().mode != GameMode::GM_GAME_PLAY)
		return;

	const float ballPosY = _ball->getPositionY();
	if (ballPosY < 0)
		loseGame(PC_KEYBOARD);
	else if (ballPosY > GlobalValues::cScreenHeight)
		loseGame(PC_MOUSE);
}
示例#3
0
void checkWrongPress() /* Checa se o botao foi pressionado erroneamente */
{
	if(digitalRead(BUT_PIN)) 
	{
		pressed = true;
		if(pressArray[counter]==0)
		{
			loseGame();
		}
	}
}
示例#4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->backStepButton, SIGNAL(clicked()), ui->playScreen, SLOT(backStep()));
    connect(ui->failButton, SIGNAL(clicked()), ui->playScreen, SLOT(loseGame()));
    connect(ui->startButton, SIGNAL(clicked()),ui->playScreen, SLOT(startGame()));

    ui->help->hide();
    ui->hostChose->hide();
    ui->playScreen->hide();
}
示例#5
0
void checkRightPress() /* Checa se o botao foi pressionado ao passar para o proximo numero */
{
	if(pressArray[counter]==1)
	{
		if(!pressed)
		{
			loseGame();
		}
		else
		{
			pressed = false;
			rightRounds++;
		}
	}
}
void update() {
	switch (GameObj.currentGameState) {
		case StartGame:
			startGame();
			GameObj.currentGameState = DisplayPattern;
		break;
		case DisplayPattern:
			GameObj.inputIndex = 0; // reset index at beginning of each display so correct entire pattern again
			displayPattern();
			GameObj.currentGameState = UserInput;
		break;
		case UserInput:
			P1OUT &= ~GLED;
			GameObj.userInput[GameObj.inputIndex] =  receiveUserInput();
			GameObj.currentGameState = CheckInput;
		break;
		case CheckInput:
			GameObj.pass = checkInput();
			if (GameObj.pass && GameObj.inputIndex == (PATTERN_LENGTH-1)) { //MAKE SURE TO INCREMENT INDEX
				P1OUT |= GLED;
				GameObj.currentGameState = WinGame;
			} else if(GameObj.pass && (GameObj.inputIndex == GameObj.patternIndex)) {
				P1OUT |= GLED;
				BlinkLEDs();
				GameObj.patternIndex += 2;
				GameObj.currentGameState = DisplayPattern;
			}	else if(GameObj.pass) {
				GameObj.inputIndex++;
				GameObj.currentGameState = UserInput;
			} else {
				P1OUT &= ~GLED;
				GameObj.currentGameState = LoseGame;
			}
		break;
		case WinGame:
			winGame();
		break;
		case LoseGame:
			loseGame();
		break;
	}
}
示例#7
0
GameWindow::GameWindow(int sizeX, int sizeY, int minesNumber) :
    QMainWindow(),
    ui(new Ui::GameWindow)
{
    ui->setupUi(this);

    QPixmap background(":/resources/images/options_background.jpg");
        QPalette qPalette;
        qPalette.setBrush(this->backgroundRole(),QBrush(background));
        this->setPalette(qPalette);

    sizeOfFieldX = sizeX;
    sizeOfFieldY = sizeY;
    minesInTheField = minesNumber;

    core = new Field(sizeOfFieldX, sizeOfFieldY, minesInTheField);
    fieldLayout = new QGridLayout;

    backButton = new QPushButton("Back to menu");
    backButton->setStyleSheet(QPushButtonStyle);
    backButton->setFixedSize(175,50);

    refreshButton = new QPushButton("Refresh game");
    refreshButton->setStyleSheet(QPushButtonStyle);
    refreshButton->setFixedSize(175,50);

    QObject::connect(backButton, SIGNAL(clicked(bool)), this, SLOT(backToMenu()));
    QObject::connect(refreshButton, SIGNAL(clicked(bool)), this, SLOT(refreshGame()));

    mainFieldLayout = new QVBoxLayout;
    panelLayout = new QVBoxLayout;
    mainLayout = new QHBoxLayout;

    vector<QMyPushButton*> tmpVect;
    for (int i = 0; i < core->getSizeX(); i++)
    {
        for (int j = 0; j < core->getSizeY(); j++)
        {
            QMyPushButton* newButton;
            tmpVect.push_back(newButton);
        }
        buttons.push_back(tmpVect);
    }

    QLabel *fieldHeight = new QLabel("Height of field:   ");
    fieldHeight->setStyleSheet(QLabelStyle);
    QLabel *fieldLength = new QLabel("Length of field:   ");
    fieldLength->setStyleSheet(QLabelStyle);
    QLabel *allCells = new QLabel("Cells in the field:");
    allCells->setStyleSheet(QLabelStyle);
    QLabel *cellsLeft = new QLabel("Cells left:           ");
    cellsLeft->setStyleSheet(QLabelStyle);
    QLabel *minesLeft = new QLabel("Mines left:         ");
    minesLeft->setStyleSheet(QLabelStyle);
    QLabel *flagsLeft = new QLabel("You have flags:  ");
    flagsLeft->setStyleSheet(QLabelStyle);


    fieldHeightNumber = new QLabel(QString::number(core->getSizeX()));
        fieldHeightNumber->setStyleSheet(QLabelStyle);
    fieldLengthNumber = new QLabel(QString::number(core->getSizeY()));
        fieldLengthNumber->setStyleSheet(QLabelStyle);
    allCellsNumber = new QLabel(QString::number(core->getSizeX() * core->getSizeY()));
        allCellsNumber->setStyleSheet(QLabelStyle);
    cellsLeftNumber = new QLabel(QString::number(core->cellsLeft));
        cellsLeftNumber->setStyleSheet(QLabelStyle);
    minesLeftNumber = new QLabel(QString::number(core->minesLeft));
        minesLeftNumber->setStyleSheet(QLabelStyle);
    flagsLeftNumber = new QLabel(QString::number(core->flagsLeft));
        flagsLeftNumber->setStyleSheet(QLabelStyle);

    QHBoxLayout *panelHorizontal1 = new QHBoxLayout;
    panelHorizontal1->addWidget(fieldHeight);
    panelHorizontal1->addWidget(fieldHeightNumber);
    QHBoxLayout *panelHorizontal2 = new QHBoxLayout;
    panelHorizontal2->addWidget(fieldLength);
    panelHorizontal2->addWidget(fieldLengthNumber);
    QHBoxLayout *panelHorizontal3 = new QHBoxLayout;
    panelHorizontal3->addWidget(allCells);
    panelHorizontal3->addWidget(allCellsNumber);
    QHBoxLayout *panelHorizontal4 = new QHBoxLayout;
    panelHorizontal4->addWidget(cellsLeft);
    panelHorizontal4->addWidget(cellsLeftNumber);
    QHBoxLayout *panelHorizontal5 = new QHBoxLayout;
    panelHorizontal5->addWidget(minesLeft);
    panelHorizontal5->addWidget(minesLeftNumber);
    QHBoxLayout *panelHorizontal6 = new QHBoxLayout;
    panelHorizontal6->addWidget(flagsLeft);
    panelHorizontal6->addWidget(flagsLeftNumber);

    //timer = new QTimer;
    //timer->start(10000);

    panelLayout = new QVBoxLayout;
    mainPanelLayout = new QVBoxLayout;
    panelBox = new QGroupBox;

    panelLayout->addSpacing(5);
    panelLayout->addLayout(panelHorizontal1);
    panelLayout->addLayout(panelHorizontal2);
    panelLayout->addLayout(panelHorizontal3);
    panelLayout->addLayout(panelHorizontal4);
    panelLayout->addLayout(panelHorizontal5);
    panelLayout->addLayout(panelHorizontal6);
    panelBox->setLayout(panelLayout);

    mainPanelLayout->addWidget(panelBox);
    //mainPanelLayout->addWidget(timer);
    mainPanelLayout->addStretch(1);
    mainPanelLayout->addWidget(refreshButton);
    mainPanelLayout->addWidget(backButton);
    mainPanelLayout->setSpacing(20);




    for (int i = 0; i < core->getSizeX(); i++)
        for (int j = 0; j < core->getSizeY(); j++)
        {
            buttons[i][j] = new QMyPushButton;
            fieldButtonSize = new QSize(32,32);
            buttons[i][j]->setStyleSheet(QFieldButtonStyle);
            buttons[i][j]->setFixedSize(*fieldButtonSize);
            //buttons[i][j]->setText("Do it!");
            fieldLayout->addWidget(buttons[i][j], i, j, 1, 1);
            buttons[i][j]->setProperty("coordinates", i * 1000 + j);
            connect(buttons[i][j], SIGNAL(pressed()), this, SLOT(clickedLeft()));
            connect(buttons[i][j], SIGNAL(rClicked()), this, SLOT(setFlag()));
            //QMyPushButton *but = new QMyPushButton;
            //connect(but, SIGNAL())

        }
    //mainFieldLayout->addSpacing(15);
    fieldLayout->setSpacing(0);
    mainFieldLayout->addLayout(fieldLayout);

    //mainLayout->addSpacing(15);
    mainLayout->addLayout(mainFieldLayout);
    mainLayout->addSpacing(25);
    mainLayout->addLayout(mainPanelLayout);
    //mainLayout->addSpacing(15);

    QWidget *centralWidget = new QWidget;
    centralWidget->setLayout(mainLayout);
    this->setCentralWidget(centralWidget);
    this->setWindowTitle("Minesweeper TOP Game");
    this->setWindowIcon(QIcon(":/resources/images/icon.png"));

    connect(this, SIGNAL(allCellsOpen()), this, SLOT(winGame()));
    connect(this, SIGNAL(allah_BABAH()), this, SLOT(loseGame()));


}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow){
    ui->setupUi(this);

    // Initialize Bet
    ui->GuessNumBet->setNum(Config::GuessNumBet);
    ui->BlackJackBet->setNum(Config::BlackjackBet);

    // Initialize server configs
    this->socket = -1;
    this->serverIP = ui->serverIPDisplay->text();
    this->serverPort = ui->serverPortDisplay->text().toInt();

    // Initialize games
    this->guess_num_client = new GuessNumClient(this);
    this->blackjack_client = new BlackJackClient(this);
    this->guess_num_client->setModal(true);
    this->blackjack_client->setModal(true);

    // Initialize keep alive timer
    this->keepAlive = new QTimer();
    this->keepAlive->setInterval(Config::KeepAliveFrequency);

    // Initialize dialog
    this->initializeWaitDialog();
    this->initializeGuessNumDialogs();
    this->initializeBlackjackDialogs();

    *(user.mutable_name()) = "Anomynous";
    ui->name->setText(QString("Anomynous"));
    ui->BlackJackButton->setEnabled(false);
    ui->GuessNumButton->setEnabled(false);

    // Register custom type so QObject::connect can work
    qRegisterMetaType<System::Type>("System::Type");

    QObject::connect(ui->ConfigureServerButton,     SIGNAL(clicked()),                 this, SLOT(showServerConfigDialog()));
    QObject::connect(ui->TryConnectionButton,       SIGNAL(clicked()),                 this, SLOT(tryConnect()));
    QObject::connect(this,                          SIGNAL(connectionInvalid()),       this, SLOT(warnConnection()));
    QObject::connect(this->keepAlive,               SIGNAL(timeout()),                 this, SLOT(keepAlivePokeServer()));

    QObject::connect(this->guess_num_client,        SIGNAL(waitForRival()),            this->guessnum_congrat, SLOT(exec()));
    QObject::connect(this->guess_num_client,        SIGNAL(loseGame()),                this->guessnum_loser, SLOT(exec()));
    QObject::connect(this->guess_num_client,        SIGNAL(winGame()),                 this->guessnum_winner, SLOT(exec()));
    QObject::connect(this->guess_num_client,        SIGNAL(modify_player_money(int)),  this, SLOT(increaseMoney(int)));
    QObject::connect(this->guess_num_client,        SIGNAL(finished(int)),             this->guess_num_client, SLOT(cleanUp()));

    QObject::connect(this->blackjack_client,        SIGNAL(modify_player_money(int)),  this, SLOT(increaseMoney(int)));
    QObject::connect(this->blackjack_client,        SIGNAL(waitForRival()),            this->blackjack_wait, SLOT(exec()));
    QObject::connect(this->blackjack_client,        SIGNAL(showBlackjackResult(int,int)), this->blackjack_result_dialog, SLOT(showResult(int,int)));
    QObject::connect(this->blackjack_client,        SIGNAL(finished(int)),             this->blackjack_client, SLOT(cleanUp()));

    QObject::connect(this->blackjack_result_dialog, SIGNAL(finished(int)),             this->blackjack_client, SLOT(accept()));

    QObject::connect(ui->GuessNumButton,            &QPushButton::clicked,             [this](){ joinGame(System::GUESSNUM); });
    QObject::connect(ui->BlackJackButton,           &QPushButton::clicked,             [this](){ joinGame(System::JACK); });
    QObject::connect(this->guess_num_client,        SIGNAL(rival_die()),  this, SLOT(handleGuessNumPlayerDie()));
    QObject::connect(this->blackjack_client,        SIGNAL(rival_die()),  this, SLOT(handleBlackJackPlayerDie()));

    // Prompt for change name at startup.
    changeName();
}
示例#9
0
void SpaceShip::checkFuelandTime(){
    if(fuel <= 0 || time <= 0)
        loseGame();
}