C语言猜字魔术

#include<iostream> 
#include<stdlib.h> 
using namespace std;

int main()
{
	while(1)
	{
		unsigned char ch[3]="",c;
		int j,sum = 0,t; //j为换行标志 ,t为产生的新汉字的操作数 
	
		cout << endl 
			 << " *************************************************************** " << endl
			 << " ****************    猜   字   小   魔   术    ***************** " << endl
			 << " *************************************************************** " << endl;
		
		ch[0] = 0XB0; //二进制为176,汉字起始 
		
		for(int k=0;k<6;k++)
		{
			t = 0X1 << k; //将二进制0x1左移k位 
			cout << endl << endl 
				 << " *************************************************************** " << endl;
			j=0;
			for(int i=0;i<128;i++)
			{
				ch[1] = 0X80 | i; //按规律获得汉字第二个字节 
				if(ch[1]&t) 
				{
					if(j%8==0)cout << endl;
					cout << "   " << ch << "   ";
					j++;
				}
			}
			cout << endl << endl 
				 << " *************************************************************** " 
				 << endl << endl;
			if(0 == k)
				cout << "  请记住其中的一个字,然后按Y或y " << endl << endl;
			else
				cout << "  请问你记住的字在这里吗?"<<endl 
					 << "  是请按Y或y,否则按N或n,游戏继续。"<< endl << endl;
			  
			cout << "  请选择: " ;
			cin >> c ;
			if(c == 'Y' || c == 'y') {
				sum += 0x1 << k;
			}
			system("cls");
		}
		ch[1] = 0xc0 | sum;
		cout << endl
		     << " *************************************************************** " << endl << endl
		     << "                     你记住的字是:" << ch << endl <<endl
		     << " *************************************************************** " << endl << endl
		     << "  是否继续?(按Y或y继续) " << endl
		     << "  请选择: " ;
		cin >> c ;
		if( !(c == 'Y' || c == 'y'))return 0; 
		system("cls");
	}
	return 0;
}

  

posted on 2011-12-17 16:14  悲笑菩提  阅读(309)  评论(0)    收藏  举报

导航