0% found this document useful (0 votes)
63 views

AIMBOT.cpp

Uploaded by

ujidej
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

AIMBOT.cpp

Uploaded by

ujidej
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <iostream>

#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>

class Enemy {
public:
Enemy(std::string name) : name(name), health(100) {}

void takeDamage(int damage) {


health -= damage;
if (health < 0) health = 0;
}

bool isAlive() const {


return health > 0;
}

std::string getName() const {


return name;
}

int getHealth() const {


return health;
}

private:
std::string name;
int health;
};

class Game {
public:
Game() {
std::srand(static_cast<unsigned int>(std::time(0))); // Seed for random
number
}

void start() {
std::cout << "Welcome to the Shooting Game!" << std::endl;

// Create enemies
enemies.push_back(Enemy("Zombie"));
enemies.push_back(Enemy("Alien"));
enemies.push_back(Enemy("Robot"));

int lockedEnemyIndex = -1;

// Game loop
while (true) {
if (enemies.empty()) {
std::cout << "You have defeated all the enemies!" << std::endl;
break;
}

std::cout << "\nEnemies remaining:" << std::endl;


for (size_t i = 0; i < enemies.size(); ++i) {
if (enemies[i].isAlive()) {
std::cout << i + 1 << ". " << enemies[i].getName()
<< " (Health: " << enemies[i].getHealth() << ")" <<
std::endl;
}
}

if (lockedEnemyIndex != -1 && enemies[lockedEnemyIndex].isAlive()) {


attackEnemy(lockedEnemyIndex);
} else {
std::cout << "Choose an enemy to attack (1-" << enemies.size() <<
") or lock on (0): ";
int choice;
std::cin >> choice;

if (choice == 0) {
std::cout << "Choose an enemy to lock on (1-" << enemies.size()
<< "): ";
int lockChoice;
std::cin >> lockChoice;
if (lockChoice >= 1 && lockChoice <= enemies.size() &&
enemies[lockChoice - 1].isAlive()) {
lockedEnemyIndex = lockChoice - 1; // Lưu chỉ số kẻ thù bị
ghim cổ
std::cout << "Locked on to " <<
enemies[lockedEnemyIndex].getName() << "!" << std::endl;
} else {
std::cout << "Invalid choice, try again." << std::endl;
}
} else if (choice < 1 || choice > enemies.size() || !enemies[choice
- 1].isAlive()) {
std::cout << "Invalid choice, try again." << std::endl;
continue;
} else {
attackEnemy(choice - 1);
}
}

if (lockedEnemyIndex != -1 && !enemies[lockedEnemyIndex].isAlive()) {


std::cout << enemies[lockedEnemyIndex].getName() << " has been
defeated!" << std::endl;
lockedEnemyIndex = -1; //
}
}
}

private:
std::vector<Enemy> enemies;

void attackEnemy(int index) {


int damage = std::rand() % 50 + 1; // Random damage between 1 and 50
enemies[index].takeDamage(damage);
std::cout << "You dealt " << damage << " damage to " <<
enemies[index].getName() << "!" << std::endl;
}
};

int main() {
Game game;
game.start();
return 0;
}

You might also like