Beispiel #1
0
int main(void)
{
	BfsStatu init;
	Act *turn[ACT];
	BfsStatu *pos, tmp;
	int i;

	initTurn(turn);
	while(cin >> A >> B >> N){
		queue.init();
		init.set(0, 0, -1, -1);
		queue.enq(init);
		while((pos=queue.deq()) != 0){
			for(i=0; i<ACT; i++){
				tmp = turn[i]->change(*pos);
				tmp.act = i;
				if(queue.check(tmp))
					queue.enq(tmp);
				if(queue.find(tmp)){
					queue.output();
					goto done;
				}
			}
		}
		done:
			;
	}
	return 0;
}
Beispiel #2
0
GameScene::GameScene(SceneRunner* const sceneRunner, std::shared_ptr<GameDb> gameDb, bool winOn4, bool reuseLost)
	:Scene(sceneRunner){
	//initialize variables
	::gameDb = gameDb;
	::winOn4 = winOn4;
	for(int i=0; i<uncollectedCardsNum; i++)
		uncolldectedCards[i] = nullptr;
	gameLogic = std::shared_ptr<GameLogic>(new GameLogic(gameDb.get(), winOn4, reuseLost));
	playerNum = gameLogic->getPlayers().size();

	//attach event handllers
	gameLogic->drawCardHook = [=](Card card){ this->drawCard(card); };
	gameLogic->collectCardHook = [=](std::vector<Player> oldStates, Card card){ this->collectCard(oldStates, card); };
	gameLogic->lostHook = [=](){ this->cardsLost(); };
	gameLogic->nextTurnHook = [=](){
		GameScene* DIS = this;
		this->add(new Timer([=]{ DIS->initTurn(); }, nextTurnDelay));
	};
	gameLogic->gameEndHook = [=](){
		GameScene* DIS = this;
		this->add(new Timer([=]{ DIS->gameEnd(); }, nextTurnDelay));
	};

	//add background
	SpriteObject* background = new SpriteObject(Vec2(0, 0), Vec2(800, 650), "./assets/background.png", Vec2(0, 0), Vec2(800, 600));
	this->add( new Animator<double>(background->tileIndex.x, 1e10, 1e10/50) );
	this->add(background);

	//construct game board
	gameBoardPanel = new Panel(Vec2(30, 205), Vec2(800, 270), Color(0, 0, 0, 0), 0, Color(0, 0, 0, 0));

	//add game board(background)
	SpriteObject* gameBoard = new SpriteObject(Vec2(-30, -35), Vec2(800, 270), "./assets/gamescene/board.png");
	gameBoardPanel->add(gameBoard);

	//add flip and collect buttons
	flipMoreButton = new Button(Vec2(0, 40), Vec2(100, 30), "More", Color(1,1,0,1), Color(0.5,0.5,0.6,1));
	collectCardsButton = new Button(Vec2(0, 110), Vec2(100, 30), "Collect", Color(1,1,0,1), Color(0.5,0.5,0.6,1));
	flipMoreButton->action = [=](){ gameLogic->drawCard(); };
	collectCardsButton->action = [=](){ gameLogic->collectCards(); };
	gameBoardPanel->add(flipMoreButton);
	gameBoardPanel->add(collectCardsButton);

	//add card deck
	cardDeckSprite = new SpriteObject(Vec2(gameBoardPanel->size.x-220, 22), Vec2(100, 150), "./assets/gamescene/cards.png", Vec2(0, 0), Vec2(100, 150));
	gameBoardPanel->add(cardDeckSprite);

	cardDeckNumText = new Text(cardDeckSprite->pos+cardDeckSprite->size*0.5-Vec2(50/2, 30/2), Vec2(50, 30), "", 20, Color(1, 1, 1, 1), Text::CENTER);
	this->updateDeckCardsNum();
	gameBoardPanel->add(cardDeckNumText);

	this->add(gameBoardPanel);

	for(int i=0; i<playerNum; i++){
		sp[i].statusPlate = new Panel(platePos[i], Vec2(800, 270), Color(0, 0, 0, 0), 0, Color(0, 0, 0, 0));
		sp[i].statusPlateBackground
			= new SpriteObject(Vec2(0, 0), Vec2(735, 90), "./assets/gamescene/statusPlate.png");
		sp[i].statusPlate->add(sp[i].statusPlateBackground);

		Text* playerName = new Text(Vec2(10, 0), Vec2(0, 0), gameDb->getUserName(i), 20);
		sp[i].statusPlate->add(playerName);
		
		this->add(sp[i].statusPlate);
	}

	stopBgm();
	initTurn();
}