Esempio n. 1
0
void updateGame(PLAYER* p1, PLAYER* p2, BALL* ball)
{
	if (ball->y <= 0 || ball->y + ball->size >= height)
	{
		ball->dY *= -1;
	}

	if (ball->x <= p1->hit_x)
	{
		if (ball->y + ball->size >= p1->hit_y1 && ball->y + ball->size <= p1->hit_y2)
		{
			ball->dX *= -1;
		}
	}
	else if (ball->x + ball->size >= p2->hit_x)
	{
		if (ball->y + ball->size >= p2->hit_y1 && ball->y + ball->size <= p2->hit_y2)
		{
			ball->dX *= -1;
		}
	}

	if (ball->x + ball->size <= 0)
	{
		p2->score += 1;
		nextRound(p1, p2, ball, P2);
		side = P2;
		ball->dX = -ball->speed;
	}
	else if (ball->x >= width)
	{
		p1->score += 1;
		nextRound(p1, p2, ball, P1);
		side = P1;
		ball->dX = ball->speed;
	}

	if (!start && !firstGame)
	{
		if (side == P1)
		{
			ball->y = p1->y + p1->size_y / 2;
		}
		else if (side == P2)
		{
			ball->y = p2->y + p2->size_y / 2;
		}
	}
}
Esempio n. 2
0
/* getNumber()
 * Retrieve four bytes from the rng and returns a single 32 bit int
 */
uint32_t Random::getNumber() {

	uint32_t ret = 0;

	ret |= _keystream << 24;
	nextRound();
	ret |= _keystream << 16;
	nextRound();
	ret |= _keystream << 8;
	nextRound();
	ret |= _keystream;

	nextRound();
	return ret;
}
Esempio n. 3
0
//--------------------------------------------------------------
void ofApp::keyPressed(int key){

    switch (key) {
        case 'c':
            camDebug = !camDebug;
            break;
        case 'f':
            ofToggleFullscreen();
            break;
        case 'd':
            dataConnect.pullData();
            break;
        case ' ':
            if(!GO_MODE){
                GO_MODE = true;
                nextRound();
            } else{
                 GO_MODE = false;
            }
            break;
        case 'r':
            sendRound();
            break;
        default:
            break;
    }
}
Esempio n. 4
0
 void Game::update(Float32 elapsedTime) {
     if (getRound().isOver()) {
         if (!getRound().isLast()) {
             nextRound();
         }
     } else {
         getRound().update(elapsedTime);
     }
 }
Esempio n. 5
0
void GameState::nextTurn()
{
    if (roundNum_ == 0) {
        nextRound();
        return;
    }

    if (turnOrder_.empty()) return;

    ++curTurn_;
    int endOfRound = turnOrder_.size();
    while (curTurn_ < endOfRound && !getUnit(turnOrder_[curTurn_]).isAlive()) {
        ++curTurn_;
    }

    if (curTurn_ == endOfRound) {
        nextRound();
    }

    onStartTurn();
}
Esempio n. 6
0
    void Game::keyEvent(const KeyPressEvent &event) {
        if (event.getCode() == SDLK_ESCAPE && (isOver() || event.withShift())) {
            close();
            return;
        }
        if (event.getCode() == SDLK_TAB && (!getRound().hasWinner())) {
            displayScoreTab = !displayScoreTab;
        }

        if (!getRound().isLast()) {
            if (event.getCode() == SDLK_F1 && (getRound().hasWinner() || event.withShift())) {
                nextRound();
                return;
            }
            if (getRound().hasWinner() && ((D6_GAME_OVER_WAIT - getRound().getRemainingGameOverWait()) > 3.0f)) {
                nextRound();
                return;
            }
        }

        getRound().keyEvent(event);
    }
Esempio n. 7
0
void Game::decPoints()
{
    PlayerStats.Score -= GameParameters.PointsForScore;
    PlayerStats.ScoreGain -= GameParameters.PointsForScore;

    if (PlayerStats.ScoreGain < GameParameters.GainThreshold) BoostPicture->setVisibility(false);

    LosePicture->setVisibility(1);
    ViewHandler->updateText(Score, std::to_string(PlayerStats.Score).std::string::c_str());

    ViewHandler->update();
    nextRound();
}
Esempio n. 8
0
void GamePairs::mainGameLoop()
{
    displayDelegate->showRound(round);
    displayDelegate->showBoard();

    Card& cardFirst  = displayDelegate->letUserChooseCard(cards());
    Card& cardSecond = displayDelegate->letUserChooseCard(cards());

    if (cardFirst.isSameCard(cardSecond))
        return cancelSelection(cardFirst, cardSecond);

    if (tryTakeCards(cardFirst, cardSecond))
    {
        displayDelegate->showCurrentPlayerSuccess();
    } else {
        displayDelegate->showCurrentPlayerFail();
        nextRound();
    }
}
Esempio n. 9
0
void SeasonScreen::buttonPressed(boost::shared_ptr<Button> button)
{
	const std::string& buttonText = button->getText();
	if(buttonText == "Back") {
		mScreenManager->dropScreensUntil("Main Menu");
	}
	else if(buttonText == "Save") {
		save();
	}
	else if(buttonText == "Next Round") {
		nextRound();
	} else if(buttonText == "Finish Season") {
		finishSeason();
	} else if(buttonText == "Prev") {
		scrollUp();
	} else if(buttonText == "Next") {
		scrollDown();
	}
}
Esempio n. 10
0
/* init()
 * Initialize the internal rc4 rng with KEYLENGTH bytes from either
*  /dev/urandom - Linux
*  CryptGenRandom - Windows
*/
void Random::init() {
	char key[KEYLENGTH];

#ifdef _WINDOWS_
	HCRYPTPROV hCryptProv;

	if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)) {
		printf("CryptAcquireContext succeeded. \n");
	} else
		MyHandleError("Error during CryptAcquireContext!\n");

	if (CryptGenRandom(hCryptProv, KEYLENGTH / 2, (BYTE*) key)) {
		printf("Random sequence generated\n");
	} else
		MyHandleError("Error during CryptGenRandom.");

#endif //Windows
#ifdef _LINUX_
	if ((FILE fUrandom = fopen("/dev/urandom", r)) != NULL)
	fscanf(fUrandom, "%16c", pbData);
	else
	fprintf(stderr, "Error opening /dev/urandom: %d", errno);
#endif

	//Initialize the internal state of the rc4 rng
	for (int i = 0; i < 256; ++i)
		_s[i] = i;

	_j = 0;
	for (int c = 0; c < 256; ++c) {
		_j = (_j + _s[c] + key[c % KEYLENGTH]) % 256;
		char temp = _s[_j];
		_s[_j] = _s[c];
		_s[c] = temp;
	}
	_i = 0;
	_j = 0;
	nextRound();
}
Esempio n. 11
0
int StudentWorld::move()
{
	setDisplayText();
	double roundFactor = 0.9 + 0.1*roundNumber();
	if (testParamsProvided() == true)
	{
		if (m_actors.empty())
		{
			int whichActor = getTestParam(TEST_PARAM_ACTOR_INDEX);
			if (whichActor == TEST_PARAM_NACHLING)
				m_actors.push_back(new Nachling(this, int(5*roundFactor)));
			else if (whichActor == TEST_PARAM_WEALTHY_NACHLING)
				m_actors.push_back(new WealthyNachling(this, int(8*roundFactor)));
			else if (whichActor == TEST_PARAM_SMALLBOT)
				m_actors.push_back(new SmallBot(this, int(12*roundFactor)));
			else if (whichActor == TEST_PARAM_GOODIE_ENERGY)
				m_actors.push_back(new Goodie(IID_ENERGY_GOODIE, this, 15, 39));
			else if (whichActor == TEST_PARAM_GOODIE_TORPEDO)
				m_actors.push_back(new Goodie(IID_TORPEDO_GOODIE, this, 15, 39));
			else if (whichActor == TEST_PARAM_GOODIE_FREE_SHIP)
				m_actors.push_back(new Goodie(IID_FREE_SHIP_GOODIE, this, 15, 39));
		}		
	}
	else
	{
		int numActiveAliens = numberOfActiveAliens();
		m_nMaxAliens = maxAliensAllowed();
		if (numActiveAliens < m_nMaxAliens)
		{
			if (numActiveAliens < m_nNeeded)
			{
				
				int p1 = rand() % 100 + 1;
				if (p1 < 70)
				{
					int p2 = rand() % 100 + 1;
					if (p2 < 20)
						m_actors.push_back(new WealthyNachling(this, int(8*roundFactor)));
					else
						m_actors.push_back(new Nachling(this, int(5*roundFactor)));
				}
				else
					m_actors.push_back(new SmallBot(this, int(12*roundFactor)));
			}
		}
		if (rand() % 3 == 0) // There is a 1 in 3 chance that you will add a single Star to the space field
			m_actors.push_back(new Star(this));
	}
	
	m_player->doSomething();

	std::list<Actor*>::iterator position;
	std::list<Actor*>::iterator temp;
	position = m_actors.begin();
	while (position != m_actors.end())
	{
		(*position)->doSomething();
		if (!(*position)->isAlive())
		{
			temp = position;	
			position++;
			delete (*temp);
			m_actors.erase(temp);
			continue;
		}
		position++;
	}
	if (m_nNeeded <= 0)
	{
		m_roundNumber++;
		nextRound();
	}
	if (m_player->currentEnergy() > 0)
		return GWSTATUS_CONTINUE_GAME;
	else
	{
		decLives();
		return GWSTATUS_PLAYER_DIED;
	}
}
Esempio n. 12
0
void Server::checkGame()
{
    qDebug() << "Server::checkGame()";
    int highValueRoundOne;
    int highValueRoundTwo;
    int highValueRoundThree;
    int playerWinnerRoundOne;
    int playerWinnerRoundTwo;
    int playerWinnerRoundThree;
    bool team0Winner;
    bool team1Winner;
    highValueRoundOne = 0;
    highValueRoundTwo = 0;
    highValueRoundThree = 0;
    playerWinnerRoundOne = -1;
    playerWinnerRoundTwo = -1;
    playerWinnerRoundThree = -1;
    team0Winner = false;
    team1Winner = false;

    // round = [0,1,2]
    //qDebug() << "Card of player0:" << cardsOfRoundOne[0];
    //qDebug() << "Card of player1:" << cardsOfRoundOne[1];
    for (int i = 0; i < numberOfPlayers; i++) {
        if (cardsOfRoundOne[i] > highValueRoundOne) {//when round 0
            qDebug() << "Cards round one: " << cardsOfRoundOne[i];
            highValueRoundOne = cardsOfRoundOne[i];
            playerWinnerRoundOne = i;
        }
        if (getRound() != 0) //when round 1
            if (cardsOfRoundTwo[i] > highValueRoundTwo) {
                qDebug() << "Cards round two: " << cardsOfRoundTwo[i];
                highValueRoundTwo = cardsOfRoundTwo[i];
                playerWinnerRoundTwo = i;
            }
        if (getRound() == 2) { //when round 2
            if (cardsOfRoundThree[i] > highValueRoundThree) {
                qDebug() << "Cards round three: " << cardsOfRoundThree[i];
                highValueRoundThree = cardsOfRoundThree[i];
                playerWinnerRoundThree = i;
            }
        }
        qDebug() << "High Value Card of Round[0]" <<highValueRoundOne;
        qDebug() << "High Value Card of Round[1]" <<highValueRoundTwo;
        qDebug() << "High Value Card of Round[2]" <<highValueRoundThree;
    }

    qDebug() << "Winner first round" << playerWinnerRoundOne;
    qDebug() << "Winner second round" << playerWinnerRoundTwo;
    qDebug() << "Winner third round" << playerWinnerRoundThree;

    if (round > 0) {
        qDebug() << "Round 2 tests";
        if (playerWinnerRoundOne % 2 == 0) {
            if (playerWinnerRoundTwo % 2 == 0) {
                team0Winner = true; //ganhou 1 e 2
                qDebug() << "Team0 Win round 1 and 2";
            } else {//perdeu 2
                if (round == 2) {
                    if (playerWinnerRoundThree % 2 == 0) {
                        team0Winner = true; // ganhou 1 e 3
                        qDebug() << "Team0 Win round 1 and 3";
                    } else {
                        team1Winner = true; // perdeu 2 e 3
                        qDebug() << "Lost round 2 and 3";
                    }
                }
            }
        } else {//perdeu 1
            if (playerWinnerRoundTwo %2 == 0) {
                if (round == 2) {
                    if (playerWinnerRoundThree % 2 == 0) {
                        team0Winner = true; // ganhou 2 e 3
                        qDebug() << "Team0 Win round 2 and 3";
                    } else {
                        team1Winner = true; // perdeu 1 e 3
                        qDebug() << "Team0 Lost round 1 and 3";
                    }
                }
            } else {
                team1Winner = true; // perdeu 1 e 2
                qDebug() << "Lost round 1 and 2";
            }
        }
    }

    if (!team0Winner && !team1Winner) {
        // The player who win this round play again
        if (round == 0) {
            qDebug() << "No game's winner | round[0]";
            setPlayerTurn(playerWinnerRoundOne);
        }
        if (round == 1) {
            qDebug() << "No game's winner | round[1]";
            setPlayerTurn(playerWinnerRoundTwo);
        }
    } else { // faz algo pq alguem ganhou
        if (team0Winner) {
            qDebug() << "Team0 win this match!";
            //restartGame();
        }
        if (team1Winner) {
            qDebug() << "Team1 win this match!";
            //restartGame();
        }
    }
    nextRound();
}
Esempio n. 13
0
void GameServer::gameStart(void)
{
	Tasks::getInstance()->addTask(GameStartTask::create(MonitorType::MonitorWaitNext));
	nextRound();
}