请问这个代码为什么不能在DEVc++里运行
#include <iostream>
#include <cstdlib>
#include <ctime>
const int MAP_WIDTH = 10;
const int MAP_HEIGHT = 10;
class Character {
public:
Character(int startX, int startY) : x(startX), y(startY), health(100) {}
int getX() const {
return x;
}
int getY() const {
return y;
}
void move(int dx, int dy) {
if (x + dx >= 0 && x + dx < MAP_WIDTH) {
x += dx;
}
if (y + dy >= 0 && y + dy < MAP_HEIGHT) {
y += dy;
}
}
void attack(class Zombie& target);
bool isAlive() const {
return health > 0;
}
private:
int x;
int y;
int health;
};
class Zombie {
public:
Zombie(int startX, int startY) : x(startX), y(startY), health(50) {}
int getX() const {
return x;
}
int getY() const {
return y;
}
void moveTowards(const Character& target) {
int dx = target.getX() - x;
int dy = target.getY() - y;
if (dx < 0) {
x -= 1;
} else if (dx > 0) {
x += 1;
}
if (dy < 0) {
y -= 1;
} else if (dy > 0) {
y += 1;
}
}
void attack(Character& target) {
target.health -= 15;
std::cout << "Zombie attacks! Target's health: " << target.health << std::endl;
}
bool isAlive() const {
return health > 0;
}
private:
int x;
int y;
int health;
};
void printMap(const Character& character, const Zombie& zombie) {
for (int i = 0; i < MAP_HEIGHT; i++) {
for (int j = 0; j < MAP_WIDTH; j++) {
if (i == character.getY() && j == character.getX()) {
std::cout << "C ";
} else if (i == zombie.getY() && j == zombie.getX()) {
std::cout << "Z ";
} else {
std::cout << ". ";
}
}
std::cout << std::endl;
}
}
void Character::attack(Zombie& target) {
target.health -= 20;
std::cout << "Character attacks! Target's health: " << target.health << std::endl;
if (!target.isAlive()) {
std::cout << "Zombie is dead!" << std::endl;
}
}
int main() {
std::srand(std::time(0));
Character character(2, 2);
Zombie zombie(7, 7);
while (character.isAlive() && zombie.isAlive()) {
printMap(character, zombie);
char action;
std::cout << "Enter action (w/a/s/d to move, q to quit): ";
std::cin >> action;
if (action == 'q') {
break;
}
int dx = 0, dy = 0;
if (action == 'w') {
dy = -1;
} else if (action == 'a') {
dx = -1;
} else if (action == 's') {
dy = 1;
} else if (action == 'd') {
dx = 1;
}
character.move(dx, dy);
zombie.moveTowards(character);
if (std::rand() % 2 == 0) {
character.attack(zombie);
} else {
zombie.attack(character);
}
}
std::cout << "Game over!" << std::endl;
return 0;
}
```c++
```