コード例 #1
0
ファイル: unittest3.c プロジェクト: Vladis466/Homework
int main () {
	
	struct gameState G;
	struct gameState *state = &G;
	struct gameState G2;
	
	int kingdomCards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, minion, cutpurse };
	
	initializeGame(2, kingdomCards, 69, state);
	memcpy(&G2, &G, sizeof(struct gameState));
	struct gameState *pre = &G2;
	
	printf("Number of Province cards: %d\n", state->supplyCount[province]);
	checkGameOver(state);

	printf("Emptying Provinces...\n");
	state->supplyCount[province] = 0;
	checkGameOver(state);
	
	printf("Refilling Provinces...\n");
	state->supplyCount[province] = pre->supplyCount[province];
	printf("Number of Province cards: %d\n", state->supplyCount[province]);
	checkGameOver(state);
	
	printf("Emptying some supply piles...\n");
	state->supplyCount[minion] = 0;
	state->supplyCount[great_hall] = 0;
	state->supplyCount[village] = 0;
	checkGameOver(state);
	
	return 0;
}
コード例 #2
0
ファイル: battleship.c プロジェクト: Cleberth/CS225Fa12Chess
void runGame(void)
{
	//Players (hits, boards)
	PLAYER player1;
	PLAYER player2;

	printf("\t\tWelcome to Shooting Boats!\n\n\n");

	printf("Setting up player 1\n");
	setupPlayer(&player1); printf("\n\n\n\n\n\n\n\n");

	printf("Setting up player 2\n");
	setupPlayer(&player2); printf("\n\n\n\n\n\n\n\n");

	printf("\t\tTime to play!\n");

	playLoop(&player1, &player2);

	printf("\t\tThe game is over!\n");

	switch(checkGameOver(&player1, &player2))
	{
		case GAME_OVER_TIE:
			printf("Mutually Assured Destruction!\n"); break;
		case GAME_OVER_PLR1_WINS:
			printf("Player 1 survives!!\n"); break;
		case GAME_OVER_PLR2_WINS:
			printf("Player 2 triumphs!\n"); break;
		default: printf("The Bermuda Triangle strikes again...");
	}
}
コード例 #3
0
ファイル: game.cpp プロジェクト: peecky/teddy-block
void Game::RunGame()
{
	unsigned time = timeGetTime();
	if((time - oldtime) < TIMEFACTOR) return;
	oldtime = time;

	figure_moving = map.Update();
	if( teddy_moving == true ) teddy_moving = kuma->Move();

	int temp_score = map.ScoreUpdate();
	score += map.show_combo() * map.show_combo() * temp_score * temp_score;
	playtime += TIMEFACTOR / 1000.0;

	if(checkGameOver() == true) {
		state = END;
		return;
	}

	// generate firuges
	int x, y, loop_limit = (MAP_WIDTH * MAP_HEIGHT * 2);
	//level = score / 5000;

	if(level > 20) level = 20;
	if(!(rand() % ( (INIT_DIFFICULTY - level*400 )/100))) {
		do {
			x = rand() % MAP_WIDTH;
			y = rand() % MAP_HEIGHT;
			loop_limit--;	// to avoid too many loops
		} while(map.getTile(x, y) != Tile::EMPTY && loop_limit > 0);
		if(loop_limit > 0) map.setTile(x, y, (Tile::Type)(rand() % 3 + 1));
	}

	Display();
}
コード例 #4
0
ファイル: Game.cpp プロジェクト: Resinderate/TimTamGame
/*
	Name:	run
	Desc:	main function used to run the game, calling everything else needed to function inside
	Args:	None
	Rtrn:	m_retry,	a bool to determine if the player wants to play again 
*/
bool Game::run()
{
	startingHousekeeping();
	while(m_window->isOpen() && m_stillPlaying)
	{
		//Run the game loop.
		handleEvents();

		if(!m_paused && !m_gameOver)
		{
			spawnNewBalls();
			moveObstacles();
			moveObstacleReactions();
			checkCollisions();
			checkBallsLeavingScreen();
			processObjective();
			processPlayerParticleSys();
			addCumilativePoints();
			generatePointsText();
		}

		if(!m_gameOver)
		{
			checkPause();
			checkGameOver();
		}

		render();
	}
	return m_retry;
}
コード例 #5
0
void MySnake::moveSnake(float dt)
{
    MySprite *footSnake = (MySprite *)getChildByTag(getChildrenCount()-2+batchNodeStartTag);
    for (int i=getChildrenCount()-2; i >= 0; i--) {
        MySprite *sprite = (MySprite *)getChildByTag(i+batchNodeStartTag);
        MySprite *sprite1 = (MySprite *)getChildByTag(i-1+batchNodeStartTag);
        if (sprite != snakeHeader) {
            sprite->setIndex(sprite1->getIndex()); //setPosition(getChildByTag(i-1+batchNodeStartTag)->getPosition());
        }
        else
        {
            this->moveSnakeHeader();
        }
    }
    
    if (snakeHeader->getIndex() == randomSprite->getIndex()) {
        
        addSnake(footSnake->getIndex());
        changeRandomSpritePozition();
    }
    
    checkGameOver();
    
    isNormal = true;
}
コード例 #6
0
void playComputer() {
    QString coord, message, message2, endMessage;
    int x, y;

    cout << "\nThe S's on the grid are your ships" << endl;
    cout << "The O's mark where the computer is guessing on the top grid" << endl;
    cout << "The O's on the lower grid are your guesses" << endl;
    cout << "The X's are the computer's hits on the top grid and your hits on the lower grid" << endl;
    cout << "If you find all 5 computer ships you win." << endl;
    cout << "If the computer finds your 5 ships, you lose." << endl;
    cout << "Alright! All your ships are set in the grid below" << endl;
    cout << "Lets begin. You start. Guess a coordinate where you think an enemy ship is." << endl;
    while (!checkGameOver(player1Grid, player2Grid, endMessage)) {
        clearScreen();
        if (!message.isEmpty())
            cout << message;
        if (!message2.isEmpty())
            cout << message2;
        displayGrid(player1Grid);
        cout << endl;
        displayGrid(player1HitGrid);

        do {
            cin >> coord;
        } while(!checkValidCoord(coord) | !markGuess(player1HitGrid, player2Grid, coord, message));

        do {
            x =rand() % 10;
            y =rand() % 10;
        } while (!markComputerGuess(player1Grid, x, y, message2));
    }
    cout << endMessage;
    return;
}
コード例 #7
0
ファイル: battleship.c プロジェクト: Cleberth/CS225Fa12Chess
void playLoop(PLAYER* plr1, PLAYER* plr2)
{
	int endGame=GAME_NOT_OVER;
	while(endGame == GAME_NOT_OVER)
	{
		printf("\n\n\n\n\n");
		executeRound(plr1, plr2);
		endGame = checkGameOver(plr1, plr2);
	}
}
コード例 #8
0
ファイル: World.cpp プロジェクト: pcman75/libgdx-cpp
void World::update(float deltaTime, float accelX)
{
	updateBob(deltaTime, accelX);
	updatePlatforms(deltaTime);
	updateSquirrels(deltaTime);
	updateCoins(deltaTime);
	if(bob.state != Bob::BOB_STATE_HIT) 
		checkCollisions();
	checkGameOver();
}
コード例 #9
0
ファイル: tetromino.cpp プロジェクト: ShotaroTsuji/mona
int Tetromino::setNew(Field* f, int x, int y, int turn, int type)
{
	this->x = x%10 + 3; // 3 〜 12
	this->y = y%22; // そのまま
	this->turn = (turn+4) % 4;
	this->type = type%7 + 1; // 1 〜 7
	this->interval = 0;
	this->landing = 0;
	this->landed = 0;
	return checkGameOver(f);
}
コード例 #10
0
PTR_MESSAGE generateGameOver(uint8_t type, uint16_t length, char* content)
{
	PTR_MESSAGE msg;
    
	msg = generateMsg(type, length, content);
	if(checkGameOver(msg) == true)
	{
		return msg;
	}
	else
	{
		free(msg);
		return NULL;
	}
}
コード例 #11
0
BOOL messageValidate(PTR_MESSAGE msg)
{
	BOOL result;

	result = false;
	switch(msg->type) {
		case LoginRequest:
			result = checkLoginRequest(msg);
			break;
		case LoginResponseOK:
			result = checkLoginResponseOK(msg);
			break;
		case CatalogRequest:
			result = checkCatalogRequest(msg);
			break;
		case CatalogResponse:
			result = checkCatalogResponse(msg);
			break;
		case CatalogChange:
			result = checkCatalogChange(msg);
			break;
		case PlayerList:
			result = checkPlayerList(msg);
			break;
		case StartGame:
			result = checkStartGame(msg);
			break;
		case QuestionRequest:
			result = checkQuestionRequest(msg);
			break;
		case QUestion:
			result = checkQuestion(msg);
			break;
		case QuestionAnswered:
			result = checkQuestionAnswered(msg);
			break;
		case QuestionResult:
			result = checkQuestionResult(msg);
			break;
		case GameOver:
			result = checkGameOver(msg);
			break;
		case ErrorWarning:
			result = checkErrorWarning(msg);
			break;
	}
	return result;    
}
コード例 #12
0
ファイル: interrupts.c プロジェクト: YazanHalawa/ECEn-427
// This is invoked in response to a timer interrupt.
// This code is used for everything that needs to
// use precise timing. It is split into many function
// for readability.
void timer_interrupt_handler() {

	// Increment the following counters:
	fit_timer_count++;
	debounce_timer_count++;
	alien_explosion_count++;

	checkGameOver();			// Check to see if the aliens have reached the bottom.
	alienBulletsCreate();		// Create a new alien bullet, if possible.
	saucerUpdate();				// Move the saucer.
	debounceButtons();			// Debounce the push buttons, and then move the tank and/or fire.
	checkExplosion();			// Handle alien explosions.
	updateAllBullets();			// Update both the tank and alien bullets.
	updateAlienBlock();			// Update the alien block position.
	updateSaucerFlashing();		// Update if the saucer is hit and should be flashing.
	updateTankFlashing();		// Update if the tank is hit and should be flashing.
	resetDebouncer();			// Reset the debouncer timer if no buttons are pressed.
}
コード例 #13
0
ファイル: GameServer.cpp プロジェクト: qing7ling0/LQProjects
void GameServer::nextRound(void)
{
	bool over = checkGameOver();
	if (over)
	{
		Tasks::getInstance()->addTask(GameOverTask::create(MonitorType::MonitorWaitNext));
	}
	else
	{
		_roundInfo->_currentRound++;
		_roundInfo->_selfRound = !_roundInfo->_selfRound;

		RoundInfo* round = RoundInfo::create();
		round->_currentRound = _roundInfo->_currentRound;
		round->_selfRound = _roundInfo->_selfRound;

		Tasks::getInstance()->addTask(NewRoundTask::create(MonitorType::MonitorWaitNext, round));
	}
}
コード例 #14
0
ファイル: Board.cpp プロジェクト: dwatzke/fifteen
void Board::moveClicked()
{
	int x, y, rs, cs;
	QPushButton* clickedBtn = static_cast<QPushButton*>(sender());
	grid->getItemPosition(grid->indexOf(clickedBtn), &y, &x, &rs, &cs);

	if((path.x() == x && (path.y() == y+1 || path.y() == y-1))
	|| (path.y() == y && (path.x() == x+1 || path.x() == x-1))) // valid button, move it
	{
		// remove the widget from the actual position
		grid->removeWidget(clickedBtn);
		// and re-add it to where the path has been
		createButton(clickedBtn, 0, path.x(), path.y());
		// and update the path coordinates
		path = QPoint(x, y);
		// also update the move count
		static_cast<MainWindow*>(parentWidget())->updateMoves();
		checkGameOver();
	}
}
コード例 #15
0
void playFriend() {
    QString coord, coord2, message;
    cout << "\nThe S's on the grid are your ships" << endl;
    cout << "The O's on the top grid mark where " << player1 << " is guessing." << endl;
    cout << "The O's on the bottom grid mark where " << player2 << " is guessing." << endl;
    cout << "The X's represents hits and are marked on the same grids as the O's" << endl;
    cout << "The first person to sink all 5 ships wins" << endl;

    while (!checkGameOver(player1Grid, player2Grid, message)) {
        cout << player1 << " choose a Coordinate to hit." << endl;
        displayGrid(player1HitGrid);
        cout << endl;
        displayGrid(player2HitGrid);

        do {
            cin >> coord;
        } while(!checkValidCoord(coord) | !markGuess(player1HitGrid, player2Grid, coord, message));

        clearScreen();
        if (!message.isEmpty())
            cout << message;
        cout << player2 << " choose a Coordinate to hit." << endl;
        displayGrid(player1HitGrid);
        cout << endl;
        displayGrid(player2HitGrid);

        do {
            cin >> coord2;
        } while (!checkValidCoord(coord2) | !markGuess(player2HitGrid, player1Grid, coord2, message));
        clearScreen();
        if (!message.isEmpty())
            cout << message;
    }

    if (message == "You Win!\n")
        cout << player1 << " wins!" << endl;
    else if (message == "It's a draw!\n")
        cout << message;
    else
        cout << player2 << " wins!" << endl;
}
コード例 #16
0
ファイル: 2048.cpp プロジェクト: JordaanMe/C-and-CPP-Programs
int generateNumber(char c){

	int blank = 0, i;
	for (i = 0; i < 16; i++)
	if (board[i / 4][i % 4] == 0)
		blank++;

	int square = rand() % blank;
	int n = rand() % 4;
	n = n < 3 ? 2 : 4;
	for (i = 0; i < 16; i++){
		if (square == 0 && board[i / 4][i % 4] == 0){
			board[i / 4][i % 4] = n;
			printBoard();
			printf("\nBoard %d,%d = %d", i / 4, i % 4, n);
			break;
		}
		else if (board[i / 4][i % 4] == 0)
			square--;
	}
	switch (c){
		case 'w' :
		printf("\nUP");
		break;
		case 's':
			printf("\nDOWN");
			break;
		case 'a':
			printf("\nLEFT");
			break;
		case 'd':
			printf("\nRIGHT");
			break;
	}
	if (blank == 1 && checkGameOver())
		return 1;
	else
		return 0;
}
コード例 #17
0
int main(void) 
{
    // intro text
    printf("* * * DUNGEON QUEST * * *\n\n");
    printf("You find yourself in a dungeon ruled by dark magic\n");
    printf("Try to escape and reach %s without dying!\n", DESTINATION);
    printf("But before you arrive, you must boost your %s to at least level %i,\n", SKILL, SKILL_GOAL);
    printf("...or else the Dieties of %s will not accept you!\n\n", DESTINATION);
    
    // provide a seed to the random number generator (don't worry about understanding this)
    srand(time(NULL));
    
    // initialize the player
    player p = { 100, 3, 1 };

    // continue looping forever until Game Over
    while (true)
    {
        if (checkGameOver(p))
        {
            // stop if we hit Game Over
            return 0;
        }
        
        reportStatus(p);
        
        printf("You continue walking through dark corridors...\n");
        p.distance -= 1;
        GetString();
        
        printf("You health is slowly waning...\n");
        p.health -= 10;
        GetString();
        
        discoverPotion(&p);
    }
}
コード例 #18
0
ファイル: CombatScene.cpp プロジェクト: davidxk/Blow-My-Lake
void Combat::update(float delta)
{
	if (playerbutton->isTouch==true&&isPlayingAnimation==false)
	{
		//锁定playerbutton触摸
		playerbutton->LockButtonTouch();
		//怪物选择button
		monsterButtonTag = monster->chooseButton();
		//判断属性胜负
		winnerNum = checkButtonTag(playerbutton->tag,monsterButtonTag);
		CCLOG("win:%d",winnerNum);
		//伤害计算
		damage = damageCompute(winnerNum);
		CCLOG("damage:%d",damage);
		//播放战斗动画
		//post消息
		CCNotificationCenter::sharedNotificationCenter()->postNotification(ANIMATION_MSG,NULL);
		//更新血条
		updateBlood(winnerNum,damage);
		playerbutton->isTouch=false;
		//判断是否结束
		checkGameOver();
	}
}
コード例 #19
0
ファイル: GameScene.cpp プロジェクト: nomadsinteractive/2048
void GameScene::doCheck() {

    if (!checkWin()) {
        checkGameOver();
    }
}
コード例 #20
0
ファイル: sea.cpp プロジェクト: TI-ECS/battleship
HitInfo Sea::hit(const Coord& pos)
{
    HitInfo res = otherField()->hit(pos);
    checkGameOver();
    return res;
}
コード例 #21
0
ファイル: T2.cpp プロジェクト: a1l9e8x6/Hello
void T2::checkMove(int dir_guester)
{
	if(dir_guester== DIR_RIGHT){
		//≈ì√ö‚Äù‚Ä?
		if (move_state == MOVE_YD1) //¬µ‚ÅÑ‚Äú¬™‚⧌©‚Äú‚àÜ‚àÇ√?
		{
			for (int i=0;i<MAX_ROW;i++)
			{
				for (int j = MAX_COL-2; j >=0 ; --j)
				{
					int index  = -1;
					int count = 0;

					if(arr_Num[i][j]>-1&&arr_Num[i][j+1]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆?
					{
						bemoved_yd1 = true;

						index = j+1;
						while (arr_Num[i][index]==-1)
						{
							count++;
							if(index<MAX_COL-1)
								index++;
							else
								break;
						}
						nodeMove(dir_guester,i,j,count);
						change2number(arr_Num[i][j],arr_Num[i][j+count]);

					}
				}

			}

			logcat_chessArr("move-yd1");
			if(bemoved_yd1){
				CCLog("can move yd1");
				move_state = MOVE_NONE;
			}else{
				CCLog("can not move yd1");
				move_state = MOVE_HETI;
			}
		}
		else if(move_state == MOVE_HETI)//¬µ‚Å?‚⧌©‚à´≈ì‚â•‚Ä?
		{
			CCLog("rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr");

			update_moveyd1();

			for (int i=0;i<MAX_ROW;i++)
			{
				for (int j=MAX_COL-1;j>0;j--)
				{
					if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i][j-1]&&arr_Num[i][j]==arr_Num[i][j-2]&&arr_Num[i][j]==arr_Num[i][j-3])
					{
						CCLog("ppppppppppppppp");
						becomposed = true;

					

						arr_Num[i][j]++;
						arr_Num[i][j-1]= -1;

						addScore(arr_Num[i][j]);

						change(dir_guester,i,j,arr_Num[i][j]);
						removeChessnode(dir_guester,i,j-1);

						MyCCLog::verbose("score---");

						break;
					}

					else if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i][j-1])
					{
						CCLog("qqqqqqqqqqqqqq");
						becomposed = true;
					

						arr_Num[i][j]++;
						arr_Num[i][j-1]= -1;

						addScore(arr_Num[i][j]);

						change(dir_guester,i,j,arr_Num[i][j]);
						removeChessnode(dir_guester,i,j-1);

					}
				}
			}
			CCLog("tttttttttttttttttttttttttttttttttttttttttttttttttttttttt");
			logcat_chessArr("right-move-heti1");

			if(bemoved_yd1&&!becomposed)
			{
				CCLog("can move and can not heti");
				move_state = MOVE_OVER;
				return;
			}

			move_state = MOVE_NONE;

		}
		else if(move_state == MOVE_YD2)
		{
			CCLog("MOVE_YD2MOVE_YD2");
			for (int i=0;i<MAX_ROW;i++)
			{
				for (int j = MAX_COL-2; j >=0 ; --j)
				{
					int index  = -1;
					int count = 0;
					if(arr_Num[i][j]>-1&&arr_Num[i][j+1]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆?
					{
						index = j+1;
						while (arr_Num[i][index]==-1)
						{
							count++;
							if(index<MAX_COL-1)
								index++;
							else
								break;
						}
						nodeMove(dir_guester,i,j,count);
						change2number(arr_Num[i][j],arr_Num[i][j+count]);

					}
				}
			}

			logcat_chessArr("move-yd2");
			move_state = MOVE_OVER;

		}

		else if(move_state == MOVE_OVER)
		{
			CCLog("right-----------move-over---over");
			addNewChess();
			move_state = MOVE_NONE;
			if(checkFull())
			{
				bool rightover = checkGameOver();
				CCLog("rightover = %d",rightover);
			}


		}

	}


	else if(dir_guester== DIR_LEFT){
		//≈ì√ö‚Äù‚Ä?

		if (move_state == MOVE_YD1) //¬µ‚ÅÑ‚Äú¬™‚⧌©‚Äú‚àÜ‚àÇ√?
		{
			for (int i=0;i<MAX_ROW;i++)
			{
				for (int j =1; j < MAX_COL ; j++)
				{
					int index  = -1;
					int count = 0;

					if(arr_Num[i][j]>-1&&arr_Num[i][j-1]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆?
					{
						bemoved_yd1 = true;

						index = j-1;
						while (arr_Num[i][index]==-1)
						{
							count++;
							if(index>0)
								index--;
							else
								break;
						}
						nodeMove(dir_guester,i,j,count);
						change2number(arr_Num[i][j],arr_Num[i][j-count]);

					}
				}

			}

			logcat_chessArr("left-move-yd1");
			if(bemoved_yd1){
				CCLog("can move left yd1");
				move_state = MOVE_NONE;
			}else{
				CCLog("can not move left yd1");
				move_state = MOVE_HETI;
			}
		}
		else if(move_state == MOVE_HETI)//¬µ‚Å?‚⧌©‚à´≈ì‚â•‚Ä?
		{

			update_moveyd1();

			for (int i=0;i<MAX_ROW;i++)
			{
				for (int j=0;j<MAX_COL-1;j++)
				{

					if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i][j+1]&&arr_Num[i][j]==arr_Num[i][j+2]&&arr_Num[i][j]==arr_Num[i][j+3])
					{
						CCLog("wdddddddsssssss");
						becomposed = true;
						arr_Num[i][j]++;
						arr_Num[i][j+1]= -1;
							addScore(arr_Num[i][j]);

						change(dir_guester,i,j,arr_Num[i][j]);
						removeChessnode(dir_guester,i,j+1);
						break;
					}
					if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i][j+1])
					{
						CCLog("ssssdwww");
						becomposed = true;
						arr_Num[i][j]++;
						arr_Num[i][j+1]= -1;

							addScore(arr_Num[i][j]);
						change(dir_guester,i,j,arr_Num[i][j]);
						removeChessnode(dir_guester,i,j+1);

					}
				}
			}
			CCLog("tttttttttttttttttttttttttttttttttttttttttttttttttttttttt");
			logcat_chessArr("left-move-heti1");

			if(bemoved_yd1&&!becomposed)
			{
				CCLog("can move and can not heti");
				move_state = MOVE_OVER;
				return;
			}
			move_state = MOVE_NONE;

		}
		else if(move_state == MOVE_YD2)
		{
			CCLog("MOVE_YD2MOVE_YD2");
			for (int i=0;i<MAX_ROW;i++)
			{
				for (int j =1; j < MAX_COL ; j++)
				{
					int index  = -1;
					int count = 0;

					if(arr_Num[i][j]>-1&&arr_Num[i][j-1]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆?
					{
						bemoved_yd1 = true;

						index = j-1;
						while (arr_Num[i][index]==-1)
						{
							count++;
							if(index>0)
								index--;
							else
								break;
						}
						nodeMove(dir_guester,i,j,count);
						change2number(arr_Num[i][j],arr_Num[i][j-count]);

					}
				}

			}
			logcat_chessArr("move-yd2");
			move_state = MOVE_OVER;

		}

		else if(move_state == MOVE_OVER)
		{
			CCLog("left-----------move-over---over");
			addNewChess();
			if(checkFull())
			{
				bool leftover = checkGameOver();
				CCLog("leftover = %d",leftover);
			}
			move_state = MOVE_NONE;
		}

	}

	else if(dir_guester == DIR_UP){	//≈ì√ö‚Ķ≈?

		if (move_state == MOVE_YD1) //¬µ‚ÅÑ‚Äú¬™‚⧌©‚Äú‚àÜ‚àÇ√?
		{
			for (int j =0; j < MAX_COL ; j++)//lie
			{
				for (int i= MAX_ROW-2;i>=0;i--)//hang
				{
					int index  = -1;
					int count = 0;
					if(arr_Num[i][j]>-1&&arr_Num[i+1][j]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆?
					{
						bemoved_yd1 = true;

						index = i+1;
						while (arr_Num[index][j]==-1)
						{
							count++;
							if(index<MAX_ROW-1)
								index++;
							else
								break;
						}
						CCLog("j = %d i= %d COUNT = %d",j,i,count);
						nodeMove(dir_guester,j,i,count);
						change2number(arr_Num[i][j],arr_Num[i+count][j]);

					}
				}

			}

			logcat_chessArr("up-move-yd1");
			if(bemoved_yd1){
				CCLog("up -can move yd1");
				move_state = MOVE_NONE;
			}else{
				CCLog("up-can not move yd1");
				move_state = MOVE_HETI;
			}
		}
		else if(move_state == MOVE_HETI)//¬µ‚Å?‚⧌©‚à´≈ì‚â•‚Ä?
		{
			CCLog("mmmmmmmmmmmmmmmmmm");

			update_moveyd1();
			for (int j=0;j<MAX_COL;j++)
			{
				for (int i=MAX_ROW-1;i>0;i--)
				{
					if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i-1][j]&&arr_Num[i][j]==arr_Num[i-2][j]&&arr_Num[i][j]==arr_Num[i-3][j])
					{
						CCLog("ppppppppppppppp");
						becomposed = true;
						arr_Num[i][j]++;
						arr_Num[i-1][j]= -1;
							addScore(arr_Num[i][j]);
						change(dir_guester,j,i,arr_Num[i][j]);
						removeChessnode(dir_guester,j,i-1);

						break;
					}

					else if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i-1][j])
					{
						CCLog("qqqqqqqqqqqqqq");
						becomposed = true;
						arr_Num[i][j]++;
						arr_Num[i-1][j]= -1;
							addScore(arr_Num[i][j]);
						change(dir_guester,j,i,arr_Num[i][j]);
						removeChessnode(dir_guester,j,i-1);



					}
				}
			}
			CCLog("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
			logcat_chessArr("up------move-heti1");

			if(bemoved_yd1&&!becomposed)
			{
				CCLog("can move and can not heti");
				move_state = MOVE_OVER;
				return;
			}

			move_state = MOVE_NONE;

		}
		else if(move_state == MOVE_YD2)
		{
			for (int j =0; j < MAX_COL ; j++)//lie
			{
				for (int i= MAX_ROW-2;i>=0;i--)//hang
				{
					int index  = -1;
					int count = 0;
					if(arr_Num[i][j]>-1&&arr_Num[i+1][j]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆?
					{
						bemoved_yd1 = true;

						index = i+1;
						while (arr_Num[index][j]==-1)
						{
							count++;
							if(index<MAX_ROW-1)
								index++;
							else
								break;
						}
						CCLog("j = %d i= %d COUNT = %d",j,i,count);
						nodeMove(dir_guester,j,i,count);
						change2number(arr_Num[i][j],arr_Num[i+count][j]);

					}
				}

			}

			logcat_chessArr("move-yd2");
			move_state = MOVE_OVER;
		}

		else if(move_state == MOVE_OVER)
		{
			CCLog("up-----------move-over---over");
			addNewChess();
			if(checkFull())
			{
					bool upover = checkGameOver();
				CCLog("upover = %d",upover);
			}
			move_state = MOVE_NONE;
		}


	}

	else if(dir_guester == DIR_DOWN){
		if (move_state == MOVE_YD1) //¬µ‚ÅÑ‚Äú¬™‚⧌©‚Äú‚àÜ‚àÇ√?
		{
			for (int j =0; j < MAX_COL ; j++)//lie
			{
				for (int i= 1;i< MAX_ROW;i++)//hang
				{
					int index  = -1;
					int count = 0;
					if(arr_Num[i][j]>-1&&arr_Num[i-1][j]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆?
					{
						bemoved_yd1 = true;

						index = i-1;
						while (arr_Num[index][j]==-1)
						{
							count++;
							if(index>0)
								index--;
							else
								break;
						}
						CCLog("j = %d i= %d COUNT = %d",j,i,count);
						nodeMove(dir_guester,j,i,count);
						change2number(arr_Num[i][j],arr_Num[i-count][j]);

					}
				}

			}

			logcat_chessArr("down-move-yd1");
			if(bemoved_yd1){
				CCLog("down -can move yd1");
				move_state = MOVE_NONE;
			}else{
				CCLog("down-can not move yd1");
				move_state = MOVE_HETI;
			}
		}
		else if(move_state == MOVE_HETI)//¬µ‚Å?‚⧌©‚à´≈ì‚â•‚Ä?
		{
			CCLog("mmmmmmmmmmmmmmmmmm");

			update_moveyd1();
			for (int j=0;j<MAX_COL;j++)
			{
				for (int i=0;i<MAX_ROW-1;i++)
				{

					if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i+1][j]&&arr_Num[i][j]==arr_Num[i+2][j]&&arr_Num[i][j]==arr_Num[i+3][j])
					{
						CCLog("ppppppppppppppp");
						becomposed = true;
						arr_Num[i][j]++;
						arr_Num[i+1][j]= -1;
							addScore(arr_Num[i][j]);
						change(dir_guester,j,i,arr_Num[i][j]);
						removeChessnode(dir_guester,j,i+1);

						break;
					}

					else if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i+1][j])
					{
						CCLog("qqqqqqqqqqqqqq");
						becomposed = true;
						arr_Num[i][j]++;
						arr_Num[i+1][j]= -1;
							addScore(arr_Num[i][j]);
						change(dir_guester,j,i,arr_Num[i][j]);
						removeChessnode(dir_guester,j,i+1);



					}
				}
			}
			CCLog("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
			logcat_chessArr("down------move-heti1");

			if(bemoved_yd1&&!becomposed)
			{
				CCLog("can move and can not heti");
				move_state = MOVE_OVER;
				return;
			}

			move_state = MOVE_NONE;

		}
		else if(move_state == MOVE_YD2)
		{
			for (int j =0; j < MAX_COL ; j++)//lie
			{
				for (int i= 1;i< MAX_ROW;i++)//hang
				{
					int index  = -1;
					int count = 0;
					if(arr_Num[i][j]>-1&&arr_Num[i-1][j]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆?
					{
						bemoved_yd1 = true;

						index = i-1;
						while (arr_Num[index][j]==-1)
						{
							count++;
							if(index>0)
								index--;
							else
								break;
						}
						CCLog("j = %d i= %d COUNT = %d",j,i,count);
						nodeMove(dir_guester,j,i,count);
						change2number(arr_Num[i][j],arr_Num[i-count][j]);

					}
				}

			}
			logcat_chessArr("move-yd2");
			move_state = MOVE_OVER;
		}

		else if(move_state == MOVE_OVER)
		{
			CCLog("down-----------move-over---over");
			addNewChess();
			if(checkFull())
			{
				bool downover = checkGameOver();
				CCLog("downover = %d",downover);
			}
			move_state = MOVE_NONE;
		}

	}

}
コード例 #22
0
ファイル: sea.cpp プロジェクト: TI-ECS/battleship
void Sea::forceHit(const Coord& pos, const HitInfo& info)
{
    otherField()->forceHit(pos, info);
    checkGameOver();
}
コード例 #23
0
ファイル: blubbels.cpp プロジェクト: cpulvermacher/EvilAlarm
//let bubbles fall down / move stacks to right
void GameWidget::compressBubbles()
{
    for(int x = grid_size-1; x >= 0; x--) {
        int hole = -1;
        int holes = 0;
        bool bubble_found = false;
        for(int y = 0; y <= grid_size; y++) {
            if(y == grid_size or grid[x][y].color) { //not empty
                if(holes) { //hole found, move bubbles down
                    for(int i = hole; i > 0; i--) {
                        grid[x][i] = grid[x][i-holes];

                        if(use_animations) {
                            grid[x][i].yoffset = holes;
                            grid[x][i].yspeed = initial_speed;
                        }
                    }
                    for(int i = 0; i < holes; i++)
                        grid[x][i] = Bubble();
                }
                bubble_found = true;
                hole = -1;
                holes = 0;
            } else if(bubble_found) {
                hole = y;
                holes++;
            }
        }
    }

    for(int x = grid_size-1; x >= 0; x--) {
        if(!grid[x][grid_size-1].color) { //collumn empty
            //shift remaining collums
            int x2 = x;
            while(--x2 >= 0) {
                for(int y = 0; y < grid_size; y++) {
                    grid[x2+1][y] = grid[x2][y];

                    if(use_animations) {
                        grid[x2+1][y].xoffset += 1;
                        grid[x2+1][y].xspeed = initial_speed;
                    }
                }
            }

            //add new collumn
            const int height = int(double(rand())/(RAND_MAX + 1.0)*grid_size);
            for(int y = grid_size-1; y >= height; y--) {
                grid[0][y] = Bubble(double(rand())/(RAND_MAX + 1.0)*num_colors+1);

                if(use_animations) {
                    grid[0][y].scale_step = num_scale_steps-1;
                }
            }

            //erase remains of old collumn
            for(int y = height-1; y >= 0; y--)
                grid[0][y] = Bubble();

            x++; //make sure to run over collumn again
        }
    }
    if(use_animations)
        timer->start();

    update();
    checkGameOver();
}
コード例 #24
0
ファイル: MancalaBoard.cpp プロジェクト: wmcnicho/cs561hw
//Enocdes rules of the game, pretty crazy function
//excepts a 0-indexed move relative to the player's cells from left to right
bool MancalaBoard::make_move(int player, int cell){
    checkGameOver(player);
    if(player == 1){
        if(cell > p1_cell_end || cell < 0){
            std::cout << "Invalid move for p1" << std::endl;
            return false;
        }
        
        int num_moves = cells[cell];
        cells[cell] = 0;
        int pos = cell; //current position during loop
        while(num_moves > 0){
            if(pos < p1_cell_end){//iterating through own player's cells just move to next cell
                pos++;
                if(num_moves == 1){//ending on own side (check if cell is empty)
                    if(cells[pos] == 0){
                        p1_mancala += cells[pos + num_cells];
                        cells[pos + num_cells] = 0;
                        cells[pos] = 0;
                        p1_mancala ++;
                    }
                    else{
                        cells[pos]++;
                    }
                }
                else{
                    cells[pos]++;
                }
            }
            else if(pos == p1_cell_end){//at the end of player's row, add to mancala and begin iterating backwards
                p1_mancala++;
                pos = p2_cell_end + 1;
            }
            else{//at other player's side add to their cell and iterate
                if(pos == p2_cell_start){//reset to bottom cell
                    pos = p1_cell_start;
                    if(num_moves == 1){//ending on own side (check if cell is empty)
                        if(cells[pos] == 0){
                            p1_mancala += cells[pos + num_cells];
                            cells[pos + num_cells] = 0;
                            cells[pos] = 0;
                            p1_mancala ++;
                        }
                        else{
                            cells[pos]++;
                        }
                        
                    }
                    else{
                        cells[pos]++;
                    }
                }
                else{
                    pos--;
                    cells[pos]++;
                }
            }
            num_moves--;
        }
        if(pos == p2_cell_end + 1)//bonus move!
        {
            if(moves_available(player) > 0){
                return true;
            }
            else{
                checkGameOver(player);
            }
        }
    }
    else if(player == 2){
        if(cell >= num_cells || cell < 0){
            std::cout << "Invalid move for p2" << std::endl;
            return false;
        }
        
        cell = cell + num_cells;//convert to upper cell location in internal state representation
        int num_moves = cells[cell];
        cells[cell] = 0;
        int pos = cell;//current position during iteration
        //A move involves placing a stone into the next cell and updating position accordingly
        while(num_moves > 0){
            if(pos > p2_cell_start){//iterating through player's own cells (CCW => negative)
                pos--;
                if(num_moves == 1){
                    if(cells[pos] == 0){//ending in void cell on own side
                        p2_mancala += cells[pos - num_cells];
                        cells[pos - num_cells] = 0;
                        cells[pos] = 0;
                        p2_mancala++;
                    }
                    else{
                        cells[pos]++;
                    }
                }
                else{
                    cells[pos]++;
                }
            }
            else if(pos == p2_cell_start){//at the end of the player's row, add to mancala and begin iterating forwards
                p2_mancala++;
                pos = p1_cell_start - 1;
            }
            else{//on p1's side increment forwards
                if(pos == p1_cell_end){//reset to top cell
                    pos = p2_cell_end;
                    if(num_moves == 1){
                        if(cells[pos] == 0){
                            p2_mancala += cells[pos - num_cells];
                            cells[pos - num_cells] = 0;
                            cells[pos] = 0;
                            p2_mancala++;
                        }
                        else{
                            cells[pos]++;
                        }
                    }
                    else{
                        cells[pos]++;
                    }
                }
                else{
                    pos++;
                    cells[pos]++;
                }
            }
            num_moves--;
        }
        if(pos == p1_cell_start - 1){//bonus move!
            if(moves_available(player) > 0){
                return true;
            }
            else{
                checkGameOver(player);
            }
        }
    }
    return false;//performed action with no bonus move
}
コード例 #25
0
ファイル: hangman.c プロジェクト: loremo/Studying
int main(){
	int lives = 7;
	FILE* fp = fopen("Ulm.hm","r");
	char buffer[MAXBUFFLENGTH * BUFFERELEMENTS]; 
	reservoirSampling(buffer, fp);
	_Bool name = false;
	char answer[42];
	int k = 0;
	
	/*printing the question and saving the answer into an array*/
	for (int i = 0; i < BUFFERELEMENTS; ++i){
		for (int j = 0; buffer[i*MAXBUFFLENGTH + j] != '\n'; ++j){
			if(name == false){
				printf("%c",buffer[i*MAXBUFFLENGTH + j]);
			} else {
			  if (buffer[i*MAXBUFFLENGTH + j] != 0){
			    answer[k++] = buffer[i*MAXBUFFLENGTH + j];
			  }
			}
			if (buffer[i*MAXBUFFLENGTH + j] == '\t')
				name = true;
		}
		printf("\n");
	}
	//printf("answer: %s\n", answer);
	
	/* array of letters that have already been chosen */
	_Bool alreadyChosen[32] = { 0 };
	int input;
	
	
	loop: // goto label
	if (checkGameOver(alreadyChosen, answer, lives))
	  goto gameOver;
	printf("%d\t",lives);
	for (int i = 0; i < 32; ++i){
	  if(alreadyChosen[i] == true){
	    printf("%c", (char)('a' + i)); // print all the letters that have already been chosen 
	  }
	}
	printf("\t\t");
	
	/* printing the word to be guessed */
	for (int i = 0; i < answer[i] != '\0'; i++){
	  if(answer[i] == ' ' || answer[i] == '-' ||answer[i] == '.' || alreadyChosen[tolower(answer[i]) - 'a'] == true){
	    printf("%c", answer[i]);
	  } else {
	      printf("%c", '_');
	  }
	}
	printf("\n");

	while((input = getchar()) != '\n'){
	  if(normalizeInput(input) == -1){ 
	    --lives; // ivalid input
	  }
	  if(alreadyChosen[normalizeInput(input) - 'a'] == true){
	    --lives; // letter already chosen
	  } 
	  for (int i = 0; i < answer[i] != '\0'; i++){
	    if (input == tolower(answer[i])){
	      alreadyChosen[normalizeInput(input) - 'a'] = true; // right choice
	      goto loop;
	    }
	  }
	  alreadyChosen[normalizeInput(input) - 'a'] = true; // wrong choice
	  --lives;
	}
	goto loop;
	
	gameOver:
	fclose(fp);
	return 0;
}
コード例 #26
0
ファイル: main.cpp プロジェクト: JackyChiu/Tic_Tac_Toe
int main(int argc, char* argv[])
{
    //make window
    if(!init())
    {
        cout<<"Init failed";
    }
    
    //loads buttons and sprites
    loadMedia();
    
    bool quit=false;
    
    int menubutton=0;
    
    SDL_Event e;
    
    
    while(quit!=true)
    {
        while(SDL_PollEvent(&e)!=0)
        {
            //quits game
            if(e.type==SDL_QUIT)
            {
                quit=true;
            }
            
            //clears board during game
            if(e.key.keysym.sym==SDLK_SPACE)
            {
                clearBoard();
            }
            
            //returns to menu
            if(e.key.keysym.sym==SDLK_ESCAPE)
            {
                if(startgame==true)
                {
                    gamecontinue=true;
                }
                startgame=false;
                aboutstate=false;
            }

            //click during game to play
            if(e.type==SDL_MOUSEBUTTONDOWN && startgame==true)
            {
                if(checkGameOver()==true)
                {
                    clearBoard();
                }
                
                else
                {
                    SDL_GetMouseState( &x, &y );
                    
                    tile=whichButton(x,y);
                }
            }
            
            //click either start or about
            if(e.type==SDL_MOUSEBUTTONDOWN && startgame==false)
            {
                SDL_GetMouseState( &x, &y );
                
                menubutton=whichButton(x,y);
                
                if(menubutton==0)
                {
                    startgame=true;
                }
                else if(menubutton==1)
                {
                    aboutstate=true;
                }
                
            }
        }
        
        if(startgame==false && aboutstate==false)
        {
            menu();
        }
        
        else if(startgame==false && aboutstate==true)
        {
            about();
        }
        
        else if(startgame==true && aboutstate==false)
        {
            SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
            SDL_RenderClear(gRenderer);
            
            play();
            drawboard();

            if(checkGameOver()==true)
            {
                announceWinner();
            }
            
        }

        SDL_RenderPresent(gRenderer);
        
        SDL_Delay(100);
        
    }
    
    close();
    
    return 0;
}
コード例 #27
0
ファイル: main.c プロジェクト: ryannorton/2048
int main(void) {
    int addScore, position, pauseSel;

    // Initializations
    PLL_Init();  			// Clock set at 80 MHz
    LCD_Init();
    Board_Init();
    Input_Init();
    DAC_Init();
    Random_Init(NVIC_ST_CURRENT_R);
    Timer2_Init(80000000); 	// time interrupt
    Timer1_Init(2000);		// sound interrupt
    EnableInterrupts();
    generateRandomTile();
    drawAllTiles();
    writeScore(0);
    writeHighscore(0);
    writeTime(0);
    displayHighestTile();

    while(1) {

        // draw arrow if ready
        if (arrowReady == 1) {
            // acknowledge flag
            arrowReady = 0;
            // draw arrow
            drawArrow();
        }

        // write time if ready
        if (timeReady == 1) {
            // acknowledge flag
            timeReady = 0;
            // write time
            writeTime(elapsedTime);
        }

        // Play mode and button1 is pushed
        if(Button1 && !pauseMode && !gameOver) {
            // Play sound
            playSound = 1;
            // shift and merge tiles towards arrow
            position = getSliderPosition();
            if (position == 1) {
                shiftLeft();
                addScore = mergeLeft();
                shiftLeft();
            }
            else if (position == 2) {
                shiftUp();
                addScore = mergeUp();
                shiftUp();
            }
            else if (position == 3) {
                shiftRight();
                addScore = mergeRight();
                shiftRight();
            }
            else {
                shiftDown();
                addScore = mergeDown();
                shiftDown();
            }

            eraseBoard();
            drawAllTiles();

            // update score
            score += addScore;
            addScore = 0;
            writeScore(score);
            displayHighestTile();

            // delay before adding new tile
            delay(200);

            // create new tile
            if (countEmptyTiles() != 0) {
                generateRandomTile();
            }
            drawAllTiles();

            // update highest tile image
            displayHighestTile();

            // check if game over
            if (checkGameOver() == 1) {
                gameOver = 1;
            }

            // unset flag
            Button1 = 0;
        }

        // button 2 is pause
        else if (Button2 && !gameOver && !pauseMode) {
            pauseMode = 1;
            pauseSel = 0;

            // disable arrow and timer
            NVIC_ST_CTRL_R = 0;
            TIMER2_CTL_R = 0x00000000;
            LCD_DrawFilledRect(prevX,prevY,20,20,BLACK);

            // draw pause mode screen
            drawPauseMode();

            // acknowledge button
            Button2 = 0;

            // wait until button is pushed
            while (pauseMode) {

                // Button 1 selects current pause selection button
                if (Button1) {

                    // acknowledge button
                    Button1 = 0;
                    Button2 = 0;
                    pauseMode = 0;

                    // if pause selection = "continue" (pauseSel = 0), continue with game
                    if (pauseSel == 0) {

                        // redraw screen
                        eraseBoard();
                        drawAllTiles();

                        // enable gameplay
                        NVIC_ST_CTRL_R = 0x07;
                        TIMER2_CTL_R = 0x00000001;
                    }

                    // if pause selection = "restart" (pauseSel = 0), end game
                    else if (pauseSel == 1) {
                        if (score > highscore) {
                            writeHighscore(score);
                        }
                        score = 0;
                        eraseScore();
                        writeScore(0);
                        clearBoard();
                        eraseBoard();
                        pauseMode = 0;
                        generateRandomTile();
                        drawAllTiles();
                        elapsedTime = 0;
                        eraseTime();
                        writeTime(0);
                        displayHighestTile();
                        NVIC_ST_CTRL_R = 0x07;
                        TIMER2_CTL_R = 0x00000001;
                    }
                }

                // Button 2 changes pause selection
                else if (Button2) {
                    Button2 = 0;
                    if (pauseSel == 0) {
                        pauseSel = 1;
                        LCD_DrawRect(144,112,58,16,BLACK);
                        LCD_DrawRect(222,112,51,16,WHITE);
                    }
                    else if (pauseSel == 1) {
                        pauseSel = 0;
                        LCD_DrawRect(222,112,51,16,BLACK);
                        LCD_DrawRect(144,112,58,16,WHITE);
                    }
                }
            }
        }

        // game over
        if (gameOver == 1) {
            NVIC_ST_CTRL_R = 0;
            TIMER2_CTL_R = 0x00000000;
            LCD_DrawFilledRect(156,38,100,20,BLACK);
            LCD_SetTextColor(255,255,240);
            LCD_Goto(30,5);
            printf("GAME OVER");
            while (Button1 == 0 && Button2 == 0) {}
            Button1 = 0;
            Button2 = 0;
            LCD_DrawFilledRect(prevX,prevY,20,20,BLACK);
            drawGameOver(score, elapsedTime);
            if (score > highscore) {
                writeHighscore(score);
                gameOverHighscore(score);
            }
            // wait til button is pushed
            while (Button1 == 0 && Button2 == 0) {}
            // acknowledge buttons
            Button1 = 0;
            Button2 = 0;
            // start new game
            score = 0;
            eraseScore();
            writeScore(0);
            clearBoard();
            eraseBoard();
            pauseMode = 0;
            generateRandomTile();
            drawAllTiles();
            elapsedTime = 0;
            eraseTime();
            writeTime(0);
            displayHighestTile();
            NVIC_ST_CTRL_R = 0x07;
            TIMER2_CTL_R = 0x00000001;

            // finish game over mode
            gameOver = 0;
        }
    }
}