Skip to content

Instantly share code, notes, and snippets.

@yknishidate
Created March 3, 2022 06:55
Show Gist options
  • Save yknishidate/4a7813c47f3fcf4ab378dd468e29a322 to your computer and use it in GitHub Desktop.
Save yknishidate/4a7813c47f3fcf4ab378dd468e29a322 to your computer and use it in GitHub Desktop.
#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