|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
C语言制作表白神器-LOVE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
//3维数组,存放LOVE字符
char LETTER[][5][5] = {
{
0, 1, 0, 0, 0,
0, 1, 0, 0, 0,
0, 1, 0, 0, 0,
0, 1, 0, 0, 0,
0, 1, 1, 1, 0
},
{
0, 0, 1, 0, 0,
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 0, 1, 0, 0
},
{
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 0, 1, 0, 0
},
{
0, 1, 1, 1, 0,
0, 1, 0, 0, 0,
0, 1, 1, 1, 0,
0, 1, 0, 0, 0,
0, 1, 1, 1, 0
}
};
int status = 1;//控制线程函数的运行状态
int speed = 500;//字符变换的速度
HANDLE hout;//控制台标准输出句柄
CONSOLE_SCREEN_BUFFER_INFO csbi;//控制台屏幕缓冲区信息结构体
char *symbol[] = {"☆", "★", "△", "※", "▲", "■"};//□ ◆用这些特殊字符组成LOVE中的各个字母
WORD attr[] = {
FOREGROUND_RED | FOREGROUND_INTENSITY, //红色
FOREGROUND_GREEN | FOREGROUND_INTENSITY,//绿色
FOREGROUND_BLUE | FOREGROUND_INTENSITY,//蓝色
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY//白色
};
//在屏幕上画出LOVE
void DrawLove()
{
int i, j, c;
COORD pos;//光标的坐标
DWORD dwLen;
for(c = 0; c < sizeof LETTER / sizeof LETTER[0]; ++c)
{
for(i = 0; i < 5; ++i)
{
pos.X = c * 5 * 2;
pos.Y = i;
SetConsoleCursorPosition(hout, pos);
for(j = 0; j < 5; ++j)
{
if(LETTER[c][i][j])
{
//获取当前屏幕缓冲区信息
GetConsoleScreenBufferInfo(hout, &csbi);
printf("%s", symbol[rand() %
(sizeof symbol / sizeof symbol[0])]);
//用指定的颜色填充字符
FillConsoleOutputAttribute(hout, attr[rand() %
(sizeof attr / sizeof attr[0])], 2,
csbi.dwCursorPosition, &dwLen);
}
else
{
printf(" ");//打印两个空格
}
}
}
}
}
//线程的处理函数
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
while(1)
{
if(status)
{
DrawLove();
Sleep(speed);
}
}
return 0;
}
int main()
{
HANDLE hThread;
int inChar;
hout = GetStdHandle(STD_OUTPUT_HANDLE);
srand((unsigned)time(0));
hThread = CreateThread(NULL, 0, ThreadProc, NULL, 0, NULL);
CloseHandle(hThread);
while(1)
{
inChar = getch();
if('q' == inChar)
{
break;
}
else if('w' == inChar && speed > 50)
speed -= 50;
else if('s' == inChar && speed < 500)
speed += 50;
else if('p' == inChar)
status = 0;
else if('c' == inChar)
status = 1;
}
return 0;
}
getch改成getchar就可以了没啥其他大的毛病
图片是你的程序的效果
|
|