コード例 #1
0
ファイル: Scene.cpp プロジェクト: Wrakor/LAIG
void Scene::changeGameEnvironment(int gameEnvironment)
{
	this->gameEnvironment = gameEnvironment;
	if (gameEnvironment == 1)
	{
		playerOneName = "White";
		playerTwoName = "Black";
		Piece::playerOnePiece = Piece::white;
		Piece::playerTwoPiece = Piece::black;
		nodes["tabuleiro"]->appearance = appearances[0];
	}
	else if (gameEnvironment == 2)
	{
		playerOneName = "Red";
		playerTwoName = "White";
		Piece::playerOnePiece = Piece::red;
		Piece::playerTwoPiece = Piece::white;
		nodes["tabuleiro"]->appearance = appearances[1];
	}

	if (gameStarted)
	{
		updateGameMessage();
		checkVictory();
	}
}
コード例 #2
0
ファイル: MainGame.cpp プロジェクト: Skitzafreak/ZombieGame
void MainGame::gameLoop() {
    
    Bengine::FpsLimiter fpsLimiter;
    fpsLimiter.setMaxFPS(60.0f);

    // Main loop
    while (_gameState == GameState::PLAY) {
        fpsLimiter.begin();

        checkVictory();
		if (_timeElapsed > 100 && !_soldiersSpawned)
			initSoldiers();
		else
			_timeElapsed++;

        processInput();
       
        updateAgents();

        updateBullets();

        _camera.setPosition(_player->getPosition());

        _camera.update();

        drawGame();

        _fps = fpsLimiter.end();
    }
}
コード例 #3
0
ファイル: Scene.cpp プロジェクト: Wrakor/LAIG
void Scene::computerPlay()
{
	if (!computerPlaying)
	{
		player = !player;
		updateGameMessage();
		board->computerPlacePiece(socket);
		checkVictory();
		if (gameState == GAMEOVER) //if someone won, dont do anything else
			return;
		computerPlaying = true; //wait for animation to end to do rotation
		return;
	}
	else
	{
		board->computerRotateQuadrant(socket);
		computerPlaying = false;
		checkVictory();
		if (gameState != GAMEOVER)
			switchPlayer();
	}
}
コード例 #4
0
ファイル: Scene.cpp プロジェクト: Wrakor/LAIG
void Scene::placePiece(unsigned int pos)
{
	if (gameState == PLACEPIECE)
	{
		board->previousBoard = board->boardRepresentation; //save previous board
		((Interface *)iface)->undo->disable(); //only undo on the end of each play
		board->boardRepresentation[pos].place(player, pos);
		std::array<unsigned int, 4> play = {pos, 0, 0, player};
		board->playHistory.push_back(play);
		gameState = ROTATE;
		checkVictory();
	}
}
コード例 #5
0
ファイル: MainGame.cpp プロジェクト: nerososft/zombieWar
void MainGame::gameLoop(){

	NeroEngine::FpsLimter _fpsLimter;
	_fpsLimter.setMaxFps(60.0f);

	const float CAMERA_SCALA = 2.0f;
	_camera.setScale(CAMERA_SCALA);
	
	const int  MAX_PHYSISC_STEPS = 1.0f;
	const float DESIREO_FPS = 60.0f;
	const float MS_PER_SECOND = 1000;
	const float MAX_DETLA_TIME = 1.0f;
	const float DESIREO_FRAMETIME = MS_PER_SECOND / DESIREO_FPS;
	float previousTicks = SDL_GetTicks();
	while (_gameState==GameState::PLAY){
		_fpsLimter.begin();
		float newTicks = SDL_GetTicks();
		float frameTime = newTicks - previousTicks;
		previousTicks = newTicks;

		float totalDeltaTime = frameTime / DESIREO_FRAMETIME;

		checkVictory();

		processInput();
		int i = 0;
		while (totalDeltaTime>=0.0f && i<MAX_PHYSISC_STEPS)
		{
			_deltaTime = 1.0f;// std::min(totalDeltaTime, MAX_DETLA_TIME);
			updateAgent(_deltaTime);
			updateBullet(_deltaTime);
			
			//_miniMap.update([=](std::vector<Zombie*> zombies, std::vector<Human*> humans)->void{
				
			//});

			totalDeltaTime += _deltaTime;
			i++;
		}
		
		_particleEngine.update(_deltaTime);

		_camera.setPosition(_player->getAgentPos());

		_camera.update();
		
		drawGame();

		_fps = _fpsLimter.end();
	}
}
コード例 #6
0
ファイル: Scene.cpp プロジェクト: Wrakor/LAIG
void Scene::rotateQuadrant(int quadrant, int direction)
{
	if (gameState == ROTATE)
	{
		board->playHistory.back().at(1) = quadrant;
		board->playHistory.back().at(2) = direction;
		board->rotateQuadrant(socket, quadrant, direction);
		checkVictory();
		if (gameState != GAMEOVER)
		{
			if (gameMode == PVC)
				computerPlay();
			else
				switchPlayer();
		}
	}
}
コード例 #7
0
void MazeSequential::main()
{
    ++m_iteration;
        
    // Delete blue cell from matrix
    m_matrix->data[m_pos] = 0;
    
    // Decide move
    // (I wish I had this done!!)
    
    performTestMove();

    // Add blue cell to matrix
    m_matrix->data[m_pos] = 1;
    
    // Run one step of GoL, with blue cell included
    step();
        
    // Check win condition
    m_won = checkVictory(m_pos);
}
コード例 #8
0
ファイル: Puzzle.cpp プロジェクト: OtemPsych/Slide-Puzzle
// Public Method(s)
	// Update
void Puzzle::update(sf::Time dt)
{
	checkVictory();
}
コード例 #9
0
ファイル: multiPlayer.cpp プロジェクト: areriff/Tic-Tac-Toe
//main game loop that get the parameter from multiplayer() above.
void gameLoop(std::pair < unsigned int, std::string> &result,
			  const std::string &playerOne, 
			  const std::string &playerTwo,
			  unsigned int &playerOneScore,
			  unsigned int &playerTwoScore) {
	bool play = true;
	auto gameBoard = initBoard();
	char turn = '1';
	while ( play ) {
		ClearScreen();
		displayBoard(gameBoard,playerOneScore,playerTwoScore,turn);
		if ( turn == '1' ) {
			pickSquare(gameBoard, '1', playerOne);	//user enter move and modify the current gameBoard.
			if ( checkVictory(gameBoard) == true ) {
				playerOneScore++;	
				ClearScreen();
				displayBoard(gameBoard, playerOneScore, playerTwoScore, turn); //display current gameBoard
				std::cout << playerOne << " wins!" << std::endl;
				auto playAgainTemp = playAgain(); //use as temporary value to hold a boolean whether player wants to play again
				if ( playAgainTemp == true ) {
					std::cout << "Swapping turns..." << std::endl;
					delay(1);
					gameBoard = initBoard(); //create a new blank board
					ClearScreen();
					swapTurn(turn); //the other player will start the new game
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
				} else if ( playAgainTemp == false ) {	//if the player decides not to continue game after winning,
					result.first = playerOneScore;			//the game will end by returning the current score at the end
					result.second = playerOne;		//of current game to result (pair) for further processing (see
					play = false;						//multiplayer() function above).
				}
			
			} else if ( checkVictory(gameBoard) == false ) {
				if ( checkDraw(gameBoard) == true ) {
					ClearScreen();
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
					std::cout << "The game is drawn." << std::endl;
					auto playAgainTemp = playAgain();
					if ( playAgainTemp == true ) {
						std::cout << "Swapping turns..." << std::endl;
						delay(1);
						gameBoard = initBoard();
						ClearScreen();
						swapTurn(turn);
						displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
					} else if ( playAgainTemp == false ) {
						play = false;	//when draw, no high score will be recorded
					}
				} else if ( checkDraw(gameBoard) == false ) {
					swapTurn(turn);
					ClearScreen();
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn); // continue to player 2
				}
			}
		}
		if ( turn == '2' ) {							//player 2 loop are exactly the same as player 1(except 
			pickSquare(gameBoard, '2', playerTwo);		//for the parameters that are being passed, which are
			if ( checkVictory(gameBoard) == true ) {	//unique for player 2 for identification purposes
				playerTwoScore++;
				ClearScreen();
				displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
				std::cout << playerTwo << " wins!" << std::endl;
				auto playAgainTemp = playAgain();
				if (playAgainTemp == true ) {
					std::cout << "Swapping turns..." << std::endl;
					delay(1);
					gameBoard = initBoard();
					ClearScreen();
					swapTurn(turn);
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
				} else if (playAgainTemp == false ) {
					result.first = playerTwoScore;
					result.second = playerTwo;
					play = false;
				}

			} else if ( checkVictory(gameBoard) == false ) {
				if ( checkDraw(gameBoard) == true ) {
					ClearScreen();
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
					std::cout << "The game is drawn." << std::endl;
					auto playAgainTemp = playAgain();
					if (playAgainTemp == true ) {
						std::cout << "Swapping turns..." << std::endl;
						delay(1);
						gameBoard = initBoard();
						ClearScreen();
						swapTurn(turn);
						displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
					} else if (playAgainTemp == false ) {
						play = false;
					}
				} else if ( checkDraw(gameBoard) == false ) {
					swapTurn(turn);
					ClearScreen();
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
				}
			}
		}
	}
}
コード例 #10
0
ファイル: game.cpp プロジェクト: justia02/PSI-team-3
void game::passTurn(bool giveUp) {
	// in the game state both player's units will be contained --> allocate memory for all units
	
	bool pl1turn = gameState->getPlayer1Turn();
	gameState = new GameStateDTO(localPlayer->getUnits()->size() + opposingPlayer->getUnits()->size());
	gameState->setGiveUp(giveUp);
	if (localPlayer->getPlayer1()) gameState->setPlayer1Turn(false);
	if (!localPlayer->getPlayer1()) gameState->setPlayer1Turn(true);
	gameState->setVictory(checkVictory());

	BaseUnitDTO* units = new BaseUnitDTO[localPlayer->getUnits()->size() + opposingPlayer->getUnits()->size()];
	int i = 0;


	m->setTurnText("It is your opponents turn");
	m->setWaitText(true);
	//m->setTurnTextColor(SColor(0, 255, 0, 0));
	
	// read units of this player

	for(std::vector<BaseUnit*>::iterator it = localPlayer->getUnits()->begin(); it != localPlayer->getUnits()->end(); ++it) {
		// create a DTO for each of them
		BaseUnitDTO tmp = BaseUnitDTO();
		tmp.setId((*it)->id);
		tmp.setX((*it)->position.X);
		tmp.setY((*it)->position.Y);
		tmp.setZ((*it)->position.Z);
		tmp.setPlayer(true);
		tmp.setHealth((*it)->health);
		std::cout<<"PASS TURN!";
		// put unitDTOs in list that is given to gamestateDTO
		units[i] = tmp;
		i++;
	}

	// read units of opponent
	for(std::vector<BaseUnit*>::iterator it = opposingPlayer->getUnits()->begin(); it != opposingPlayer->getUnits()->end(); ++it) {
		// create a DTO for each of them
		BaseUnitDTO tmp = BaseUnitDTO();
		tmp.setId((*it)->id);
		tmp.setX((*it)->position.X);
		tmp.setY((*it)->position.Y);
		tmp.setZ((*it)->position.Z);
		tmp.setPlayer(false);
		tmp.setHealth((*it)->health);
		// put unitDTOs in list that is given to gamestateDTO
		units[i] = tmp;
		i++;
	}

	// put units in the game state DTO
	gameState->setUnits(units);
	// serialize the gamestateDTO (unitDTOs should be serialized along with them...)
	char* buffer = gameState->serializeGameState();
	if (gameState->getVictory()) {
		device->getGUIEnvironment()->addMessageBox(L"YOU WIN!", L"Congratulations, you win the game!", true, EMBF_OK);
		endOfGame = true;
	}
	if (gameState->getGiveUp()) {
		device->getGUIEnvironment()->addMessageBox(L"YOU SURRENDER!", L"Your opponent won the game. You surrendered.", true, EMBF_OK);
		endOfGame = true;
	}

	std::cout<<"FLAGS IN GAMESTATE \n";
	std::cout<<"Give up: ";
	std::cout<<gameState->getGiveUp();
	std::cout<<"\n";
	std::cout<<"Player 1 Turn: ";
	std::cout<<gameState->getPlayer1Turn();
	std::cout<<"\n";
	std::cout<<"Victory: ";
	std::cout<<gameState->getVictory();
	std::cout<<"\n";

	try {
		networkUtilities->setBuffer(buffer);
		networkUtilities->sendData();
		if (! gameState->getGiveUp()) {
			pthread_create(&thread, NULL, updateGameState, this);
		} else {
			endOfGame = true;
		}
	}
	catch(NonRealtimeNetworkingException e) {
		device->getGUIEnvironment()->addMessageBox(L"Oops an Error", L"Something went wrong, probably connection lost", true, EMBF_OK);
		endOfGame = true;
	}

	try {
		if (gameState->getVictory()) networkUtilities->closeConnection();
	} catch (NonRealtimeNetworkingException e) {
		// just catch that shit already
	}
}
コード例 #11
0
ファイル: MainGame.cpp プロジェクト: fluier/ZombieGame
void MainGame::gameLoop() {

	// Some helpful constants.
	const float DESIRED_FPS = 60.0f; // FPS the game is designed to run at
	const int MAX_PHYSICS_STEPS = 6; // Max number of physics steps per frame
	const float MS_PER_SECOND = 1000; // Number of milliseconds in a second
	const float DESIRED_FRAMETIME = MS_PER_SECOND / DESIRED_FPS; // The desired frame time per frame
	const float MAX_DELTA_TIME = 1.0f; // Maximum size of deltaTime

	// Used to cap the FPS
	Adina::FpsLimiter fpsLimiter;
	fpsLimiter.setMaxtFPS(60000.0f);

	// Zoom out the camera by 4x
	const float CAMERA_SCALE = 1.0f / 3.0f;
	m_camera.setScaleFactor(CAMERA_SCALE);

	// Start our previousTicks variable
	float previousTicks = SDL_GetTicks();

	// Main loop
	while (m_gameState == GameState::PLAY) {
		fpsLimiter.begin();

		// Calculate the frameTime in milliseconds
		float newTicks = SDL_GetTicks();
		float frameTime = newTicks - previousTicks;
		previousTicks = newTicks; // Store newTicks in previousTicks so we can use it next frame
		// Get the total delta time
		float totalDeltaTime = frameTime / DESIRED_FRAMETIME;

		checkVictory();

		m_inputManager.update();

		processInput();

		int i = 0; // This counter makes sure we don't spiral to death!
		// Loop while we still have steps to process.
		while (totalDeltaTime > 0.0f && i < MAX_PHYSICS_STEPS) {
			// The deltaTime should be the the smaller of the totalDeltaTime and MAX_DELTA_TIME
			float deltaTime = std::min(totalDeltaTime, MAX_DELTA_TIME);
			// Update all physics here and pass in deltaTime
			updateAgents(deltaTime);
			updateBullets(deltaTime);
			m_particleEngine2D.update(deltaTime);
			// Since we just took a step that is length deltaTime, subtract from totalDeltaTime
			totalDeltaTime -= deltaTime;
			// Increment our frame counter so we can limit steps to MAX_PHYSICS_STEPS
			i++;
		}

		// Make sure the camera is bound to the player position
		m_camera.setPosition(m_player->getPosition());
		m_camera.update();
		m_hudCamera.update();

		drawGame();

		// End the frame, limit the FPS, and get the current FPS.
		m_fps = fpsLimiter.end();
		//std::cout << m_fps << std::endl;
	}
}