42 lines
711 B
C
42 lines
711 B
C
|
#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";
|
||
|
}
|
||
|
};
|