QtDesignPatterns/statepattern/interface.h

42 lines
711 B
C
Raw Normal View History

2024-02-06 17:21:37 +08:00
#include "context.h"
#include <string>
#include <iostream>
using namespace std;
class State
{
public:
State(){}
virtual ~State(){}
virtual void doAction(Context *context) = 0;
virtual string getString() = 0;
};
class StartState: public State
{
public:
void doAction(Context *context)
{
cout << "Player is in start state" << endl;
context->setState(this);
}
string getString()
{
return "Start State";
}
};
class StopState: public State
{
public:
void doAction(Context *context)
{
cout << "Player is in stop state" << endl;
context->setState(this);
}
string getString()
{
return "Stop State";
}
};