📜  KUNG FU HUSTLE - C++ (1)

📅  最后修改于: 2023-12-03 15:02:33.771000             🧑  作者: Mango

KUNG FU HUSTLE - C++

Kung Fu Hustle is a popular movie that combines action, comedy, and martial arts. This movie has inspired many programmers to create games and programs based on its theme. In this article, we will discuss a C++ program based on the Kung Fu Hustle movie.

Introduction

Our C++ program based on Kung Fu Hustle will simulate a fight between two characters named "Sing" and "The Beast." In this program, we will use object-oriented programming principles to create two classes - "Character" and "Combat" - to represent the characters and the combat.

Character Class

The "Character" class will represent the characters in the Kung Fu Hustle movie. This class will have the following private data members:

  • name (string): represents the name of the character
  • health (int): represents the health or life points of the character
  • attack (int): represents the attack power of the character

The "Character" class will have the following public member functions:

Constructor
Character(string name, int health, int attack)

This constructor will initialize the private data members of the "Character" class.

Getters
string getName()
int getHealth()
int getAttack()

These getters will return the private data members of the "Character" class.

Attack
void attack(Character& character)

This function will simulate the character attacking another character. The target character will receive damage based on the attacking character's attack power.

Take Damage
void takeDamage(int damage)

This function will reduce the health of the character based on the damage received.

Combat Class

The "Combat" class will represent the fight between two characters in the Kung Fu Hustle movie. This class will have the following private data members:

  • player1 (Character): represents the first player
  • player2 (Character): represents the second player

The "Combat" class will have the following public member functions:

Constructor
Combat(Character& player1, Character& player2)

This constructor will initialize the private data members of the "Combat" class.

Getters
Character getPlayer1()
Character getPlayer2()

These getters will return the private data members of the "Combat" class.

Fight
void fight()

This function will simulate the fight between two characters. The first player to reach 0 health points will lose the fight.

Conclusion

In this article, we have discussed a C++ program based on the Kung Fu Hustle movie. We have used object-oriented programming principles to create two classes - "Character" and "Combat" - to represent the characters and the combat. This program is a basic example of how to use classes and objects in C++.