Untitled
unknown
plain_text
a year ago
2.4 kB
7
Indexable
#include <iostream>
#include <vector>
#include <string>
class Level {
public:
std::string description;
std::string challengeCode; // Code the player must write
bool isCompleted;
Level(std::string desc, std::string code)
: description(desc), challengeCode(code), isCompleted(false) {}
void display() {
std::cout << "Level: " << description << std::endl;
std::cout << "Challenge: Write code to " << challengeCode << std::endl;
}
void complete() {
isCompleted = true;
std::cout << "Congratulations! Level completed." << std::endl;
}
};
class Player {
public:
std::string name;
int currentLevel;
Player(std::string playerName) : name(playerName), currentLevel(0) {}
void advanceLevel() {
currentLevel++;
std::cout << name << " has advanced to level " << currentLevel << "!" << std::endl;
}
};
class Game {
private:
std::vector<Level> levels;
Player player;
public:
Game(std::string playerName) : player(playerName) {
// Create some levels
levels.push_back(Level("Learn Variables", "Declare a variable."));
levels.push_back(Level("Master Loops", "Use a loop to repeat actions."));
levels.push_back(Level("Understand Functions", "Create a function to solve a problem."));
}
void start() {
std::cout << "Welcome to Code Quest, " << player.name << "!" << std::endl;
while (player.currentLevel < levels.size()) {
levels[player.currentLevel].display();
// Simulate player writing code (here we'll just simulate a correct answer)
std::string playerCode;
std::cout << "Enter your code (simulated): ";
std::getline(std::cin, playerCode); // For actual code, you'd need to implement a way to validate
// Here we assume the player gets it right for demonstration
levels[player.currentLevel].complete();
player.advanceLevel();
}
std::cout << "You've completed all levels! Well done!" << std::endl;
}
};
int main() {
std::string playerName;
std::cout << "Enter your name: ";
std::getline(std::cin, playerName);
Game game(playerName);
game.start();
return 0;
}
Editor is loading...
Leave a Comment