C++教程:俄罗斯方块源码+注释+解答
俄罗斯方块(Tetris,源码俄文:Тетрис)是源码一款电视游戏机和掌上游戏机游戏,它由俄罗斯人阿列克谢·帕基特诺夫发明,源码js异步加载 源码故得此名。源码
顾名思义,源码飞莱相册源码俄罗斯方块自然是源码PHP挖矿赚钱源码俄罗斯人发明的。这人叫阿列克谢·帕基特诺夫(Алексей Пажитнов 英文:Alexey Pazhitnov)。源码俄罗斯方块原名是源码俄语Тетрис(英语是Tetris),这个名字来源于希腊语tetra,源码意思是源码"四",而游戏的源码作者最喜欢网球(tennis)。于是源码,他把两个词tetra和tennis合而为一,源码600套网站源码命名为Tetris,源码这也就是源码木凡影视源码俄罗斯方块名字的由来。
俄罗斯方块源码
#include
#include
#include
/*#define SUSHU
oid ab(int *b, int *c){
int p = *b;
*b = *c; //c = b = b = p =
*c = p;
}
*/
#include
char LEETER[4][5][5] = {
{
0, 1, 0, 0, 0, //表示字母L
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, //表示字母O
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, //表示字母V
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, //表示字母E
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 = ; //控制字符变换的速度
HANDLE hout; //控制台标准输出的句柄
CONSOLE_SCREEN_BUFFER_INFO csbi; //控制台屏幕缓冲区信息结构体
char *symbol[] = { "☆", "★", "●", "◆", "▲", "■", "□" }; //字母符号☆mm
WORD attrbute[] = {
FOREGROUND_RED | FOREGROUND_INTENSITY, //红色
FOREGROUND_BLUE | FOREGROUND_INTENSITY, //蓝色
FOREGROUND_GREEN | FOREGROUND_INTENSITY //绿色
};
void drawLetter()
{
int i, j, c;
COORD pos; //光标的坐标
DWORD len; //实际填充字符属性的个数
for (c = 0; c < sizeof LEETER / sizeof LEETER[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 (LEETER[c][i][j])
{
GetConsoleScreenBufferInfo(hout, &csbi);
printf("%s", symbol[rand() % (sizeof symbol / sizeof symbol[0])]);
FillConsoleOutputAttribute(hout,
attrbute[rand() % (sizeof attrbute / sizeof attrbute[0])],
2, csbi.dwCursorPosition, &len);
}
else
{
printf(" "); //两个空格
}
}
}
}
}
DWORD WINAPI ThreadProc(LPVOID lpParam) //线程处理函数
{
while (1)
{
if (status)
{
drawLetter(); //画字符
Sleep(speed);
}
}
return 0;
}
int main()
{
int ctrl; //控制游戏
hout = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hThread; //线程句柄
srand((unsigned)time(0)); //初始化随机种子
hThread = CreateThread(NULL, 0, ThreadProc, NULL, 0, NULL);
CloseHandle(hThread);
while (1)
{
ctrl = _getch();
if (ctrl == 'q')
break;
else if (ctrl == 'w')
{
if (speed < )
speed += ;
}
else if (ctrl == 's')
{
if (speed > )
speed -= ;
}
else if (ctrl == 'p')
status = 0;
else if (ctrl == 'c')
status = 1;
}
return 0;
本文摘自: cdtedu.com/c/course/...,如有侵权,请联系我!
å ³äºcè¯è¨ä¸çrand()
å 为éæºæ°ç§åä¸å
ç¨srand设置ä¸ä¸ªä¸åçéæºæ°ç§åå³å¯
ä¾ç¨
/* rand example: guess the number */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
int iSecret, iGuess;
/* initialize random seed: */
srand ( time(NULL) );
/* generate secret number: */
iSecret = rand() % + 1;
do {
printf ("Guess the number (1 to ): ");
scanf ("%d",&iGuess);
if (iSecret<iGuess) puts ("The secret number is lower");
else if (iSecret>iGuess) puts ("The secret number is higher");
} while (iSecret!=iGuess);
puts ("Congratulations!");
return 0;
}
2024-11-23 07:02
2024-11-23 06:55
2024-11-23 06:01
2024-11-23 05:50
2024-11-23 04:53