前言

因为在学校不像在家一样“自由”,所以几乎一个月没有碰这个游戏了,之后为了简化,又把一些卡牌都去掉了。。最后的效果也不是很满意,总之对我来说现在能做完就不错了,至少可以对战了。。

功能实现

  1. 持续状态
  2. 特殊卡牌

持续状态

绘制

我们需要将使用的持续卡牌的状态绘制出来,并让玩家属性与其交互

std::vector<int> playerStatus;                //玩家状态的数组
void drawStatus(RenderWindow* window);        //绘制卡牌状态
Texture tPlayerStatus[20];                    //状态纹理
statusBtn sPlayerStatus[20];                //状态精灵

所以准备好必要的图片

将其加载

for (int i = 0; i < 20; i++) {
        stringstream ss;
        ss << "./data/status/card" << i << ".png";
        tPlayerStatus[i].loadFromFile(ss.str());
        sPlayerStatus[i].setTexture(tPlayerStatus[i]);
        sPlayerStatus[i].setScale(0.3f, 0.3f);
    }

然后依次绘制

void Player::drawStatus(RenderWindow* window) {
    for (int i = 0; i < playerStatus.size(); i++) {
        sPlayerStatus[playerStatus[i]].setPosition(325 + i * 60.f, 790);
        window->draw(sPlayerStatus[playerStatus[i]]);
    }
}

使用持续卡牌后状态就会绘制在必要位置

数值

以下函数为了方便对特定卡牌进行测试

void Player::cheat_getCard(Card card[], int num) {
    if (handCardNums == handMaxNum) {
        return;
    }
    for (int i = 0; i < handMaxNum; i++) {
        if (handCards[i] == &nullCard) {
            if (card[num].cardState == card[num].cardPool) {                                    //如果卡牌在卡池里就抽牌
                card[num].cardState = card[num].handPool;                                        //卡牌移到手牌区
                handCardNums += 1;                                                //手牌数加一
                handCards[i] = &card[num];                                        //手牌数组赋值
            }
        }
    }
}

装备分为被动型触发和主动型触发,所以写两个不同的函数

被动触发

void Player::statusUpdate(Player* enemy, int turn) {
    for (int i = 0; i < playerStatus.size(); i++) {
        switch (playerStatus[i]) {
            case 0:                                                            //累计造成4伤害加1点生命值
                addUpDamageAble = true;
                if (addUpDamage / 4 >= 1) {
                    hp += addUpDamage / 4;
                    addUpDamage %= 4;
                }
                break;
            case 1:
                if (turn == 1 && countDamage == 0) {
                    addUpDamage += hp / 10;
                    enemy->hp -= hp / 10;
                    countDamage = 1;
                } else if (turn == 0) {
                    countDamage = 0;
                }
                break;
            default:
                break;
        }
    }
}

主动触发

void cardManager::playerStatus(Player* player1, Card* card, Player* player2) {
    for (int i = 0; i < player1->playerStatus.size(); i++) {
        switch (player1->playerStatus[i]) {
            case 2:
                if (card->cardType == card->magic) {
                    player2->hp -= 1;
                }
            default:
                break;
        }
    }
}
Last modification:February 12th, 2021 at 06:16 am