/*
cout << " *****************game by ring light**************************" << endl;
cout << " **** 一个全开的循环串联灯链 为节约资源等待你的关灯动作******" << endl;
cout << " *****提示: 当选择一盏灯时,该灯及旁边的灯状态均会发生变化****" << endl;
cout << " *****************game by ring light**************************" << endl;
破解办法居然简单在于逐一从第一个点开关所有的灯就能实现所有的灯从全亮到全灭
*/
#include
using namespace std;
struct node
{
int data;
node *prev;
node *next;
public:
node():data(1),prev(NULL),next(NULL){}
node(int a):data(a),prev(NULL),next(NULL){}
};
void creat(node *list)
{
int n=20;
node *tmp;node *tail;
while(n--)
{
if(list->next == NULL)
{
tmp = new node(1);
tmp->prev = list;
tmp->next = list;
list->prev = tmp;
list->next = tmp;
tail=tmp;
}
else
{
tmp = new node(1);
list->next->prev = tmp;
tmp->next = list->next;
tmp->prev = tail;
tail->next=tmp;
list->next = tmp;
}
}
}
void show(node *list)
{
int n=20;
node *p = list->next;
while(n--)
{
//cout<<"["<<20-n<<"] "<data<<" ";
cout<data<<" ";
p=p->next;
}
cout<next;
while(x-- -1)
{
p=p->next;
}
p->prev->data=1-p->prev->data;
p->data=1-p->data;
p->next->data=1-p->next->data;
}
int check(node *list)
{
int n=20;
node *p = list->next;
while(n--)
{
if(p->data==1)break;
p=p->next;
}
return 1-p->data;
}
void play(node *list)
{
int x=1;
int n=40;
while(n--)
{
cout<<"40步解灯谜之"<<40-n<<"步:(输入0~20)"<>x;
_play(list,x);
show(list);
if(n==20&&check(list))break;
}
}
int main()
{
cout << " *****************game by ring light**************************" << endl;
cout << " **** 一个全开的循环串联灯链 为节约资源等待你的关灯动作******" << endl;
cout << " *****提示: 当选择一盏灯时,该灯及旁边的灯状态均会发生变化****" << endl;
cout << " *****************game by ring light**************************" << endl;
node list;
creat(&list); show(&list);
play(&list);
show(&list);
cout << " wzzx" << endl;
return 0;
}
本文题目:小代码链表实现关灯游戏2
网页链接:
http://cdxtjz.com/article/iipjgs.html