C++ 状态机
来源:互联网 发布:淘宝火拼下架 编辑:程序博客网 时间:2024/06/07 06:49
#include "stdlib.h"
#include <iostream>
#include <map>
#include "conio.h"
using namespace std;
enum SateID
{
char_a=0,
char_b=0,
char_c=0,
};
class baseState
{
public:
virtual void getChar()=0;
};
class StateA
{
public:
virtual void getChar()
{
cout<<"A State "<<endl;
}
protected:
private:
};
class StateB
{
public:
virtual void getChar()
{
cout<<"B State "<<endl;
}
protected:
private:
};
class StateC
{
public:
virtual void getChar()
{
cout<<"C State "<<endl;
}
protected:
private:
};
class StateEngic
{
public:
void init()
{
baseState* p=(baseState*)(new StateA());
m_pbaseArr.insert(make_pair('a',p));
p=(baseState*)(new StateB());
m_pbaseArr.insert(make_pair('b',p));
p=(baseState*)(new StateC());
m_pbaseArr.insert(make_pair('c',p));
}
void ChangeState()
{
cout<<"StateEngic State "<<endl;
char ch;
while (1)
{
ch=getch();
if (ch=='q')
{
break;
}
else if (m_pbaseArr.find(ch)!=m_pbaseArr.end())
{
m_pbaseArr.find(ch)->second->getChar();
}
}
}
protected:
baseState* m_pState;
map<char,baseState*> m_pbaseArr;
private:
};
int main()
{
StateEngic StateInstace;
StateInstace.init();
StateInstace.ChangeState();
system("pause");
return 0;
}
#include <iostream>
#include <map>
#include "conio.h"
using namespace std;
enum SateID
{
char_a=0,
char_b=0,
char_c=0,
};
class baseState
{
public:
virtual void getChar()=0;
};
class StateA
{
public:
virtual void getChar()
{
cout<<"A State "<<endl;
}
protected:
private:
};
class StateB
{
public:
virtual void getChar()
{
cout<<"B State "<<endl;
}
protected:
private:
};
class StateC
{
public:
virtual void getChar()
{
cout<<"C State "<<endl;
}
protected:
private:
};
class StateEngic
{
public:
void init()
{
baseState* p=(baseState*)(new StateA());
m_pbaseArr.insert(make_pair('a',p));
p=(baseState*)(new StateB());
m_pbaseArr.insert(make_pair('b',p));
p=(baseState*)(new StateC());
m_pbaseArr.insert(make_pair('c',p));
}
void ChangeState()
{
cout<<"StateEngic State "<<endl;
char ch;
while (1)
{
ch=getch();
if (ch=='q')
{
break;
}
else if (m_pbaseArr.find(ch)!=m_pbaseArr.end())
{
m_pbaseArr.find(ch)->second->getChar();
}
}
}
protected:
baseState* m_pState;
map<char,baseState*> m_pbaseArr;
private:
};
int main()
{
StateEngic StateInstace;
StateInstace.init();
StateInstace.ChangeState();
system("pause");
return 0;
}
阅读全文
0 0
- c语言状态机编程
- c语言注释---状态机
- c语言 状态机
- C语言实现状态机
- 状态机C语言
- C语言状态机学习
- C语言状态机的实现
- 状态机的c语言编程
- C语言最优状态机规范
- 【步兵 c++】实例讲解 状态机
- 状态机的C语言编程
- 状态机的c语言编程
- 状态机
- 状态机
- 状态机
- 状态机
- 状态机
- 状态机
- 数据结构之队列(设计并实现一个自己的队列:循环数组+扩容策略)
- Android测试和调试的一些学习笔记
- 刹那繁华
- Linux80端口被占用tomcat服务起不来
- 【leedcode】392. Is Subsequence
- C++ 状态机
- Apicloud开发新闻类App实战项目-老孟编程
- SpringBoot项目的云服务器部署
- 文章标题
- Java中的向下转型和向上转型理解
- vue-router使用history的配置问题
- 欢迎使用CSDN-markdown编辑器
- Java中部分技术点的出现---个人的思索。。。。。
- Meterial Design 的activity转场效果