Ejemplo n.º 1
0
int TicTacToe::play(bool _xTurn, int pos) {
	bool win;
	
	if(!isRightTurn(_xTurn)) {
		return INVALID_TURN;
	}
	
	if(!isValidMove(pos)) {
		return INVALID_MOVE;
	}
	
	placeMove(_xTurn,pos);
	
	plotGame();
	
	win = won(_xTurn);
	xTurn = !xTurn;
	
	if(win) {
		resetGame();
		return WIN;
	}
	else if(isFull()){
		resetGame();
		return OVER;
	}
	else {
		return NO_WIN;
	}
}
Ejemplo n.º 2
0
// glut menu callback
void demo_menu(int id)
{
    switch(id)
    {
        case 1:
        pauseBool = false;
        if(!gameStarted)
        {
        start = std::chrono::high_resolution_clock::now();
        gameStarted = true;
        }
        break;

        case 2:
        pauseBool = true;
        break;

        case 3:
        resetGame();
        break;

        case 4:
        resetGame();
        scoreOne = 0;
        scoreTwo = 0;
        break;

        case 5:
        exit(0);
        break; 
    }
    glutPostRedisplay();
}
Ejemplo n.º 3
0
void		SdlDisplay::sdlMenuAction(bool multi)
{
    if (index == 1)
    {
        freeall = true;
        gameover = true;
        resetGame();
        sdlLauncher(false);
    }
    else if (index == 2)
    {
        freeall = true;
        gameover = true;
        resetGame();
        sdlLauncher(true);
    }
    else if (index == 3)
    {
        freeall = true;
        gameover = true;
        resetGame();
        if (multi)
            sdlLauncher(true);
        else
            sdlLauncher(false);
    }
}
Ejemplo n.º 4
0
Result game(int seed) {
    Result result = {LOSE, 0};
    srand(seed);
    Block blocks[size*size];
    int blocksLeft = 0;
    resetGame(blocks, &blocksLeft, &result);
    int index = 0;
    int spawn = FALSE;
    int quit = FALSE;
    while (!quit) {
        if (KEY_DOWN_NOW(BUTTON_UP)) {
            if (moveBlocks(blocks, UP, &result.score, &blocksLeft, &result.outcome) && blocksLeft) {
                spawn = TRUE;
            }
            while (KEY_DOWN_NOW(BUTTON_UP));
        }
        if (KEY_DOWN_NOW(BUTTON_DOWN)) {
            if (moveBlocks(blocks, DOWN, &result.score, &blocksLeft, &result.outcome) && blocksLeft) {
                spawn = TRUE;
            }
            while (KEY_DOWN_NOW(BUTTON_DOWN));
        }
        if (KEY_DOWN_NOW(BUTTON_LEFT)) {
            if (moveBlocks(blocks, LEFT, &result.score, &blocksLeft, &result.outcome) && blocksLeft) {
                spawn = TRUE;
            }
            while (KEY_DOWN_NOW(BUTTON_LEFT));
        }
        if (KEY_DOWN_NOW(BUTTON_RIGHT)) {
            if (moveBlocks(blocks, RIGHT, &result.score, &blocksLeft, &result.outcome) && blocksLeft) {
                spawn = TRUE;
            }
            while (KEY_DOWN_NOW(BUTTON_RIGHT));
        }
        if (spawn) {
            index = spawnBlock(blocks, blocksLeft--);
            result.score += 1<<blocks[index].num;
            waitForVblank();
            drawBlock(blocks, index);
            updateScoreDisplay(result.score);
            quit = !hasMoves(blocks);
            spawn = FALSE;
        }
        if (KEY_DOWN_NOW(BUTTON_B)) {
            quit = TRUE;
            while (KEY_DOWN_NOW(BUTTON_B));
        }
        if (KEY_DOWN_NOW(BUTTON_SELECT)) {
            resetGame(blocks, &blocksLeft, &result);
            while (KEY_DOWN_NOW(BUTTON_SELECT));
        }
    }
    //put a while loop here to check if game ends properly
    return result;
}
Ejemplo n.º 5
0
void MenuServeur::processEvents()
{
  sf::Event event;
  while (mWindow.pollEvent(event))
  {
      if (event.type==sf::Event::KeyPressed)
     {
      switch(event.key.code)
      {
        case sf::Keyboard::Escape:
             mWindow.close();
             break;
        case sf::Keyboard::Return: //retour menu
             break;
        case sf::Keyboard::R:
              resetGame();

        break;
     }}
    switch (event.type)
    {
    case sf::Event::MouseButtonPressed:
      if (event.mouseButton.button == sf::Mouse::Left)
      {
        Square square(squareClicked(event.mouseButton.x,event.mouseButton.y));
        if (square != UNKNOWN)
        {
          if (mBoard.addMove(mPlayer,square))
          {
            addSprite(square);
            updateOutcome();
            displayOutcome();
            if (mOutcome == UNFINISHED)
              swapPlayer();
            else
               // Xwin();
              resetGame();

          }
        }
      }
      break;

    case sf::Event::Closed:
      mWindow.close();
      break;
    }
  }
}
Ejemplo n.º 6
0
void Battleship::play() {
	cout << endl << endl << "~~~~~~ WELCOME TO BATTLESHIPS ~~~~~~" << endl;
	bool gameOver = false;

	while (!gameOver) {
		gameLoop();
		cout << endl << "Do you want to try again? (Y/N)" << endl;
		char tryAgain;
		cin >> tryAgain;

		if (tryAgain == 'Y') {
			resetGame();
			cout << endl << endl;
		}
		else if (tryAgain = 'N'){
			gameOver = true;
		}
		else {
			cout << "Your input was not understood. Ending game..." << endl;
			gameOver = true;
		}
	}

	cout << endl << "~~~~~~~ GAME OVER ~~~~~~~" << endl << endl;
}
Ejemplo n.º 7
0
void resetGameLoadMapAddActors( GameModel & game, PathGraph & pathgraph, GameView & view, GameViewSound & sound, ActorControllerKeyboard * & keyboardController, std::map< std::string, ActorControllerAI * > & aiControllers, std::map< std::string, float > & globalVariables, float gametime, const std::string & filename ) {
	// delete ai controllers
	for( std::map< std::string, ActorControllerAI * >::iterator iter = aiControllers.begin( ); iter != aiControllers.end( ); iter++ ) {
		delete iter->second;
	}
	aiControllers.clear( );

	// reset game
	resetGame( game, pathgraph, view, sound );
	setGameVars( game, globalVariables );

	// load map
	loadMap( game, pathgraph, view, sound, globalVariables, filename );
	view.initBrushTextures( );

	// add players
	//addPlayer( game, keyboardController, globalVariables, gametime, "Player" );
	addActor( game, keyboardController, globalVariables, gametime, "Player" );
	for( int i = 0; i < 3; i++ ) {
		aiControllers[ "AI-" + std::string( 1, (char)( i + 49 ) ) ] = new ActorControllerAI( &game, pathgraph );
		//addAI( game, aiControllers[ "AI-" + std::string( 1, (char)( i + 49 ) ) ], globalVariables, gametime, "AI-" + std::string( 1, (char)( i + 49 ) ) );
		addActor( game, aiControllers[ "AI-" + std::string( 1, (char)( i + 49 ) ) ], globalVariables, gametime, "AI-" + std::string( 1, (char)( i + 49 ) ) );
	}
	view.setCamera( &game.getActors( ).front( ) );
	sound.setCamera( &game.getActors( ).front( ) );
}
Ejemplo n.º 8
0
void myGame::updateGameState()
{
	timeInState+= frameTime;		// keeps track of the time spent in each state of the display

	if (gameStates == BEGIN && timeInState > 3.0)
	{
		gameStates = PLAY;
		timeInState = 0;
	}

	else if (gameStates == PLAY && dotsRemaining == 0)
	{
		gameStates = END;
		timeInState = 0;
	}

	else if (gameStates == END && timeInState > 3.0 ||
		 gameStates == END && input->isKeyDown(ENTER_KEY))
	{
		/*
		dotsRemaining = rows * cols ;
		for(int i=0;i<dots.getSize();i++){
			dots.getArray()[i]->setVisible(true);
			dots.getArray()[i]->setActive(true);
		}
		*/
		resetGame();
		player.setX(playerNS::X);
		player.setY(playerNS::Y);
		gameStates = BEGIN;
		timeInState = 0;
	}
}
Ejemplo n.º 9
0
void isLevelDone()
{
  int i, j;

  // Verify
  for (i=0; i!=LEVEL_SIDE; i++)
    for (j=0; j!=LEVEL_SIDE; j++)
      if (lvl.map[i][j].state == 1) return;

  // Increment the instructions counter
  for (i=0; i!=MATRIX_W; i++)
    for (j=0; j!=MATRIX_H; j++)
      if (game.func_matrix[i][j] > 0) game.instructions_count++;
  
  setFadeMode(&main_fade,FADE_IN,0);
  waitFadeDone();

  // This was the last level... outro time.
  if (nextLevel()) { game.state = OUTRO; return; }

  // Else, reset game state; this is intro time.
  resetGame();
  stopProgram();
  clearFuncMatrix();
  game.state = GAME_INTRO;
}
Ejemplo n.º 10
0
void mainloop(){
      int esc = 1;
      Stats* stats;
      stats = initGame();
      do{
            system("CLS");
            switch(esc){
                  case 0:
                        break;
                  case 1:
                        esc = menuPrincipal();
                        break;
                  case 11:
                        esc = menuNovoJogo(stats);
                        break;
                  case 111:
                        menuNovoJogador(stats);
                        esc /= 10;
                        break;
                  case 112:
                        seletorRodada(stats);
                        esc = novaPartida();
                        if (esc == 11) resetGame(stats);
                        break;
                  case 10:
                  case 110:
                        esc = 0;
                        break;
            };
      }while(esc!=0);
};
Ejemplo n.º 11
0
//--------------------------------------------------------------
void testApp::keyReleased(int key)
{
	//if the game is running
	if(!gameOver)
	{
		if(key=='w')
		{
			//move up
			player1.stopMoving();
		}
		if(key=='s')
		{
			//move down
			player1.stopMoving();
		}
		if(key==' ')
		{
			//fire
			player1.fire();
		}
	}
	//if the game over screen is up
	else
	{
		//reset the game when enter is pressed
		if(key==OF_KEY_RETURN)
		{
			resetGame();
		}
	}
}
Ejemplo n.º 12
0
void game::update(){
	if(meny->getShowMeny()){//if meny is on.
		meny->guiUpdate();//calls meny memeber function guiUpdate.
		resetGame(); // resets the game over and over.
	} else { //if meny is off.
		ball->movementOfBall(updateTime);//move the ball with updatetime clock.
		//Player pad movement.
		if(fPlayer->getLeft()){//if player pad should move left.
			fPlayer->moveLeft();//move player pad left.
		}
		if(fPlayer->getRight()){//if player pad should move right.
			fPlayer->moveRight();//move player pad right.
		}

		if(boxesIsEmpty()){ //vector with boxes is empty
			meny->winner(updateTime);//call winning text.
		}

		if(ball->checkIfDead()){//check if ball is dead(position under player pad).
			fPlayer->loseLife();//removes a extra life.
			if(fPlayer->getLife() >= 0){//if extra life is more/= to 0.
				delete ball;//delete old ball
				ball = new bounceBall();//alocate new ball.
			}else{
				meny->gameOver(updateTime);//show gameover text object.
			}
		}
		collition();//check if ball collide with something.
	} 
}
void Pacman::reset()
{
	m_player.Lives = 3;
	m_gameScore = 0;

	resetGame();
}
Ejemplo n.º 14
0
void updateScore(){
	int ballPositionX = 10.0*(modelB[0][3]);
	int leftWall = -130;
	int rightWall = 130;
	// Player 1 scores
	if (ballPositionX >= rightWall){
		score[0]++;
		std::cout<<"Player 1 scored!\n";
		std::cout<<"Score is "<<score[0]<<" : "<<score[1]<<"\n\n";
		resetGame();
	} // Player 2 scores
	else if (ballPositionX <= leftWall){
		score[1]++;
		std::cout<<"Player 2 scored!\n";
		std::cout<<"Score is "<<score[0]<<" : "<<score[1]<<"\n\n";
		resetGame();
	}		
}
Ejemplo n.º 15
0
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    
    if (!publicRelease){
        if (key == 'f'){
            setFood();
        }
        
        if (key == 'e'){
            endGame();
        }
        
        if (key == 'c'){
            captureScreen = !captureScreen;
            return;
        }
        
        if (key == 'v'){
            captureOneScreenshot = true;
        }
        
        if (key == 'p'){
            debugPause = !debugPause;
        }
        
        if (key == 'm'){
            debugMute = !debugMute;
        }
        
        if (key == 'r'){
            resetGame();
        }
    }
    
    snake.keyPressed(key);
    
    
    
    if (onTitle){
        resetGame();
        //onTitle = true; //kill me
    }
    
    
}
Ejemplo n.º 16
0
void main(void) {
  DisableInterrupts;
	initializations(); 		  			 		  		
	EnableInterrupts;
  
  turnOffLEDs();
  // reset game on startup
  resetGame();
  
  TC7 = 15000;            //set up TIM TC7 to generate 0.1 ms interrupt rate
  for(;;) {
    displayBoard();
    
    
    if (interuptFlag) {
       tickCounter++;
       ticksSinceLastEvolution++;  	
  
       if (ticksSinceLastEvolution >= TICKS_BETWEEN_EVOLUTIONS) {
         ticksSinceLastEvolution = 0;
         evolveFlag = 1;
       }  
    }
    
    if (evolveFlag) {
      evolveFlag = 0;
      evolve();
    }
    
    if (boardsAreSame == 1) {
      resetGame();
    }
  
    // check to see if the user would like to reset the game (presses right push button)
    if (rghtpb == 1) {
      rghtpb = 0;
      resetGame();
    }
    
  
    _FEED_COP(); /* feeds the watchdog timer */
  } /* loop forever */
  /* make sure that you never leave main */
}
Ejemplo n.º 17
0
start::start(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::start)
{
    ui->setupUi(this);
    resDialog=new result;
    Game=new game(this,resDialog);
    connect(resDialog,SIGNAL(reset()),this,SLOT(resetGame()));
    this->setCentralWidget(Game);
}
Ejemplo n.º 18
0
State onGameMain(Game* game) {
	/*IGNORE*/
	int choice = 0;
	char filename[255];
	printGameMenu(game);
	choice = getInput();
	/* 
	"0. Restart a new game"
	"1. Load from a old game"
	"2. Save log"
	"3. Save this game"
	"4. Allow redo [%s]"
	"5. Allow illegal move [%s]"
	"6. Select default opponent [%s]"
	"7. Select default difficulty"
	"8. Return to the game"
	"9. Exit"
	*/
	switch(choice) {
	case 0:
		resetGame(game);
		return NewGame;
	case 1:
		/*loadGame(game);
		*/return NewGame;
	case 2:
		printf("Enter the file name you want to save \n");
		scanf("%s", filename);
		saveLog(game, filename);
		break;
	case 3:
		/*saveGame(game);
		*/break;
	case 4:
		game->setting->allowRedo ^= 1;
		break;
	case 5:
		game->setting->allowIllegalMove ^= 1;
		break;
	case 6:
		selectOpponent(game);
		break;
	case 7:
		selectDifficulty(game);
		break;
	case 8:
		return TurnPlayer;
	case 9:
		return Exit;
	default:
		return GameMenu;
	}
	return GameMenu;
}
Ejemplo n.º 19
0
//---------------------------------------------------------------------------------
// Name: enter() 
//---------------------------------------------------------------------------------
void GameplayState::enter(App * app)
{
    initState();
    
    BATTLE_CITY->loadMap( getNextMapNum() );
    setMapFrame();

    resetGame();
    incTimesPlayed();
    
    APP_EVENT( GAME_STARTED );
}
Ejemplo n.º 20
0
void EmuSettings::resetButtonClicked()
	{
    if( settingsChanged )
    	{
		savecurrentSettings();
		emit( updateSettings(gpspsettings) );
		settingsChanged = false;
    	}
    
	if( romloaded )
		emit( resetGame() );
	}
Ejemplo n.º 21
0
void World::onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event *event) {
    switch (keyCode) {
    case EventKeyboard::KeyCode::KEY_D:
        _debugMode = !_debugMode;
        break;
    case EventKeyboard::KeyCode::KEY_R:
        resetGame();
        break;
    default:
        Layer::onKeyReleased(keyCode, event);
    }
}
void StatePlaying::initiate()
{
  float farClippingPlane = 2000.0f;

  // Set far clipping plane
  gRenderer.setNearFarClippingPlanes(1.0f,farClippingPlane);    

  m_objects = new Ned3DObjectManager();	
	m_objects->setNumberOfDeadFrames(2);
	m_tetherCamera = new TetherCamera(m_objects);
	
  // Create terrain
  terrain = new Terrain(8,"terrain.xml"); //powers of two for terrain size
  m_objects->spawnTerrain(terrain);
  
  // Load models
  m_objects->setModelManager(gModelManager);
  gModelManager.importXml("models.xml");

  // Loads game objects like the crows, plane, and silo
	resetGame();
  
  // set fog
  gRenderer.setFogEnable(true);
  gRenderer.setFogDistance(farClippingPlane - 1000.0f,farClippingPlane);
  gRenderer.setFogColor(MAKE_ARGB(0,60,180,254));

  // set lights
  gRenderer.setAmbientLightColor(MAKE_ARGB(255,100,100,100));
  gRenderer.setDirectionalLightColor(0XFFFFFFFF);
  Vector3 dir = Vector3(5.0f,-5.0f, 6.0f);
  dir.normalize();
  gRenderer.setDirectionalLightVector(dir);
  	
  // Create water now that we know what camera to use
  float fov = degToRad(gGame.m_currentCam->fov);
  water = new Water(fov, farClippingPlane, "water.xml");
  
  m_objects->spawnWater(water);

	// aquire sounds  
  gSoundManager.setDopplerUnit(1.0f/3.0f); // sound factors
  // get windmill sound
  m_windmillSound = gSoundManager.requestSoundHandle("windmill2.wav");
  m_windmillSoundInstance = gSoundManager.requestInstance(m_windmillSound);  

  // add console commands  
  gConsole.addFunction("camerafollow","",consoleSetFollowCamera);
  gConsole.addFunction("cameratarget","s",consoleSetCameraTarget);
  gConsole.addFunction("godmode","b",consoleGodMode);

}
Ejemplo n.º 23
0
void fetchUserInput()
{

	Block orgBlock = currentBlock;

	if (gameState == 0)
	{
		switch (getch())
		{
			case KEY_LEFT:
				moveLeft();
				break;

			case KEY_RIGHT:
				moveRight();
				break;

			case KEY_UP:
				rotateBlock();
				break;

			case KEY_DOWN:
				moveDown();
				break;

			case 'p':
				gameState = 1;
				break;
		}
	} else {
		switch (getch())
		{
			case 'p':
				if (gameState == 1)
				{
					gameState = 0;
				}
				break;
			case 'r':
				resetGame();
				break;
			case 'q':
				inGame = 0;
				break;
		}
	}

	if (isCollision())
	{
		currentBlock = orgBlock;
	}
}
Ejemplo n.º 24
0
void game_init(struct game_t* g)
{
    UT_icd tap_state_icd =
    {
        sizeof(struct tap_state),
        NULL, // Initializer
        NULL, // Copier
        NULL  // Destructor
    };
    utringbuffer_new(g->blockHistory, GAME_STATE_HISTORY_LENGTH, &tap_state_icd);

    resetGame(g);
}
Ejemplo n.º 25
0
void PongGame::runEndState(){
	const Uint8* keys = GameEngine::getKeyState();

	GameEngine::setColor(0, 0, 0);
	GameEngine::drawText("GAME   OVER!", 170, 400, 1.0f);
	GameEngine::drawText(winner + " Wins!", 210, 290, 0.75f);
	GameEngine::drawText("Press BACK to Restart", 200, 200, 0.5f);

	if(GameEngine::GAMEPAD1_BACK || GameEngine::GAMEPAD2_BACK || keys[GameEngine::BACKSPACE_KEY]){
		resetGame();
		currentState = COUNTDOWN_STATE;
	}
}
Ejemplo n.º 26
0
void MainWindow::showResult()
{
    this->hide();
    results->show();
    results->showScore(score);
    results->showText(pig_count, score, 6-bird_count);
    if(results->exec())
    {
        this->show();
        results->close();
        resetGame();
    }
}
Ejemplo n.º 27
0
Common::Error CGEEngine::loadGameState(int slot) {
	// Clear current game activity
	sceneDown();
	resetGame();

	// Load the game
	loadGame(slot, NULL);
	_commandHandler->addCommand(kCmdLevel, -1, _oldLev, &_sceneLight);
	_sceneLight->gotoxy(kSceneX + ((_now - 1) % kSceneNx) * kSceneDx + kSceneSX,
	                  kSceneY + ((_now - 1) / kSceneNx) * kSceneDy + kSceneSY);
	sceneUp();

	return Common::kNoError;
}
Ejemplo n.º 28
0
void replay() {
    printf("\nDo you want to continue ? (y/n)\n");
    char answer;
    //	clearInputBuffer();
    scanf("%c", &answer);
    if(answer == 'n')
        game.player.wantToPlay = 0;
    else if(game.player.balance <= 0){
    	printf("Sorry dude, your out of money !\n");
        game.player.wantToPlay = 0;
    }
    resetGame();
    clearScreen();
}
Ejemplo n.º 29
0
void GameScene::GameEnd()
{
    popBall(_ballArray.front(), _ballArray.begin());

    if (_ballArray.empty()) {
        unschedule(schedule_selector(GameScene::GameEnd));
        CCScene* lossScene = LossScene::scene(_score);
        //        CCDirector::sharedDirector()->replaceScene(
        //  CCTransitionFade::create(0.5, lossScene));
        CCDirector::sharedDirector()->replaceScene(lossScene);
        CCDirector::sharedDirector()->retain();
        resetGame();
    }
}
Ejemplo n.º 30
0
void input(SDL_Window* screen ){

	SDL_Event event;

	while (SDL_PollEvent(&event)){//Handling the keyboard
		switch (event.type){
		case SDL_QUIT:exit(0);break;
		case SDL_KEYDOWN:
			switch(event.key.keysym.sym){
			case SDLK_ESCAPE:exit(0);
			case SDLK_w://paddle 1 up;
				if (modelP1[1][3] < 7.0) {
					modelP1 = modelP1 * Translate(0.0,1.0,0.0);
				}
				//std::cout<<"modelP1="<<std::endl;
				//printMat4(modelP1);
				//std::cout<<std::endl;
				break;
			case SDLK_s://paddle 1 down;
				if (modelP1[1][3] > -7.0) {
					modelP1 = modelP1 * Translate(0.0,-1.0,0.0);
				}
				//std::cout<<"modelP1="<<std::endl;
				//printMat4(modelP1);
				//std::cout<<std::endl;
				break;
			case SDLK_i://paddle 2 up
				if (modelP2[1][3] < 7.0) {
					modelP2 = modelP2 * Translate(0.0,1.0,0.0);
				}
				break;
			case SDLK_k://paddle 2 down
				if (modelP2[1][3] > -7.0) {
					modelP2 = modelP2 * Translate(0.0,-1.0,0.0);
				}
			break;
			case SDLK_r://new game
				std::cout<<"*new game*\n";
				score[0]=0;
				score[1]=0;
				modelP1 = modelP2 = identity();
				modelP1 = modelP1 * Translate(-10.0,0.0,0.0);
				modelP2 = modelP2 * Translate(10.0,0.0,0.0);
				resetGame();
				break;
			}
		}
	}
}