case STATE2:
if (num == 2)
{
current_state = STATE3; // 用户输入对了一步,STATE走一步
}
else
{
current_state = STATE1;
}
break;
case STATE3:
if (num == 3)
{
current_state = STATE4; // 用户输入对了一步,STATE走一步
}
else
{
current_state = STATE1;
}
break;
case STATE4:
if (num == 4)
{
current_state = STATE5; // 用户输入对了一步,STATE走一步
}
else
{
current_state = STATE1;
}
break;
case STATE5:
if (num == 5)
{
current_state = STATE6; // 用户输入对了一步,STATE走一步
}
else
{
current_state = STATE1;
}
break;
case STATE6:
if (num == 6)
{
current_state = STATE7; // 用户输入对了一步,STATE走一步
}
else
{
current_state = STATE1;
}
break;
default:
current_state = STATE1;
}
if (current_state == STATE7)
{
printf("锁开了.");
break;
}
}
return 0;
}
实际输出结果:
请输入密码,密码正确开锁.
1
num = 1.
2
num = 2.
3
num = 3.
4
num = 4.
5
num = 5.
6
num = 6.
锁开了.
五、总结:
今天的文章仅仅只是简单的一个入门。更深入的学习,个人觉得根据实际开发需求再去深入,暂时把握好自己的重心,不要盲目跟从。