当前位置: 首页>>代码示例>>C++>>正文


C++ GameScene::initTurn方法代码示例

本文整理汇总了C++中GameScene::initTurn方法的典型用法代码示例。如果您正苦于以下问题:C++ GameScene::initTurn方法的具体用法?C++ GameScene::initTurn怎么用?C++ GameScene::initTurn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GameScene的用法示例。


在下文中一共展示了GameScene::initTurn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GameLogic

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();
}
开发者ID:SadaleNet,项目名称:projectTheGame,代码行数:68,代码来源:GameScene.cpp


注:本文中的GameScene::initTurn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。