Created
March 3, 2022 06:55
-
-
Save yknishidate/4a7813c47f3fcf4ab378dd468e29a322 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
class Command | |
{ | |
public: | |
virtual ~Command() {} | |
virtual void execute() = 0; | |
}; | |
class JumpCommand : public Command | |
{ | |
public: | |
void execute() override | |
{ | |
std::cout << "jump!" << std::endl; | |
} | |
}; | |
class FireCommand : public Command | |
{ | |
public: | |
void execute() override | |
{ | |
std::cout << "fire!" << std::endl; | |
} | |
}; | |
int main() | |
{ | |
Command* xCommand = new JumpCommand(); | |
Command* yCommand = new FireCommand(); | |
std::string input; | |
while(true){ | |
std::cin >> input; | |
if (input == "X") xCommand->execute(); | |
if (input == "Y") yCommand->execute(); | |
if (input == "quit") break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment