コード例 #1
0
void TwoPlayerSelectionScreen::buildScene()
{
    m_screenStack->pushScreen(ScreenID::GAME);
    sf::View oldView{ m_context.window->getView() };
    m_context.window->setView(m_context.guiView);
    m_guiEnvironment.createScene("assets/gui/two_player_game_selection.xml");
    m_context.window->setView(oldView);
    // Player 1
    m_p1KnightCheckBox = static_cast<gsf::CheckBoxWidget*>(
            m_guiEnvironment.getWidgetByID("checkBoxWidget_p1Knight"));
    m_p1RunnerCheckBox = static_cast<gsf::CheckBoxWidget*>(
            m_guiEnvironment.getWidgetByID("checkBoxWidget_p1Runner"));    
    m_p1WizardCheckBox = static_cast<gsf::CheckBoxWidget*>(
            m_guiEnvironment.getWidgetByID("checkBoxWidget_p1Wizard"));
    m_p1WarriorCheckBoxes.push_back(m_p1KnightCheckBox);
    m_p1WarriorCheckBoxes.push_back(m_p1RunnerCheckBox);
    m_p1WarriorCheckBoxes.push_back(m_p1WizardCheckBox);
    m_p1KnightCheckBox->setIsChecked(true);
    //m_player1WarriorCheckBoxes:  
    m_p1KnightCheckBox->setOnLeftClickListener(
            [this](gsf::Widget *widget, sf::Vector2f pos)
    {
        // CheckBox should be un uncheckable, so we set it to false by every click
        // so the checkbox chnage the state every time to true.
        m_p1KnightCheckBox->setIsChecked(false);
        if (!m_p1KnightCheckBox->isChecked())
        {
            deselectDevicesWhichAreNotGiven(widget, m_p1WarriorCheckBoxes);
        }
    });
    m_p1RunnerCheckBox->setOnLeftClickListener(
            [this](gsf::Widget *widget, sf::Vector2f pos)
    {
        m_p1RunnerCheckBox->setIsChecked(false);
        if (!m_p1RunnerCheckBox->isChecked())
        {
            deselectDevicesWhichAreNotGiven(widget, m_p1WarriorCheckBoxes);
        }
    });
    m_p1WizardCheckBox->setOnLeftClickListener(
            [this](gsf::Widget *widget, sf::Vector2f pos)
    {
        m_p1WizardCheckBox->setIsChecked(false);
        if (!m_p1WizardCheckBox->isChecked())
        {
            deselectDevicesWhichAreNotGiven(widget, m_p1WarriorCheckBoxes);
        }
    });

    // Player 2
    m_p2KnightCheckBox = static_cast<gsf::CheckBoxWidget*>(
            m_guiEnvironment.getWidgetByID("checkBoxWidget_p2Knight"));
    m_p2RunnerCheckBox = static_cast<gsf::CheckBoxWidget*>(
            m_guiEnvironment.getWidgetByID("checkBoxWidget_p2Runner"));    
    m_p2WizardCheckBox = static_cast<gsf::CheckBoxWidget*>(
            m_guiEnvironment.getWidgetByID("checkBoxWidget_p2Wizard"));
    m_p2WarriorCheckBoxes.push_back(m_p2KnightCheckBox);
    m_p2WarriorCheckBoxes.push_back(m_p2RunnerCheckBox);
    m_p2WarriorCheckBoxes.push_back(m_p2WizardCheckBox);

    m_p2KnightCheckBox->setIsChecked(true);
    m_p2KnightCheckBox->setOnLeftClickListener(
            [this](gsf::Widget *widget, sf::Vector2f pos)
    {
        m_p2KnightCheckBox->setIsChecked(false);
        if (!m_p2KnightCheckBox->isChecked())
        {
            deselectDevicesWhichAreNotGiven(widget, m_p2WarriorCheckBoxes);
        }
    });
    m_p2RunnerCheckBox->setOnLeftClickListener(
            [this](gsf::Widget *widget, sf::Vector2f pos)
    {
        m_p2RunnerCheckBox->setIsChecked(false);
        if (!m_p2RunnerCheckBox->isChecked())
        {
            deselectDevicesWhichAreNotGiven(widget, m_p2WarriorCheckBoxes);
        }
    });
    m_p2WizardCheckBox->setOnLeftClickListener(
            [this](gsf::Widget *widget, sf::Vector2f pos)
    {
        m_p2WizardCheckBox->setIsChecked(false);
        if (!m_p2WizardCheckBox->isChecked())
        {
            deselectDevicesWhichAreNotGiven(widget, m_p2WarriorCheckBoxes);
        }
    });
    // Level
    handleLevelLoading();

    // Buttons
    gsf::TextButtonWidget* startBtn{ static_cast<gsf::TextButtonWidget*>(
            m_guiEnvironment.getWidgetByID("textButtonWidget_start")) };
    startBtn->setOnLeftClickListener(
            [this](gsf::Widget *widget, sf::Vector2f pos)
    {
        std::string levelName{ m_levelListBox->currentText() };
        std::string levelID{ m_levels[levelName] };
        MainGameScreen::GameData gameData(
                MainGameScreen::GameMode::TWO_PLAYER,
                levelID, 
                getPlayer1WarriorType(),
                getPlayer2WarriorType());
        m_screenStack->registerScreen<MainGameScreen, 
            MainGameScreen::GameData>(ScreenID::GAME, gameData);
        m_screenStack->popScreen();
        m_screenStack->pushScreen(ScreenID::GAME);
    });

    gsf::TextButtonWidget* backBtn{ static_cast<gsf::TextButtonWidget*>(
            m_guiEnvironment.getWidgetByID("textButtonWidget_back")) };
    backBtn->setOnLeftClickListener(
            [this](gsf::Widget *widget, sf::Vector2f pos)
    {
        m_screenStack->popScreen();
        m_screenStack->pushScreen(ScreenID::MAINMENU);
    });
}
コード例 #2
0
ファイル: main.cpp プロジェクト: fengfenghuo/program
int main() {
	while (true) {
		uint16_t role_count = 0;
		uint16_t player_num = 0;
		menu();
		role_count = setGameRoleNum();

		if (role_count == 0) {
			cout << "结束游戏~ " << endl;
			return 0;
		}

		GameData gameData(role_count);
		gameData.shuffleCards();

		player_num = gameData.generateStatus(role_count);
		if (player_num < 0) {
			cout << "出错了,生成身份出错啦~" << endl;
			return ERROR_SYSTEM_ERROR;
		}

		PLAYERINFO * playerInfo = gameData.findPlayerInfoByNum(player_num);
		if (playerInfo == NULL) {
			cout << "你消失啦~,重新开始吧~" << endl;
			return ERROR_SYSTEM_ERROR;
		}
		cout << "你的身份是:" << viewRoleStatus(playerInfo->status) << "位于【" << player_num << "】号位" << endl;
		gameData.generateRoles();

		gameData.viewPlayersRole();
		gameData.startingCards();
		gameData.viewPlayerCards(player_num);

		cout << "游戏开始~" << endl << endl;
		while (!gameData.endingCondition(player_num)) {
			for (uint16_t i = 0; i < gameData.curRoleCount(); i++) {
				gameData.playerStartToPlay(i);
				int judge = gameData.judgeCards(i);
				if (judge < 0) {
					cout << "【" << i << "】号位判定牌错误" << endl;
					return ERROR_SYSTEM_ERROR;
				}

				if (judge == ERROR_TARGET_DEAD && gameData.endingCondition(player_num)) {
					break;
				}

				if (!gameData.dealCards(CARDS_DEALS, i)) {
					cout << "【" << i << "】号位抓牌错误" << endl;
					return ERROR_SYSTEM_ERROR;
				}

				int signal = 0;
				while (CLICARDS * cards = gameData.playCards(i)) {
					signal = gameData.applyCardPlay(cards, i);
					if (signal < 0) {
						cout << "【" << i << "】号位出牌错误" << endl;
						return ERROR_SYSTEM_ERROR;
					}
					if (signal == ERROR_TARGET_DEAD && gameData.endingCondition(player_num)) {
						break;
					}
				}

				if (signal == ERROR_TARGET_DEAD && gameData.endingCondition(player_num)) {
					break;
				}

				gameData.discardCards(i);
				gameData.playerEndToPlay(i);
			}
		}
	}
	
	/*uint16_t num = 0;
	cout << "请选择需要的人数:" << endl;
	cin >> num;

	uint16_t *array = new uint16_t[num];
	
	GameData gm;
	gm.generateStatus(num, array);

	for (uint16_t i = 0; i < num; i++) {
		cout << array[i] << "  ";
	}
	gm.shuffleCards();
	gm.viewPilesCards();
*/
	return 0;
}
コード例 #3
0
ファイル: MyBot.cpp プロジェクト: liquid-phynix/aicbot
int main(int argc, char**){
  srand(time(NULL));
#ifdef VDEBUG
  if(argc>1) vdebug=true;
#endif
  
  timeval startTime, endTime;
  std::cout.sync_with_stdio(0);
  std::unordered_map<std::string, int> gameParams;
  std::istringstream istream;
  std::string oneLine, tmpString;
  
  while(std::getline(std::cin, oneLine)){
    int paramValue;
    istream.clear();
    istream.str(oneLine);
    istream >> tmpString >> paramValue;
    if(tmpString=="ready") break;
    gameParams[tmpString] = paramValue;
  }
  _gameData gameData(gameParams["rows"],
                     gameParams["cols"],
                     gameParams["viewradius2"],
                     gameParams["attackradius2"]);
  go();
  
  while(std::getline(std::cin, oneLine)){
    gettimeofday(&startTime, NULL);
    istream.clear();
    istream.str(oneLine);
    istream >> tmpString;
    LOG("turn: " << gameData.turn);
    if(tmpString=="end"){break;};
    gameData.perTurnReset();
    while(getline(std::cin, oneLine)){
      istream.clear();
      istream.str(oneLine);
      pos f1f2;
      int f3=-1;
      istream >> tmpString >> f1f2.row >> f1f2.col >> f3;
      if(tmpString=="go") break;
      if(tmpString=="a"){gameData.receiveAnt(f1f2, f3); continue;};
      if(tmpString=="w"){gameData.receiveWater(f1f2); continue;};
      if(tmpString=="f"){gameData.receiveFood(f1f2); continue;};
      if(tmpString=="h"){gameData.receiveHill(f1f2, f3); continue;};
    }
    
    gameData.processAnts();
    gameData.processFood();
    gameData.processHills();
    

    
    gameData.assocFoodWithAnt();
    
    if(gameData.ant_count_water_mark>15){
      gameData.captureEnemyHills();
    }
    
    
    gameData.clusterAnts();
    gameData.computeClusterPrioritiesAndDispatch();    
    
    
    
    gameData.computeThreat();
    
    gameData.reachEnemy();
    
    

    
    
    gameData.wanderAntsAroundCompositeMod();
    
    

    if(vdebug){
      gameData.debugDraw();
      gameData.toPPM();
    }
    
    gameData.keepHillInSightOverride();
    
    gameData.outputCoordinates();
    gettimeofday(&endTime, NULL);
    LOG("turn took " << elapsedTime(startTime, endTime) << "ms");
    go();
  }
  return 0;
}