• LQDOJ
  • Trang chủ
  • Bài tập
  • Bài nộp
  • Thành viên
  • Kỳ thi
  • Nhóm
  • Giới thiệu
    • Status
    • Khóa học
    • Đề xuất ý tưởng
    • Proposal Problem
    • Proposal Contest
    • Tools
    • Báo cáo tiêu cực
    • Báo cáo lỗi

Tiếng Việt

Tiếng Việt
English

Đăng nhập

Đăng ký

thiennguyen1k998

  • Giới thiệu
  • Bài tập
  • Bài nộp

Rating
-
Bài tập
206
Điểm
41263
Rating #
-
Điểm #
124

Giới thiệu

c++
C++
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace

public:
    Character(string n, int h, int p, int e) : name(n), health(h), power(p), energy(e) {}

    void attack(Character &opponent) {
        if (energy >= 10) {
            cout << name << " tan cong " << opponent.name << " voi mot don manh me!" << endl;
            opponent.health -= power;
            energy -= 10;
            cout << opponent.name << " con " << opponent.health << " mau." << endl;
        } else {
            cout << "Khong du nang luong de tan cong!" << endl;
        }
    }

    void recoverEnergy() {
        energy += 20;
        cout << name << " phuc hoi 20 nang luong!" << endl;
    }

    void showStats() {
        cout << "Ten: " << name << ", Mau: " << health << ", Suc manh: " << power << ", Nang luong: " << energy << endl;
    }

    bool isAlive() {
        return health > 0;
    }

    string getName() { return name; }
    int getHealth() { return health; }
    int getEnergy() { return energy; }
};

void showMenu() {
    cout << "1. Tan cong" << endl;
    cout << "2. Phuc hoi nang luong" << endl;
    cout << "3. Xem thong tin nhan vat" << endl;
    cout << "4. Thoat" << endl;
}

int main() {
    srand(time(0));

    Character goku("Goku", 100, 20, 50);
    Character vegeta("Vegeta", 100, 18, 50);

    while (goku.isAlive() && vegeta.isAlive()) {
        cout << "\n*** Tran chien giua " << goku.getName() << " va " << vegeta.getName() << " ***" << endl;
        showMenu();

        int choice;
        cout << "Chon hanh dong: ";
        cin >> choice;

        switch (choice) {
            case 1:
                goku.attack(vegeta);
                if (vegeta.isAlive()) {
                    vegeta.attack(goku);
                }
                break;

            case 2:
                goku.recoverEnergy();
                break;

            case 3:
                goku.showStats();
                vegeta.showStats();
                break;

            case 4:
                cout << "Thoat tro choi." << endl;
                return 0;

            default:
                cout << "Lua chon khong hop le." << endl;
                break;
        }

        if (!goku.isAlive()) {
            cout << goku.getName() << " da bi danh bai. " << vegeta.getName() << " chien thang!" << endl;
            break;
        }

        if (!vegeta.isAlive()) {
            cout << vegeta.getName() << " da bi danh bai. " << goku.getName() << " chien thang!" << endl;
            break;
        }
    }

    return 0;
}

acc chính
npns_TienDung

𝒞ℯ𝓁ℯ𝓈𝓉𝒾𝒶𝓁 ℰ𝓂𝓅𝓇ℯ𝓈𝓈 ℴ𝒻 𝓉𝒽ℯ 𝒮𝒾𝓁𝓋ℯ𝓇 ℳℴℴ𝓃𝓁𝒾ℊ𝒽𝓉
𝔼𝕞𝕓𝕖𝕣𝕨𝕚𝕟𝕘 ℙ𝕙𝕠𝕖𝕟𝕚𝕩 𝕠𝕗 𝕥𝕙𝕖 𝔽𝕚𝕖𝕣𝕪 ℍ𝕠𝕣𝕚𝕫𝕠𝕟
𝓞𝓫𝓼𝓲𝓭𝓲𝓪𝓷 𝓥𝓪𝓵𝓴𝔂𝓻𝓲𝓮 𝓸𝓯 𝓽𝓱𝓮 𝓢𝓽𝓸𝓻𝓶𝔂 𝓟𝓮𝓪𝓴𝓼
D̷u̷s̷k̷b̷l̷a̷d̷e̷ ̷A̷s̷s̷a̷s̷s̷i̷n̷ ̷o̷f̷ ̷t̷h̷e̷ ̷W̷h̷i̷s̷p̷e̷r̷i̷n̷g̷ ̷S̷h̷a̷d̷o̷w̷s̷


«    »
Thứ 2
Thứ 3
Thứ 4
Thứ 5
Thứ 6
Thứ 7
CN
Ít
Nhiều

proudly powered by DMOJ| developed by LQDJudge team