summaryrefslogtreecommitdiffstats
path: root/examples/statemachine/errorstateplugins/spin_ai/spin_ai.h
blob: 7336640268731f1295aca70fd44e53298e9d9291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef SPIN_AI_H
#define SPIN_AI_H

#include <errorstate/plugin.h>
#include <errorstate/tank.h>

#include <QObject>
#include <QState>

class SpinState: public QState
{
    Q_OBJECT
public:
    SpinState(Tank *tank, QState *parent) : QState(parent), m_tank(tank)
    {
    }

public slots:
    void spin() 
    {
        m_tank->turn(90.0);
    }

protected:
    void onEntry()
    {
        connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin()));
        spin();        
    }

private:
    Tank *m_tank;

};

class SpinAi: public QObject, public Plugin
{
    Q_OBJECT
    Q_INTERFACES(Plugin)
public:
    virtual QState *create(QState *parentState, Tank *tank);
};

#endif