Exemplo n.º 1
0
void Combat::buttonClickedSlot()
{
    if(!rollDice)
    {
        //we can apply the hit now
        for(int i = 0; i < playerCount.size(); i++)
        {
            if(getPlayerTurn() == playerCount.at(i))
            {
                int hitPoint = playerHitPoint.at(i)->objectName().toInt();
                //get the button
                QObject *button = sender();
                QWidget *widget = qobject_cast<QWidget *>(button);
                //get the player rack
                QObject *PlayerRack = button->parent();
                int playerWidgetID = PlayerRack->objectName().toInt();
                if(playerWidgetID == getPlayerTurn())
                {
                    Message("Warning", "You can't remove your things");
                } else {
                    //remove the thing and button
                    if(hitPoint == 0)
                    {
                        //not enough hitpoint,change to next player
                        popMessageBox();
                        Message("Warning", "Don't have hitpoint!");
                        break;
                    } else {
                        //remove the things
                        int ThingID = button->objectName().toInt();
                        removePlayerThingFromID(ThingID);
                        //delete the button
                        delete widget;
                        //refresh the playerhitpoint label
                        playerHitPoint.at(i)->setObjectName(QString::number(hitPoint-1));
                        QString temp ="Player " + QString::number(playerCount.at(i)) +  " HitPoint : " + playerHitPoint.at(i)->objectName();
                        playerHitPoint.at(i)->setText(temp);
                        //check if the hitPoint become to 0
                        if(!checkAllPlayerRack()&&(hitPoint == 1))
                        {
                            popMessageBox();
                            break;
                        }
                    }
                }
            }
        }

    }

}
Exemplo n.º 2
0
void Combat::retreatButtonSlot()
{
    //retreat
    if(isCombat)
    {
        for(int i = 0; i < playerCount.size(); i++)
        {
            if(getPlayerTurn() == playerCount.at(i))
            {
                //clear the widget
                qDeleteAll(vertical_layout->itemAtPosition(i,0)->widget()->children());
                delete vertical_layout->itemAtPosition(i,0)->widget();
                //special income and building can't send back
                //send back all the other creature
                QList<Thing*> result;
                for(int j = 0; j < getThingsFromPlayerID(getPlayerTurn()).size();)
                {
                    if(getThingsFromPlayerID(getPlayerTurn()).at(j)->getType() != 7)
                    {
                        result.push_back(getThingsFromPlayerID(getPlayerTurn()).at(j));
                        switch (getPlayerTurn()) {
                        case 1:
                            PlayerOneThing.removeAt(j);
                            break;
                        case 2:
                            PlayerTwoThing.removeAt(j);
                            break;
                        case 3:
                            PlayerThreeThing.removeAt(j);
                            break;
                        case 4:
                            PlayerFourThing.removeAt(j);
                            break;
                        default:
                            break;
                        }
                    } else {
                        j++;
                    }
                }
                emit(sendRetretThingSignal(result,getPlayerTurn()));
                //refresh the layout of the combat
                vertical_layout->addWidget(createPlayerBox(getThingsFromPlayerID(getPlayerTurn()),getPlayerTurn()),i,0);
                //check the winning
                if(!checkAllPlayerRack())
                {
                    //change to nextplayer
                    popMessageBox();
                }
                break;
            }
        }
    } else {
        //exploration lose
        Message("Sorry", "You lose the exploration");
        deleteALLWidget();
        this->close();
        emit(changeNextPlayerSingal());
    }
}
Exemplo n.º 3
0
void Combat::buildingButtonClickSlot()
{
    //when we want eliminate the buidling
    if(!rollDice)
    {
        if(getPlayerTurn() == ownPlayer)
        {
            Message("Warning", "You can't remove your things");
        } else {
            for(int i = 0; i < playerCount.size(); i++)
            {
                if(getPlayerTurn() == playerCount.at(i))
                {
                    int hitPoint = playerHitPoint.at(i)->objectName().toInt();
                    if(hitPoint == 0)
                    {
                        Message("Warning", "Don't have hitpoint!");
                        popMessageBox();
                    } else {
                        if(getBuildingValue() == 0)
                        {
                            Message("Warning", "Building is neutral");
                        } else {
                            //reduce one level of the building
                            setBuildingValue(getBuildingValue()-1);
                            //refresh the playerhitpoint label
                            playerHitPoint.at(i)->setObjectName(QString::number(hitPoint-1));
                            QString temp ="Player " + QString::number(playerCount.at(i)) +  " HitPoint : " + playerHitPoint.at(i)->objectName();
                            playerHitPoint.at(i)->setText(temp);
                            //check if the building value become to 0
                            if(getBuildingValue() == 0)
                            {
                                //change the building to nertral
                                QString temp = "border-image: url(" + getHexBuilding()->getNeutralURL();
                                buildingButton->setStyleSheet(temp + ")");
                            }
                            //check for winning the game
                            checkAllPlayerRack();
                        }
                    }
                }
            }
        }
    }
}
Exemplo n.º 4
0
void Server::startGame()
{
    deck = new Deck();
    for (int card = 0; card < 3; card++) {
        for(int i = 0; i < numberOfPlayers; i++) {
            players[i]->setCards(card, deck->newCard());
        }
    }
    players[getPlayerTurn()]->yourTurn();
}
Exemplo n.º 5
0
// This procedure has issues in some place, need re-check
void Server::restartGame()
{
    QString code;
    QString message;
    code == "02";
    message = code + "nothing";
    for (int i = 0; i < numberOfPlayers; i++){
        players[i]->sendMessage(message);
    }
    int add;
    playerTurn = 0;
    round = 0;
    hand++;
    if (hand > numberOfPlayers-1)
        hand = 0;
    deck->suffleDeck();
    add = 0;
    for (int card = 0; card < 3; card++) {
        for(int i = 0; i < numberOfPlayers; i++) {
            if (hand == 0) {
                players[i]->setCards(card, deck->newCard());
            }
            if (hand == 1) {
                add = i + hand;
                if (add > 3) {
                    players[add-4]->setCards(card, deck->newCard());
                } else {
                    players[add]->setCards(card, deck->newCard());
                }
            }
            if (hand == 2) {
                add = i + hand;
                if (add > 3) {
                    players[add-4]->setCards(card, deck->newCard());
                } else {
                    players[add]->setCards(card, deck->newCard());
                }
            }
            if (hand == 3) {
                add = i + hand;
                if (add > 3) {
                    players[add-4]->setCards(card, deck->newCard());
                } else {
                    players[add]->setCards(card, deck->newCard());
                }
            }
        }
    }
    setPlayerTurn(hand);
    players[getPlayerTurn()]->yourTurn();
}
Exemplo n.º 6
0
void Combat::updateDiceValueSlot(int tempDice)
{
    diceValue = tempDice;
    QList<Thing*> tempThings = getThingsFromPlayerID(getPlayerTurn());
    int addCount = 0;
    switch (getCombatTurn()) {
    case 1:
        //magic combat turn
        for(int i = 0; i < tempThings.size(); i++)
        {
            if(tempThings.at(i)->getType() == 5
                    ||tempThings.at(i)->getType() == 8
                    ||tempThings.at(i)->getType() == 9)
            {
                if(tempThings.at(i)->getAttackValue() >= diceValue)
                {
                    //increase the hipoint of this player
                    addCount++;
                }
            }
        }
        //all the buidling count
        if(getHexBuilding())
        {
            if((ownPlayer == getPlayerTurn()) && (getHexBuilding()->getID() == 4))
            {
                if(diceValue <= getBuildingValue())
                {
                    addCount++;
                }
            }
        }
        break;
    case 2:
        //ranged combat turn
        for(int i = 0; i < tempThings.size(); i++)
        {
            if(tempThings.at(i)->getType() == 4
                    ||tempThings.at(i)->getType() == 9)
            {
                if(tempThings.at(i)->getAttackValue() >= diceValue)
                {
                    //increase the hipoint of this player
                    addCount++;
                }
            }
        }
        //all the buidling count
        if(getHexBuilding())
        {
            if((ownPlayer == getPlayerTurn()) && (getHexBuilding()->getID() == 3))
            {
                if(diceValue <= getBuildingValue())
                {
                    addCount++;
                }
            }
        }
        break;
    case 3:
        //melee combat turn
        for(int i = 0; i < tempThings.size(); i++)
        {
            //normal things
            if(tempThings.at(i)->getType() == 1 ||
                    tempThings.at(i)->getType() == 2 ||
                    tempThings.at(i)->getType() == 7)
            {
                if(tempThings.at(i)->getAttackValue() >= diceValue)
                {
                    //increase the hipoint of this player
                    addCount++;
                }
            }
            //Charging creature
            if(tempThings.at(i)->getType() == 3)
            {
                if(tempThings.at(i)->getAttackValue() >= diceValue)
                {
                    addCount = addCount + 2;
                }
            }
        }
        //all the buidling count
        if(getHexBuilding())
        {
            if((ownPlayer == getPlayerTurn()) && (getHexBuilding()->getID() == 1||getHexBuilding()->getID() == 1))
            {
                if(diceValue <= getBuildingValue())
                {
                    addCount++;
                }
            }
        }
        break;
    default:
        break;
    }
    //update the hitpoint label
    for(int i = 0; i < playerCount.size(); i++)
    {
        if(playerCount.at(i) == getPlayerTurn())
        {
            //refresh the playerhitpoint label
            int hitpoint = playerHitPoint.at(i)->objectName().toInt() + addCount;
            playerHitPoint.at(i)->setObjectName(QString::number(hitpoint));
            QString temp = "Player " + QString::number(playerCount.at(i)) + " HitPoint : " + playerHitPoint.at(i)->objectName();
            playerHitPoint.at(i)->setText(temp);
        }
    }
    //change to next player
    popMessageBox();
}
Exemplo n.º 7
0
void Combat::changePlayerTurnSlot(QAbstractButton* temp)
{
    //refresh the dice value
    dice->refreshLabel();

    if(getPlayerTurn() == playerCount.at(playerCount.size()-1))
    {
        //all the player finish rolling dice, begin to apply hits.vice versa
        if(rollDice)
        {
            if(getCombatTurn() <= 3)
            {
                rollDice = false;
                //start to apply hit
                dice->hide();
            } else {
                //start next combat turn
                setCombatTurn(1);
                dice->show();
                button->hide();
                button2->hide();
            }
        } else {
            rollDice = true;
            if(getCombatTurn() == 3)
            {
                setCombatTurn(getCombatTurn()+1);
                button->show();
                button2->show();
            } else {
                //start to roll dice
                dice->show();
                //start next combat turn
                setCombatTurn(getCombatTurn()+1);
            }
        }
        //change to next player
        setPlayerTurn(playerCount.at(0));
        if(getThingsFromPlayerID(getPlayerTurn()).size() == 0)
        {
            if(ownPlayer == getPlayerTurn())
            {
                if(getBuildingValue() == 0)
                {
                    //change to next player
                    changePlayerTurnSlot(temp);
                }
            } else {
                //change to next player
                changePlayerTurnSlot(temp);
            }
        }
    } else {
        //change to next player
        for(int i = 0; i < playerCount.size(); i++)
        {
            if(playerCount.at(i) == getPlayerTurn())
            {
                setPlayerTurn(playerCount.at(i+1));
                if(getThingsFromPlayerID(getPlayerTurn()).size() == 0)
                {
                    if(ownPlayer == getPlayerTurn())
                    {
                        if(getBuildingValue() == 0)
                        {
                            //change to next player
                            changePlayerTurnSlot(temp);
                        }
                    } else {
                        //change to next player
                        changePlayerTurnSlot(temp);
                    }
                }
                break;
            }
        }
    }

}