示例#1
0
文件: Worms.c 项目: ndelanou/PCWorms
/**
* \fn void updateGameWorms(Jeu* jeu, Worms** wormsTab, SDL_Texture* pTextureDisplay, SDL_Rect* pCamera)
* \brief Update worms display, manages overlay and physics for all worms.
*
* \returns void
*/
void updateGameWorms(Jeu* jeu, Worms** wormsTab, SDL_Texture* pTextureDisplay, SDL_Rect* pCamera)
{
	int indexWorms;

	updateTeamLife(jeu->equipes);
	isGameEnd(jeu);

	if (!globalVar.gameEnd && !globalInput->menu && !globalInput->weaponTab)
	{
		if (wormsTab[globalVar.indexWormsTab]->vie <= 0)
		{
			callNextWorms(wormsTab);
		}
		globalInput->deplacement = 0;
		for (indexWorms = 0; indexWorms < globalVar.nbWormsTotal; indexWorms++)
		{
			if (indexWorms == globalVar.indexWormsTab || wormsTab[indexWorms]->wormsObject->reactToBomb == 1
				|| !testGround(jeu->pMapTerrain->collisionMapSurface, wormsTab[indexWorms]->wormsObject->objectSurface, 1))
			{
				if (wormsTab[indexWorms]->vie > 0
					|| (wormsTab[indexWorms]->vie == 0 && !testGround(jeu->pMapTerrain->collisionMapSurface, wormsTab[indexWorms]->wormsObject->objectSurface, 2)))
				{
					KaamWormsMotionManagement(wormsTab[indexWorms], jeu->pMapTerrain->collisionMapSurface);
				}
				if (deathByLimitMap(wormsTab[indexWorms], jeu->pMapTerrain->collisionMapSurface))
					resetInputs();
			}
			if (globalInput->deplacement || globalInput->raffraichissement)
			{
				updateTextSurfaceWormsTab(wormsTab);	//MAJ de la position du texte + Surface Vie	
				displayWorms(wormsTab[indexWorms], 1);
				if (globalVar.nbWormsTotal > 1)
					wormsOverlay(wormsTab);
				globalInput->raffraichissement = 1;
			}
			/*if (wormsTab[indexWorms]->vie > 0 && (!wormsTab[indexWorms]->wormsObject->startMotion || !wormsTab[indexWorms]->wormsObject->falling))
			randomAnimationWorms(wormsTab[indexWorms], jeu->pMapTerrain->collisionMapSurface);*/
		}
		updateHUD(wormsTab);
		if (wormsTab[globalVar.indexWormsTab]->vie > 0 && !globalInput->grenade)
			weaponManagement(jeu->pMapTerrain, pTextureDisplay, wormsTab, globalInput->weaponIndex, pCamera);
		if (globalInput->grenade && !globalInput->arme)
			grenadeManagement(jeu->pMapTerrain, pTextureDisplay, wormsTab, pCamera);
	}
}
示例#2
0
void Algorythm::makeMove(MoveDirection direction)
{
    std::vector< std::vector <CellMovementInfo > > for_drawer;
    int64_t old_score = _score;



    //move
    _direction = direction;
    for(int y=0; y<Cell::N; ++y)
    {
        int empty = 0;
        _info.clear();

        for(int x=0; x<Cell::N; ++x)
        {
            //replace coordinates in deppend  on direction
            int x_cur = x;
            int y_cur = y;

            if(direction == MoveDirection::Right || direction == MoveDirection::Up)
                x_cur = Cell::N - x - 1;

            if(direction == MoveDirection::Down || direction == MoveDirection::Up)
            {
                std::swap(x_cur, y_cur);
            }
            Cell curr_cell = _cells.getCell(x_cur,y_cur);

            if(curr_cell.isEmpty())
                ++ empty;
            else
            {
                processOneCell(x_cur, y_cur, empty);
            }
        }

        if(!_info.empty())
            for_drawer.push_back(_info);
    }

    //if there is no changes after the move do not add new letter(do not continue the algorythm)
    if(for_drawer.empty())
    {
        ADStatistics::logEvent("[Game] Move no change");
        previousActionFinished();
        return;
    }

    ADStatistics::logEvent("[Game] Move");

    //add a new letter
    Cell new_letter = addLetter();

    sendPackagetForDrawer(for_drawer, new_letter);
    //sendScores(for_drawer);

    //look - is there next move, if no - send signal to table - game end
    if(isGameEnd())
    {
        emit signalGameEnd();
    }

    //make unmerged all cells
    unMergeCells();

    //for debug
    logTable();

    //send scores
    if(old_score != _score)
    {
        emit signalScoreChanged(_score);
    }

    //send signal table is changed
    emit signalTableChanged(_cells);
}
示例#3
0
void Game::start( Result *result){
    //各プレイヤーの順位が決定するまでゲームを行う
    COUT<<"start"<<endl;
    
    if( players.isInequality() ){//身分差があるなら
        changeCardsUEC( result );//カードの交換
    }
    
    players.setCardsNum();//プレイヤーのカード枚数を確認する
    
    //最初のプレイヤーIDをturnに保存する
    players.turn = players.convIDtoSekiNum(whoHave(2, 1));//ダイヤの3を持つものが最初のターンである
    
    while( !isGameEnd() ){//試合が存続中である(順位がすべて決していない)

        {//各プレイヤの手札を作り、送る
            int sendTefuda[config.PLAYER_NUM][8][15]={{0}};
            makeTefuda815( sendTefuda );
            for(int i=0; i<config.PLAYER_NUM; i++){
                send815( sendTefuda[i], players.id[i].sockfd );
            }
            COUT<<"send hand"<<endl;
            PRINT815( sendTefuda[players.turnId()] );
        }
        int data[8][15]={{0}};
        recv815(data, players.id[players.turnId()].sockfd);//現在のターンのプレイヤから提出カードを受け取る
        
        #ifdef DEBUGMODE
        //デバグ用出力
        table.print();
        players.print();
        COUT<<"get"<<endl;
        PRINT815(data);
        #endif
        
        //提出されたデータの解析
        Yaku yaku;//受け取ったデータの変換先
        int num = 0;//返信用番号
        if( conv815toYaku(&yaku, data) ){//815はそもそも"役"として解釈可能か?
            //解釈可能ならばyaku形式に変換されている
            if(isSubmittableYaku(yaku)){//提出可能な手か?
                if(yaku.isPass()){//パスと明示している(UEC標準ルールには存在しない)
                    if( config.PROTOCOL!=20070 ){
                        //20070以上のプロトコルならパス明示の返答をする。
                        num = 7;
                    }else{
                        //でなければ普通にパスである。
                        num = 8;
                    }
                }else{//提出可能な役
                    num = 9;
                }
            }else{//提出不可能な役
                //パスとして更新する
                yaku.demoPass();
                num = 8;
            }
        }else{//役として成り立っていない
            //cout << "unable to convert into Yaku!" << endl;
            //UECルールではパス(出せる手がない場合)もここにくるので出力させているときりがない
            yaku.demoPass();
            num = 8;
        }
        
        {//提出手役の記録
            Table bTable = table;//提出前の盤面
            vector<int> passArray, numArray;//パスしてるかの配列
            makePassArray( &passArray );//パスアレイを作る
            makeNumArray( &numArray );//枚数アレイを作る
            result->addAct( players.turnId(), bTable, passArray, numArray, yaku );//提出役の記録
            //result->print();
        }
        
        table.player_id = players.turnId();
        
        //以下、実際の盤面更新
        switch( num ){
        case 7:
            COUT << 7 << endl;
            send1( 7, players.id[players.turnId()].sockfd );//パスとしてパスをした
            pass();
            break;
        case 8:
            COUT << 8 << endl;
            send1( 8, players.id[players.turnId()].sockfd );//パスしたとみなした
            pass();
            break;
        case 9:
            COUT << 9 << endl;
            //役による盤面更新
            send1( 9, players.id[players.turnId()].sockfd );//提出できた
            update(yaku);//役情報による盤面の更新
            break;
        }
        
        {//更新された場札を送る
            int sendBafuda[config.PLAYER_NUM][8][15] = {{0}};
            makeBafuda815( sendBafuda );//加工
            for(int i=0; i<5; i++){
                send815( sendBafuda[i], players.id[i].sockfd );
            }
            COUT<<"send bafuda"<<endl;
            PRINT815( sendBafuda[players.turnId()] );
        }
            
        //場札を通知したら、次のプレイヤーに移るが、場が流れることもある
        bool pf  = true;//ぱふ
        switch(num){
        case 7:
        case 8:
            //パスした場合の次のプレイヤー
            if( isBaAlive() ){
                //まだ回せるなら回す
                players.nextTurn();
            }else{
                //場を流す
                purge();
            }
            break;
        case 9:
            //何かが通知されれば次のプレイヤーに移るが、場が流れることもある
            if( table.isOnset() ){
                purge();
                break;
            }
            players.nextTurn();
            break;
        }
            
        {
            //試合終了の判定
            if(isGameEnd()){
                //試合が終わってしまった
                result->mAgari = players.agari;//あがった順番をresultに保存する
                for(int i=0; i<players.agari.size(); i++){
                    players.id[players.agari[i]].mibun = i;
                }
                result->finish( players );
                break;//おさらば
            }else{
                //まだ終わってない
                for(int i=0; i<config.PLAYER_NUM; i++){
                    send1( 0, players.id[i].sockfd );
                }
            }
        }
        
    }//while
    
}
示例#4
0
文件: new 1.c 项目: ndelanou/PCWorms
int mainFenetre()
{
	unsigned int frame_max = SDL_GetTicks() + FRAME_RATE, temps = 0;
	Input * pInput = NULL; //structure contenant les informations relatives aux inputs clavier
	SDL_Texture * pTextureDisplay = NULL;	//Texture globale
	SDL_Rect camera = initRect(0, 0, 0, 0); // rect(x,y,w,h)
	Worms** wormsTab = NULL;
	char mapName[100];
	Jeu* jeu = NULL;

	//init SDL + fenetre + renderer
	if (initSWR())
	{
		//Initialisation des inputs
		pInput = initInput();
		if (pInput == NULL)
		{
			fprintf(logFile, "mainFenetre : FAILURE, initInput.\n");
			cleanUp(&pInput, &pTextureDisplay);
			return -1;
		}

		//InitSounds 
		if (!initSDLMixer()){
			fprintf(logFile, "initSDLMixer : FAILURE, init.\n");
			cleanUp(&pInput, &pTextureDisplay);
			return -1;
			
		}

		strcpy(mapName, cMAP);
		/*Initialisation SDL_TTF*/
		if (TTF_Init() == -1)
		{
			fprintf(logFile, "mainFenetre : FAILURE, initialisation de TTF_Init : %s.\n\n", TTF_GetError());
			cleanUp(&pInput, &pTextureDisplay);
			return -1;
		}

		if (mainMenu(pInput, mapName) < 0)
		{
			fprintf(logFile, "mainFenetre : FAILURE, mainMenu .\n\n");
			cleanUp(&pInput, &pTextureDisplay);
			return -1;
		}
		if (!pInput->quit)
		{
			if (mainInit() < 0)	//set le nombre d'équipe et le nombre de worms par équipe
			{
				fprintf(logFile, "mainInit : FAILURE.\n");
				cleanUp(&pInput, &pTextureDisplay);
				return -1;
			}

			/*Init game*/
			jeu = nouveauJeu(mapName);
			if (jeu == NULL)
			{
				fprintf(logFile, "nouveauJeu : FAILURE.\n");
				cleanUp(&pInput, &pTextureDisplay);
				return -1;
			}

			/*Init map*/
			if (initialisionTerrain(&jeu->pMapTerrain, "../assets/pictures/FondMap1.png", jeu->nomMap) < 0)
			{
				fprintf(logFile, "mainFenetre : FAILURE, initialisationTerrain.\n");
				cleanUp(&pInput, &pTextureDisplay);
				return -1;
			}

			/*Init global texture*/
			pTextureDisplay = my_createTextureFromSurface(jeu->pMapTerrain->globalMapSurface);
			if (pTextureDisplay == NULL)
			{
				fprintf(logFile, "mainFenetre : FAILURE, createGlobalTexture.\n");
				destroyMap(&jeu->pMapTerrain);
				cleanUp(&pInput, &pTextureDisplay);
				return -1;
			}

			/*Init sounds*/
			if (loadSounds(BipExplo, 0) < 0)
			{
				fprintf(logFile, "mainFenetre : FAILURE, loadSounds.\n");
				cleanUp(&pInput, &pTextureDisplay);
				return -1;
			}

			/*Init camera*/
			initCameras(jeu->pMapTerrain, &camera, NULL);

			/*Initialisation du tableau global de worms*/
			wormsTab = initWormsTab(jeu->equipes);
			if (wormsTab == NULL)
			{
				destroyMap(&jeu->pMapTerrain);
				cleanUp(&pInput, &pTextureDisplay);
				fprintf(logFile, "mainFenetre : FAILURE, allocating memory to the global array of worms pointer.\n\n");
				return -1;
			}

			/*Init Display*/
			initDisplay(jeu->pMapTerrain, pTextureDisplay);

			/*Initialisation des worms*/
			while (!KaamInitGame(wormsTab, jeu->pMapTerrain->collisionMapSurface))
				renderScreen(2, 0, jeu->pMapTerrain, 1, pTextureDisplay, &camera, NULL);
		}
		while (!(pInput->quit))
		{
			//Récupération des inputs
			getInput(pInput);

			//Gestion des inputs
			if (!gestInput(pInput, jeu->pMapTerrain, pTextureDisplay, &camera, wormsTab))
			{
				fprintf(logFile, "mainFenetre : FAILURE, gestInput.\n");
			}

			//Update de l'écran
			if (pInput->raffraichissement)
			{
				renderScreen(2, 0, jeu->pMapTerrain, 1, pTextureDisplay, &camera, NULL);
				pInput->raffraichissement = 0;
			}

			updateTeamLife(jeu->equipes);
			isGameEnd(jeu->equipes);

			//Gestion du frame Rate
			frameRate(frame_max);
			frame_max = SDL_GetTicks() + FRAME_RATE;
			if ((SDL_GetTicks() - temps) >= 1000)
			{
				temps = SDL_GetTicks();
				jeu->temps -= 1;
			}
		}


		endDisplay();
		cleanSounds();
		Mix_CloseAudio();
		fprintf(logFile, "||| END OF THE GAME |||\n");
		if (jeu != NULL)
			destroyMap(&jeu->pMapTerrain);
		destroyPolice();
		if (wormsTab != NULL)
			free(wormsTab);
		wormsTab = NULL;
	}
	cleanUp(&pInput, &pTextureDisplay);
	fprintf(logFile, "mainFenetre : SUCCESS.\n");
	if (jeu != NULL)
	{
		saveGame(jeu);
		destroyJeu(&jeu);
	}
	{
		time_t t1 = time(NULL);
		fprintf(logFile, "\n\nEnd of Session : %s", ctime(&t1));
		fclose(logFile);
	};
	return 0;
}