数据结构
在这个游戏中,假定每个人都是一个节点,这样有利于程序的理解。
[cpp] view plaincopyprint
template
struct Node{
List_entry code; // 存储每个人手中 密码
List_entry iposition; // 存储每个人所处的 位置
Node *next;
Node();
Node(List_entry a, List_entry b, Node *link=NULL);
};
template
class Joeph_list{
public:
Joeph_list();
int size() const;
bool empty() const;
void clear();
Error_code retrieve(int position, List_entry &x, List_entry &y) const;
Error_code replace(int position, const List_entry &x, const List_entry &y);
Error_code remove(int position, List_entry &x, List_entry &y);
Error_code insert(int position, const List_entry &x, const List_entry &y);
~Joeph_list();
protected:
int count;
void Init(); // 初始化线性表
Node *head;
Node *set_position(int position) const;
// 返回指向第position个结点的指针
};
template
struct Node{
List_entry code; // 存储每个人手中 密码
List_entry iposition; // 存储每个人所处的 位置
Node *next;
Node();
Node(List_entry a, List_entry b, Node *link=NULL);
};
template
class Joeph_list{
public:
Joeph_list();
int size() const;
bool empty() const;
void clear();
Error_code retrieve(int position, List_entry &x, List_entry &y) const;
Error_code replace(int position, const List_entry &x, const List_entry &y);
Error_code remove(int position, List_entry &x, List_entry &y);
Error_code insert(int position, const List_entry &x, const List_entry &y);
~Joeph_list();
protected:
int count;
void Init(); // 初始化线性表
Node *head;
Node *set_position(int position) const;
// 返回指向第position个结点的指针
};
Node结构:表示实现Joeph_list以及List表的结点
Joeph_list类:储存游戏中玩家座位、密码等信息的数据结构
List类:以链表的方式存储图片等数据结构
全局对象game:SimpleWidow的窗口输出游戏过程
Listtu;Listshu;Listpeople;分别存储游戏参与者报数、所持密码、和游戏参与者的图片。
全局函数:
void Baoshu(int p,int s); 用以显示游戏参与者报数的效果
void Yizou(int p,int m); 用以移走报到数的游戏参与者
void Code(int m); 用以更新密码信息
void Jieshu(); 结束游戏
项目测试
1、游戏开始,初始m为6,从第一个玩家开始自动报数,报到数的人出列
2、以出列人手中的密码为密码(不大于6)继续游戏

3、直到所有人出列,游戏结束

项目演示
