#include <iostream>
#include <vector>
#include <conio.h> // Para _getch()
#include <windows.h> // Para Sleep()
using namespace std;
class Game {private:
vector<vector<char>> board;
int pacmanX, pacmanY;
int score;
public:
Game() : pacmanX(1), pacmanY(1), score(0) { board = { {'#', '#', '#', '#', '#', '#', '#', '#', '#', '#'}, {'#', ' ', ' ', ' ', '#', ' ', ' ', ' ', ' ', '#'}, {'#', ' ', '#', ' ', '#', ' ', '#', '#', ' ', '#'}, {'#', ' ', '#', ' ', ' ', ' ', ' ', '#', ' ', '#'}, {'#', ' ', '#', '#', '#', '#', ' ', '#', ' ', '#'}, {'#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#'}, {'#', '#', '#', '#', '#', '#', '#', '#', '#', '#'} };
}
void draw() { system("cls"); // Limpiar la consola for (const auto& row : board) { for (const auto& cell : row) { cout << cell;
}
cout << endl;
}
cout << "Score: " << score << endl;
}
void movePacman(char direction) { int newX = pacmanX;
int newY = pacmanY;
if (direction == 'w') newX--;
else if (direction == 's') newX++;
else if (direction == 'a') newY--;
else if (direction == 'd') newY++;
if (board[newX][newY] != '#') { if (board[newX][newY] == ' ') { score++;
}
board[pacmanX][pacmanY] = ' ';
pacmanX = newX;
pacmanY = newY;
board[pacmanX][pacmanY] = 'P'; // P para Pac-Man
}
}
void run() { board[pacmanX][pacmanY] = 'P'; // Inicializar Pac-Man en la posición
while (true) { draw();
if (_kbhit()) { char ch = _getch();
movePacman(ch);
}
Sleep(100); // Controlar la velocidad del juego
}
}
};
int main() { Game game;
game.run();
return 0;
}