示例#1
0
文件: mancala.c 项目: wfei/hw
int main(int argc, char *argv[]){
    lHead = NULL;
    printFlag = 1;
    printf("Author: Muxuan Wang\n");
    printf("Program 5: Mancala\n");
    printf("TA: Sean Deitz, W 9:00 AM\n");
    printf("Nov.28,2012\n");
    printf("\n");
    
    printf("Welcome to the game of Mancala, where you are playing against\n");
    printf("a computer opponent. You may enter 'u' to undo a move or \n");
    printf("'x' to exit. Your holes are on the bottom row and you get\n");
    printf("to go first.\n");
    printf("\n");
    printf("\n");
    

    Hole board[14];
    initBoard(board);
    if (argc > 1) {
	commandLineArg(board, argv);
    }
    
    addToTail(&lHead, board);

    int player = 0;
    char userInput;
    int notDone = 1;
    int gameNum = 1;

    //each loop is a turn, and involves user and computer to play.
    while(notDone){
	printf("----------------------------------------------------------\n");
	playerToMove(player,board, &gameNum);
	notDone = checkEndGame(board);
	if (notDone == 0) {
	    break;
	}
	player = (++player) % 2;
	playerToMove(player,board, &gameNum);	    
	notDone = checkEndGame(board);
	gameNum++;
	player = (++player) % 2;
	addToTail(&lHead, board);
    }

    endGameScore(board);
    printf("The final board is: \n");
    displayBoard(board);
    if(board[13].capacity > board[6].capacity){
	printf("Computer Won!!\n");
    }else if(board[13].capacity < board[6].capacity){
	printf("You Won!!\n");
    }else{
	printf("Play Even!!");
    }

} // end of main
示例#2
0
int IAclass::calcMinMax(std::map<poseCase, typeCase>& mapLevel, int prof, bool isMax, int alpha, int beta)
{
    int tmpNb = 0;
    poseCase poseActu(-1, -1);

    if(checkEndGame(mapLevel) == true || prof <= 0)
    {
        return evalue(mapLevel);
    }

    for(int i = 0; i < 7; ++i)
    {
        poseActu = coupPossible(mapLevel, i);
        if(poseActu == poseCase(-1, -1))
        {
            continue;
        }

        mapLevel[poseActu] = isMax ? color : enemiColor;
        lastPose = poseActu;
        tmpNb = calcMinMax(mapLevel, prof - 1, !isMax, alpha, beta);
        mapLevel[poseActu] = VIDE;
        if(isMax)
        {
            if(tmpNb > alpha)
            {
                alpha = tmpNb;
            }
            if(alpha >= beta)
            {
                return alpha;
            }
        }
        else if(!isMax)
        {
            if(tmpNb < beta)
            {
                beta = tmpNb;
            }
            if(beta <= alpha)
            {
                return beta;
            }
        }
    }

    return (isMax ? alpha : beta);
}
示例#3
0
文件: mancala.c 项目: wfei/hw
// The function is to process a player's move from displaying the board, getting
// user input to dealing with user input.
// It takes player, board array and gameNum as parameter. 
// gameNum is used to record how many turns the user and computer have played.
void playerToMove(int player,Hole board[],int* gameNum){
    char userInput;
    int playerDone = 0;
    int i = 0;
    do{
	if ((player == 1 && i > 0) || player == 0)
	    displayBoard(board);
	userInput = getUserInput(player, gameNum, playerDone, board);
	playerDone = pieceToMove(player, userInput, board);
	if(checkEndGame(board) == 0)
	    break;
	i++;
	
    }while (playerDone);
   
	
} //end of playerToMove
示例#4
0
文件: mancala.c 项目: wfei/hw
// The function is to process a player's move from displaying the board, getting
// user input to dealing with user input.
// It takes player, board array and gameNum as parameter. 
// gameNum is used to record how many turns the user and computer have played.
void playerToMove(int player,Hole board[],int gameNum){
    char userInput;
    int playerDone = 0;
    do{
	displayBoard(board);
	userInput = getUserInput(player, gameNum, playerDone, board);
	playerDone = pieceToMove(player, userInput, board);
	if(checkEndGame(board) == 0)
	    break;
	
    }while (playerDone);
    //displayBoard(board);
    //printf("---------------------------------------------------\n sepertat");

    /* if(oneGameDone){ */
    /* 	printf("-----------------------------------------------------\n"); */
    /* 	displayBoard(board); */
    /* } */
	
} //end of playerToMove
示例#5
0
void GameEnvironment::draw()
{
	if (blinkCounter++ < blinkDelay)
		;
	else
	{
		blinkDelay = (30 * rand()) / (RAND_MAX + 1.0);
		lightOn = rand() % 2 == 1;
		blinkCounter = 0;

		if (blinkDelay > 15 && !lightOn)
			lightOn = true;
	}

	if (!gameOver && !gameWon)
	{
		if (lightOn || pause)
		{
			// add ambient and directed light
			addLight();

			//add fog
			addFog();

			// flashlight
			glPushMatrix();
			//move with camera
			glTranslated(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ());
			//rotate with camera
			glRotatef(-cameraYaw * 180 / PI, 0, 1, 0);
			glRotatef(-cameraPitch * 180 / PI, 0, 0, 1);
			glScalef(0.25, 0.25, 0.25);
			glTranslatef(1.0, -0.4, +0.7);
			glRotated(60, 0.7, -3.0, 0.5);
			flashlight->draw();
			glPopMatrix();
			
			// level
			glPushMatrix();
			level->draw();
			glPopMatrix();

			//table
			glPushMatrix();
			table->draw();
			glPopMatrix();

			if (!accesscardIsFound)
			{
				//accesscard
				glPushMatrix();
				glTranslatef(-38.0, -1.3, -58.0);
				accesscard->draw();
				glPopMatrix();
			}

			// terminal
			glPushMatrix();
			glScalef(1.0, 0.9, 1.0);
			glTranslatef(-34.5, -1.3, -59);
			terminal->draw();
			glPopMatrix();

			// monster
			glPushMatrix();
				monsterLastPositionZ = (monsterLastPositionZ + monsterSpeed);
				enemyMonster->jbTranslate(monsterLastPositionX, monsterLastPositionY, monsterLastPositionZ);
				glRotated(180, 0, -1.0, 0);

				enemyMonster->setFrameNumber(frame);
				enemyMonster->drawWithAni(monsterAnimationId);
				++frame;
				if (monsterIsRunning)
				{
					monsterSpeed += 0.02;
				}
				else
				{
					monsterSpeed = 0.0;
				}

				if (frame == (enemyMonster->frame_count[monsterAnimationId] - 1))
				{
					frame = 0;
				}
			glPopMatrix();

			glDisable(GL_TEXTURE_2D);
		}

		setCameraBoundingBox();		

		//countDistanceToMonster();
		jbCountDistanceToMonster();

		detectCollision(enemyMonster);
		detectCollision(table);
		//collision with walls
		checkLevelCollisionX();
		checkLevelCollisionZ();

		playRadarSound();
		playPlayerFootstepSound();
		playEnemyMonsterRandomSound();

		isEnemyMonsterSeePlayer();
		isEnemyMonsterCatchPlayer();
		isEnemyMonsterRunAway();
		checkEndGame();

		glFlush();
	}
	else if (gameWon)
	{
		// Add ambient light
		GLfloat ambientColor[] = { 0.85f, 0.85f, 0.85f, 1.0f };
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
		glPushMatrix();
		//move with camera
		glTranslated(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ());
		//rotate with camera
		glRotatef(-cameraYaw * 180 / PI, 0, 1, 0);
		glRotatef(-cameraPitch * 180 / PI, 0, 0, 1);
		glScalef(0.5, 0.5, 0.5);
		glTranslatef(12.0, -5.0, 0.0);
		glRotated(90, 0.0, 1.0, 0.0);
		gameOverSuccess->draw();
		glPopMatrix();
	}
	else if (gameOver)
	{
		// Add ambient light
		GLfloat ambientColor[] = { 0.85f, 0.85f, 0.85f, 1.0f };
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
		glPushMatrix();
		//move with camera
		glTranslated(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ());
		//rotate with camera
		glRotatef(-cameraYaw * 180 / PI, 0, 1, 0);
		glRotatef(-cameraPitch * 180 / PI, 0, 0, 1);
		glScalef(0.5, 0.5, 0.5);
		glTranslatef(12.0, -5.0, 0.0);
		glRotated(90, 0.0, 1.0, 0.0);
		gameOverFail->draw();
		glPopMatrix();
	}
}
示例#6
0
//--------------------------------------
void Map::Update()
{
	//Cập nhật tank người chơi
	if (_eagle->getEagleStatus() == EAGLE_STATUS::LIVE)
	{
		_player->Update();
	}

	//Cập nhật tank địch
	updateEnemy();

	//Cập nhật đạn
	BulletManager::getInstance()->Update();

	//Xét va chạm giữa tank người chơi và căn cứ
	CollisionManager::CollisionPreventMove(_player, _eagle);

	//Xét va chạm giữa tank địch và căn cứ
	int n = _listEnemyOnMap->size();
	for (int i = 0; i < n; i++)
	{
		bool isCollided = CollisionManager::CollisionPreventMove(_listEnemyOnMap->at(i), _eagle);
		if (isCollided)
			break;
	}

	//Xét va chạm giữa các xe tank địch với nhau
	bool isCollision;
	for (int i = 0; i < n-1; i++)
	{
		for (int j = i+1; j < n; j++)
		{
	
				isCollision = CollisionManager::CollisionEnemy(_listEnemyOnMap->at(i), _listEnemyOnMap->at(j));
				if (isCollision)
					break;
			
		}
	}

	//Xét va chạm giữa các xe tank địch với tank người chơi
	for (int i = 0; i < n; i++)
	{
		CollisionManager::CollisionChangeDirection(_player, _listEnemyOnMap->at(i));
	}

	//Xét va chạm giữa đạn với tank địch với tank người chơi
	if (_eagle->getEagleStatus() == EAGLE_STATUS::LIVE)
	{
		if (n == 0)
			BulletManager::getInstance()->UpdateCollisionWithDynamicObject(_player, _eagle);
		for (int i = 0; i < n; i++)
		{
			BulletManager::getInstance()->UpdateCollisionWithDynamicObject(_player, _eagle, _powerUpItem, _listEnemyOnMap->at(i));
		}

	}

	//Xét va chạm giữa tank người chơi và powerup item
	if(_powerUpItem->IsEnable())
	{
		CollisionManager::CollisionWithItem(_player, _powerUpItem);
	}

	//Hồi sinh tank của người chơi
	if (_player->_isTerminated)
	{
		if (_player->getLife() > 0)
		{
			int pos = CollisionManager::FindRespawnPosition(_playerRespawnPos, DEFINE_ZERO_VALUE, _listEnemyOnMap);
			if (pos == 0)
			{
				_player->Respawn(DEFAULT_PLAYER_POSITION_X, DEFAULT_PLAYER_POSITION_Y);
			}
			else if (pos == 1)
			{
				_player->Respawn(DEFAULT_PLAYER_POSITION_X_2, DEFAULT_PLAYER_POSITION_Y);
			}
			else
			{
				_player->setPositionX(DEFINE_ZERO_VALUE);
				_player->setPositionY(DEFAULT_PLAYER_POSITION_Y);
			}

		}
		else
		{
			_player->setLife(-1);
			_player->setPositionX(DEFINE_ZERO_VALUE);
			_player->setPositionY(DEFINE_ZERO_VALUE);
		}
	}
	updatePowerItem();
	ClearDestroyedEnemy();
	checkEndGame();
}