Пример #1
0
void MainWindow::createGame()
{
    ui->actionNew_Game->setDisabled(true);
    bool ok;
    unsigned nbPlayers;
    unsigned gridSideSize;
    bool setupOk = false;
    while(!setupOk) {
        nbPlayers = (unsigned)QInputDialog::getInt(this, tr("New game"),
                                                   tr("Choose number of players (2 or 4) :"), 2, 2, 4, 2, &ok);
        gridSideSize = (unsigned)QInputDialog::getInt(this, tr("New game"),
                                                      tr("Choose size of grid (5 to 19 of uneven numbers) :"), 5, 5, 19, 2, &ok);
        if (ok) {
            try {
                game= new Game (gridSideSize);
                game->setNbPlayer(nbPlayers);
                game->addPlayer(nbPlayers);
                game->setCurrentPlayer(0);
                disableBtnGame();
                this->enableAllButtons();
                updatePlayerInfo();
                setupOk = true;
            }catch (invalid_argument &e) {
                QMessageBox::information(this, "ERROR", "Number of players or the size is incorrect !");
            }
        }
    }
    GameGUI *gui= new GameGUI(game);
    gui->show();
}
Пример #2
0
void GameScene::betting(int player, int type, int amount)
{
	if(type == TYPE_CALL || type == TYPE_DOUBLE)
	{
		totalBetting += amount;
		player_info[player].betting(type, amount);

		char szAmount[128];
		sprintf(szAmount, "%d$", amount);

		CCLabelTTF* ttf = CCLabelTTF::create(szAmount, "Helvetica", 38);
		ttf->setColor(ccc3(200, 200, 0));
		ttf->setPosition(ccp(player_slot[player]->getPositionX(), player_slot[player]->getPositionY()));
		addChild(ttf, 3);

		CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
		CCAction* pAction = CCSequence::create(CCSpawn::create(CCMoveTo::create(0.5f, ccp(visibleSize.width/2, visibleSize.height/2)), CCFadeOut::create(0.5f), NULL), 
			CCRemoveSelf::create(), 
			NULL);
		ttf->runAction(pAction);
	}
	else
	{
		player_info[player].betting(type, 0);
	}

	updatePlayerInfo();

	CCLabelTTF* ttf = CCLabelTTF::create("", "Helvetica", 50);
	if(type == TYPE_CALL) {
		ttf->setColor(ccc3(30, 30, 255));
		ttf->setString("Call");
	} else if(type == TYPE_DOUBLE) {
		ttf->setColor(ccc3(255, 255, 255));
		ttf->setString("Double");
	} else if(type == TYPE_CHECK) {
		ttf->setColor(ccc3(0, 255, 0));
		ttf->setString("Check");
	} else if(type == TYPE_DIE) {
		ttf->setColor(ccc3(255, 0, 0));
		ttf->setString("DIE");
	}

	if(player == 1)
		ttf->setAnchorPoint(ccp(0, 0));
	else if(player == 3)
		ttf->setAnchorPoint(ccp(1.0, 0));
	
	ttf->setPosition(ccp(pLabelPlayerMoney[player]->getPositionX(), pLabelPlayerMoney[player]->getPositionY()));


	addChild(ttf, 3);

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCAction* pAction = CCSequence::create(CCSpawn::create(CCMoveBy::create(0.5f, ccp(0, 30)), CCFadeOut::create(0.5f), NULL), 
		CCSpawn::create(CCRemoveSelf::create(), CCCallFunc::create(this, callfunc_selector(GameScene::updateTableInfo)), NULL), 
		NULL);
	ttf->runAction(pAction);
}
Пример #3
0
void MainWindow::movementSW()
{
    if(game->getBoard().diagonalMovementPossible(game->getPlayerAt(game->getCurrentPlayer())->getPawn(),Direction::SUD_WEST)){
        game->movePawn(Direction::SUD_WEST,game->getPlayerAt(game->getCurrentPlayer())->getPawn());
        alertWinner();
        game->nextPlayer();
        updatePlayerInfo();
    }else{
        alertIncorrectMovement();
    }
}
Пример #4
0
void MainWindow::movementUp()
{
    if(game->getBoard().movementPossible(game->getPlayerAt(game->getCurrentPlayer())->getPawn(),Direction::NORTH)){
        game->movePawn(Direction::NORTH,game->getPlayerAt(game->getCurrentPlayer())->getPawn());
        alertWinner();
        game->nextPlayer();
        updatePlayerInfo();       
    }else{
        alertIncorrectMovement();
    }
}
Пример #5
0
CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo,
                                   Gender gender):
    Window(_("Select Character")),
    mCharInfo(charInfo),
    mGender(gender),
    mCharSelected(false)
{
    // Control that shows the Player
    mBeingBox = new BeingBox();
    mBeingBox->setWidth(74);

    mNameLabel = new Label(strprintf(_("Name: %s"), ""));
    mLevelLabel = new Label(strprintf(_("Level: %d"), 0));
    mJobLevelLabel = new Label(strprintf(_("Job Level: %d"), 0));
    mMoneyLabel = new Label(strprintf(_("Money: %d"), 0));

    const std::string tempString = getFont()->getWidth(_("New")) <
                                   getFont()->getWidth(_("Delete")) ?
                                   _("Delete") : _("New");

    mPreviousButton = new Button(_("Previous"), "previous", this);
    mNextButton = new Button(_("Next"), "next", this);
    mNewDelCharButton = new Button(tempString, "newdel", this);
    mSelectButton = new Button(_("OK"), "ok", this);
    mCancelButton = new Button(_("Cancel"), "cancel", this);

    ContainerPlacer place;
    place = getPlacer(0, 0);

    place(0, 0, mBeingBox, 1, 6).setPadding(3);
    place(1, 0, mNewDelCharButton);
    place(1, 1, mNameLabel, 5);
    place(1, 2, mLevelLabel, 5);
    place(1, 3, mJobLevelLabel, 5);
    place(1, 4, mMoneyLabel, 5);
    place.getCell().matchColWidth(1, 4);
    place = getPlacer(0, 2);
    place(0, 0, mPreviousButton);
    place(1, 0, mNextButton);
    place(4, 0, mCancelButton);
    place(5, 0, mSelectButton);

    reflowLayout(250, 0);

    setLocationRelativeTo(getParent());
    setVisible(true);
    mSelectButton->requestFocus();
    updatePlayerInfo();
}
Пример #6
0
void MainWindow::placeWall()
{
    int column = (int)ui->btnCol->value();
    int row = (int) ui->btnRow->value();
    pair <int,int> pos {row,column};
    Alignement align;
    if(ui->btnVerti->isChecked()){
        align=Alignement::VERTICAL;
    }else{
        align=Alignement::HORIZONTAL;
    }
    if(game->getBoard().placementWallPossible(pos,align)){
        game->placeWall(pos,align,game->getPlayerAt(game->getCurrentPlayer()));
        game->nextPlayer();
        updatePlayerInfo();
    }else{
        alertIncorrectWallPlacement();
    }
}
Пример #7
0
bool GameScene::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
	updatePlayerInfo();

	return true;
}
Пример #8
0
void GameScene::onMessage(CCObject* obj)
{
	CCArray* arr = (CCArray*)obj;
	int typ =((CCInteger*)arr->data->arr[0])->getValue();
	string data = string(((CCString*)arr->data->arr[1])->getCString());

	if(typ == TYPE_JOIN)
	{
		vector<string> elems;
		stringstream ss(data);
		string item;
		while (std::getline(ss, item, '|')) {
			elems.push_back(item);
		}
		ss.flush();

		int idx = atoi(elems[0].c_str());

		player_info[idx].setPlayerName(elems[1]);
		player_info[idx].setMoney(atoi(elems[2].c_str()));

		updatePlayerInfo();
	} 
	else if(typ == TYPE_STATUS)
	{
		mStatus = atoi(data.c_str());
	}
	else if(typ == TYPE_DRAW_CARD)
	{
		vector<string> elems;
		stringstream ss(data);
		string item;
		while (std::getline(ss, item, '|')) {
			elems.push_back(item);
		}
		ss.flush();

		if(elems[0] == "t")
		{
			for(int i=1; i<elems.size(); i++)
				common_slot->setCard(i-1, elems[i].c_str());
		}
		else
		{
			int idx = atoi(elems[0].c_str());
			for(int i=1; i<elems.size(); i++)
				player_slot[idx]->setCard(i-1, elems[i].c_str());
		}
	} 
	else if(typ == TYPE_MYTURN)
	{
		showPopup(atoi(data.c_str()));
	}
	else if(typ == TYPE_BETTING)
	{
		vector<string> elems;
		stringstream ss(data);
		string item;
		while (std::getline(ss, item, '|')) {
			elems.push_back(item);
		}
		ss.flush();

		betting(atoi(elems[0].c_str()), atoi(elems[1].c_str()), atoi(elems[2].c_str()));
	}
}
Пример #9
0
void CharSelectDialog::logic()
{
    updatePlayerInfo();
}