路过看看 。。。。
程序代码:#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define GRAPH_SIZE 30
#define POINT_SIZE 27
void Init();
void print();
void gotoXY(int, int);
POINT point[POINT_SIZE];
int main()
{
Init();
point[0].x = point[0].y = 1;
while (1)
{
print();
//游戏结束
if (point[0].y - point[0].x == GRAPH_SIZE % 2 &&
point[0].y + point[0].x == GRAPH_SIZE)
{
break;
}
for (int i = POINT_SIZE - 1; i > 0; i--)
{
point[i] = point[i - 1];
}
//下一步
if (point[0].x - point[0].y >= -1 &&
point[0].x + point[0].y <= GRAPH_SIZE - 1)
{
point[0].x++;
}
else if (point[0].x - point[0].y >= 1 &&
point[0].x + point[0].y >= GRAPH_SIZE)
{
point[0].y++;
}
else if (point[0].x - point[0].y <= 0 &&
point[0].x + point[0].y >= GRAPH_SIZE + 1)
{
point[0].x--;
}
else if (point[0].x - point[0].y <= -2 &&
point[0].x + point[0].y <= GRAPH_SIZE)
{
point[0].y--;
}
Sleep(100);
}
_getch();
return 0;
}
void Init()
{
CONSOLE_CURSOR_INFO cursor_info;
//光标不显示
cursor_info.bVisible = FALSE;
cursor_info.dwSize = 20;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
//画界面
for (int i = 0; i <= GRAPH_SIZE; i++)
{
printf("%s", "█");
}
for (int i = 1; i < GRAPH_SIZE; i++)
{
gotoXY(0, i), puts("█");
gotoXY(GRAPH_SIZE, i), puts("█");
}
for (int i = 0; i <= GRAPH_SIZE; i++)
{
printf("%s", "█");
}
}
void gotoXY(int x, int y)
{
COORD coord = {2 * x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void print()
{
for (int i = 0; i < POINT_SIZE - 1; i++)
{
if (!point[i].x || !point[i].y)
{
continue;
}
gotoXY(point[i].x, point[i].y);
putchar(0xa3), putchar(i + 'A' + 0x80);
}
//打印空格覆盖多出的字符 Z
if (!point[POINT_SIZE - 1].x || !point[POINT_SIZE - 1].y)
{
return;
}
gotoXY(point[POINT_SIZE - 1].x, point[POINT_SIZE - 1].y);
// putchar(0xa3), putchar(' ' + 0x80);
putchar(' '), putchar(' ');
}
程序代码:#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define GRAPH_SIZE 30
#define POINT_SIZE (GRAPH_SIZE * GRAPH_SIZE)
void Init();
void gotoXY(int, int);
POINT point[POINT_SIZE];
int main()
{
Init();
for (int i = 0; i < POINT_SIZE; i++)
{
gotoXY(point[i].x, point[i].y);
putchar(0xa3), putchar('*' + 0x80);
Sleep(100);
}
_getch();
return 0;
}
void Init()
{
CONSOLE_CURSOR_INFO cursor_info;
//光标不显示
cursor_info.bVisible = FALSE;
cursor_info.dwSize = 20;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
//画界面
for (int i = 0; i <= GRAPH_SIZE+1; i++)
{
printf("%s", "█");
}
for (int i = 1; i <= GRAPH_SIZE; i++)
{
gotoXY(0, i), puts("█");
gotoXY(GRAPH_SIZE+1, i), puts("█");
}
for (int i = 0; i <= GRAPH_SIZE+1; i++)
{
printf("%s", "█");
}
//900个点初始化
for (int i = 0; i < GRAPH_SIZE; i++)
for (int j = 0; j < GRAPH_SIZE; j++)
{
point[i*GRAPH_SIZE+j].x = i + 1;
point[i*GRAPH_SIZE+j].y = j + 1;
}
//使随机
srand(time(NULL));
for (int i = 0; i < POINT_SIZE; i++)
{
int tmp = rand() % POINT_SIZE;
POINT swap;
swap = point[i], point[i] = point[tmp], point[tmp] = swap;
}
}
void gotoXY(int x, int y)
{
COORD coord = {2 * x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
程序代码:#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define GRAPH_SIZE 30
void Init();
void gotoXY(int, int);
int X, Y;
int main()
{
Init();
while (1)
{
gotoXY(X, Y);
putchar(0xa3), putchar('*' + 0x80);
while (!_kbhit());
gotoXY(X, Y);
putchar(' '), putchar(' ');
char ch = _getch();
if ('q' == ch)
{
break;
}
switch (ch)
{
case 'a':
X = (X + GRAPH_SIZE - 2) % GRAPH_SIZE + 1;
break;
case 's':
Y = Y % GRAPH_SIZE + 1;
break;
case 'd':
X = X % GRAPH_SIZE + 1;
break;
case 'w':
Y = (Y + GRAPH_SIZE - 2) % GRAPH_SIZE + 1;
break;
default: break;
}
}
return 0;
}
void Init()
{
CONSOLE_CURSOR_INFO cursor_info;
//光标不显示
cursor_info.bVisible = FALSE;
cursor_info.dwSize = 20;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
//画界面
for (int i = 0; i <= GRAPH_SIZE+1; i++)
{
printf("%s", "█");
}
for (int i = 1; i <= GRAPH_SIZE; i++)
{
gotoXY(0, i), puts("█");
gotoXY(GRAPH_SIZE+1, i), puts("█");
}
for (int i = 0; i <= GRAPH_SIZE+1; i++)
{
printf("%s", "█");
}
//小孩位置初始化
srand(time(NULL));
X = rand() % GRAPH_SIZE;
Y = rand() % GRAPH_SIZE;
}
void gotoXY(int x, int y)
{
COORD coord = {2 * x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
程序代码:#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define GRAPH_SIZE 29
#define COUNT_MAX (GRAPH_SIZE / 2)
#define MIDDLE (GRAPH_SIZE - COUNT_MAX)
void Init();
void gotoXY(int, int);
int main()
{
Init();
for (int i = 1; i < MIDDLE; i++)
{
gotoXY(i + MIDDLE, MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
gotoXY(-i + MIDDLE, MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
Sleep(100);
}
for (int i = 1; i < MIDDLE; i++)
{
gotoXY(MIDDLE, i + MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
gotoXY(MIDDLE, -i + MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
Sleep(100);
}
for (int i = 1; i < MIDDLE; i++)
{
for (int j = i; j < MIDDLE; j++)
{
gotoXY(j + MIDDLE, -i + MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
gotoXY(-j + MIDDLE, -i + MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
gotoXY(j + MIDDLE, i + MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
gotoXY(-j + MIDDLE, i + MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
Sleep(100);
}
for (int j = i + 1; j < MIDDLE; j++)
{
gotoXY(i + MIDDLE, j + MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
gotoXY(i + MIDDLE, -j + MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
gotoXY(-i + MIDDLE, j + MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
gotoXY(-i + MIDDLE, -j + MIDDLE);
putchar(0xa3), putchar('*' + 0x80);
Sleep(100);
}
}
_getch();
return 0;
}
void Init()
{
CONSOLE_CURSOR_INFO cursor_info;
//光标不显示
cursor_info.bVisible = FALSE;
cursor_info.dwSize = 20;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
//画界面
for (int i = 0; i <= GRAPH_SIZE+1; i++)
{
printf("%s", "█");
}
for (int i = 1; i <= GRAPH_SIZE; i++)
{
gotoXY(0, i), puts("█");
gotoXY(GRAPH_SIZE+1, i), puts("█");
}
for (int i = 0; i <= GRAPH_SIZE+1; i++)
{
printf("%s", "█");
}
}
void gotoXY(int x, int y)
{
COORD coord = {2 * x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

程序代码:#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define GRAPH_HEIGHT 20
#define GRAPH_WEIGH 60
void Init();
void gotoXY(int, int);
char s[][GRAPH_WEIGH + 1] = {
" ",
" * * ** ******* * * * ",
" ** ** ** * * ** * * ",
" ** ** * * * * ***** ",
"** ******** *** * * **** **** * ",
"* * * * * * * * * * * ",
"**** * * * * * * * * * ",
" * ******** ***** ******* * ** ** * ********* ",
" ** * * *** * * ***** * ",
" ** * * * * ** * * ",
"** ** ***** ******* * *** * * * ",
"* * ******* * * * * * * * ** * * ",
"**** * * * * * * * * * ** * * * * * * ",
" * * * * * * * * * * ** * * ** * * ** ",
" * * ******* * * * ***** * * * *** ** ",
" ** * * * * * * * * * * * **** ** ** ** ",
" ** * * * * * * * * * * ** * * ** * ** ",
"** ** * * * * * * * * *** * * ** ***********",
"* ** * * * * * * ********** ** ******** * ** *"};
int main()
{
CHAR_INFO fill;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD c1 = {GRAPH_WEIGH * 2 + 4, 1};
COORD c2 = {2, 1};
COORD c3 = {GRAPH_WEIGH * 2, 1};
SMALL_RECT block1 = {2, 1, 3, GRAPH_HEIGHT};
SMALL_RECT block2 = {4, 1, GRAPH_WEIGH * 2 + 1, GRAPH_HEIGHT};
SMALL_RECT tmp = {GRAPH_WEIGH * 2 + 4, 1, GRAPH_WEIGH * 2 + 5, GRAPH_HEIGHT};
CONSOLE_SCREEN_BUFFER_INFO binfo;
GetConsoleScreenBufferInfo(hOut, &binfo);
fill.Attributes = binfo.wAttributes;
fill.Char.AsciiChar = ' ';
Init();
while (!_kbhit())
{
ScrollConsoleScreenBuffer(hOut, &block1, NULL, c1, &fill);
ScrollConsoleScreenBuffer(hOut, &block2, NULL, c2, &fill);
ScrollConsoleScreenBuffer(hOut, &tmp, NULL, c3, &fill);
Sleep(100);
}
return 0;
}
void Init()
{
//光标不显示
CONSOLE_CURSOR_INFO cursor_info;
cursor_info.bVisible = FALSE;
cursor_info.dwSize = 20;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
//改变控制台缓冲区大小
COORD coord = {128, 32};
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coord);
//画界面
for (int i = 0; i <= GRAPH_WEIGH+1; i++)
{
printf("%s", "█");
}
puts("");
for (int i = 0; i < GRAPH_HEIGHT; i++)
{
printf("%s", "█");
for (int j = 0; j < GRAPH_WEIGH; j++)
{
putchar(0xa3), putchar(s[i][j] + 0x80);
}
printf("%s\n", "█");
}
for (int i = 0; i <= GRAPH_WEIGH+1; i++)
{
printf("%s", "█");
}
}
