走过路过,欢迎大家对此代码给点建议,回个帖。
ybmq.rar
(42.42 KB)
以上是小作品的两张瞬间截图和可执行的exe文件
下面是我的代码,有什么好的建议还望多多指教。
#include "stdafx.h"
#include <time.h>
#include <stdio.h>
#include <windows.h>
//程序开头,我们定义了一个在屏幕中运动的点的结构类型:
struct move_point
{
int x,y;/*该点的位置,包括x坐标和y坐标*/
int xv, yv;/*该点在x轴、y轴的速度*/
}man1,man2,man3,man4;
//控制移动范围
#define heng1 78
#define heng2 0
#define zong1 24
#define zong2 0
#define N 80
HANDLE hConsole;
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(hConsole, coord);
}
void main()
{
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, 0x000c);
system("title 开心每一天!");
gotoxy(36,10);
printf("*");
Sleep(N);
gotoxy(25,10);
printf("*");
Sleep(N);
gotoxy(47,10);
printf("*");
Sleep(N);
gotoxy(34,8);
printf("*");
Sleep(N);
gotoxy(38,8);
printf("*");
Sleep(N);
gotoxy(30,7);
printf("*");
Sleep(N);
gotoxy(42,7);
printf("*");
Sleep(N);
gotoxy(27,8);
printf("*");
Sleep(N);
gotoxy(45,8);
printf("*");
Sleep(N);
gotoxy(25,11);
printf("*");
Sleep(N);
gotoxy(47,11);
printf("*");
Sleep(N);
int i,j,zz1,zz2,zz3,zz4;
for(i=1,j=1;i<6,j<6;i++,j++)
{
gotoxy(25+i,11+j);
printf("*");
Sleep(N);
}
gotoxy(32,17);
printf("*");
Sleep(N);
gotoxy(34,18);
printf("*");
Sleep(N);
man1.xv=1;man1.yv=1;man2.xv=-1;man2.yv=-1;
man3.xv=1;man3.yv=1;man4.xv=-1;man4.yv=-1;
SetConsoleTextAttribute(hConsole, 0x000e);
srand((unsigned)time(NULL));
zz1=rand()%101;
srand(zz1);
man1.x=rand()%75+2;man1.y=rand()%23+1;
gotoxy(man1.x, man1.y);
printf("御");
srand((unsigned)time(NULL));
zz2=rand()%102;
srand(zz2);
man2.x=rand()%75+2;man2.y=rand()%23+1;
gotoxy(man2.x, man2.y);
printf("坂");
srand((unsigned)time(NULL));
zz3=rand()%103;
srand(zz3);
man3.x=rand()%75+2;man3.y=rand()%23+1;
gotoxy(man3.x, man3.y);
printf("美");
srand((unsigned)time(NULL));
zz4=rand()%104;
srand(zz4);
man4.x=rand()%75+2;man4.y=rand()%23+1;
gotoxy(man4.x, man4.y);
printf("琴");
while(1)
{
SetConsoleTextAttribute(hConsole, 0x000c);
gotoxy(36,10);
printf("*");
gotoxy(25,10);
printf("*");
gotoxy(47,10);
printf("*");
gotoxy(34,8);
printf("*");
gotoxy(38,8);
printf("*");
gotoxy(30,7);
printf("*");
gotoxy(42,7);
printf("*");
gotoxy(27,8);
printf("*");
gotoxy(45,8);
printf("*");
gotoxy(25,11);
printf("*");
gotoxy(47,11);
printf("*");
int i,j;
for(i=1,j=1;i<6,j<6;i++,j++)
{
gotoxy(25+i,11+j);
printf("*");
}
gotoxy(32,17);
printf("*");
gotoxy(34,18);
printf("*");
for(i=1,j=1;i<6,j<6;i++,j++)
{
gotoxy(47-i,11+j);
printf("*");
}
gotoxy(40,17);
printf("*");
gotoxy(38,18);
printf("*");
gotoxy(36,19);
printf("*");
Sleep(100);
gotoxy(55,16);
printf("Happy everyday!");
SetConsoleTextAttribute(hConsole, 0x000a);
//1、擦去物体原来的轨迹:
gotoxy(man1.x, man1.y);/*把光标移到指定的坐标*/
printf(" ");/*输出空格,把先前的字符擦去*/
//2、然后我们让物体按其速度运动:
man1.x += man1.xv ;/*水平方向按x轴的速度运动*/
man1.y += man1.yv;/*垂直方向按y轴的速度运动*/
gotoxy(man1.x, man1.y);
printf("御");
if (man1.x >= heng1 || man1.x <= heng2)
{
man1.xv = -man1.xv;
}
if (man1.y >= zong1 || man1.y <= zong2)
{
man1.yv = -man1.yv;
}
Sleep(1);
//1、擦去物体原来的轨迹:
gotoxy(man2.x, man2.y);/*把光标移到指定的坐标*/
printf(" ");/*输出空格,把先前的字符擦去*/
//2、然后我们让物体按其速度运动:
man2.x += man2.xv ;/*水平方向按x轴的速度运动*/
man2.y += man2.yv;/*垂直方向按y轴的速度运动*/
gotoxy(man2.x, man2.y);
printf("坂");
if (man2.x >= heng1 || man2.x <= heng2)
{
man2.xv = -man2.xv;
}
if (man2.y >= zong1 || man2.y <= zong2)
{
man2.yv = -man2.yv;
}
Sleep(1);
//1、擦去物体原来的轨迹:
gotoxy(man3.x, man3.y);/*把光标移到指定的坐标*/
printf(" ");/*输出空格,把先前的字符擦去*/
//2、然后我们让物体按其速度运动:
man3.x += man3.xv ;/*水平方向按x轴的速度运动*/
man3.y += man3.yv;/*垂直方向按y轴的速度运动*/
gotoxy(man3.x, man3.y);
printf("美");
if (man3.x >= heng1 || man3.x <= heng2)
{
man3.xv = -man3.xv;
}
if (man3.y >= zong1 || man3.y <= zong2)
{
man3.yv = -man3.yv;
}
Sleep(1);
//1、擦去物体原来的轨迹:
gotoxy(man4.x, man4.y);/*把光标移到指定的坐标*/
printf(" ");/*输出空格,把先前的字符擦去*/
//2、然后我们让物体按其速度运动:
man4.x += man4.xv ;/*水平方向按x轴的速度运动*/
man4.y += man4.yv;/*垂直方向按y轴的速度运动*/
gotoxy(man4.x, man4.y);
printf("琴");
if (man4.x >= heng1 || man4.x <= heng2)
{
man4.xv = -man4.xv;
}
if (man4.y >= zong1 || man4.y <= zong2)
{
man4.yv = -man4.yv;
}
Sleep(1);
SetConsoleTextAttribute(hConsole, 0x000f);
gotoxy(36,10);
printf("*");
gotoxy(25,10);
printf("*");
gotoxy(47,10);
printf("*");
gotoxy(34,8);
printf("*");
gotoxy(38,8);
printf("*");
gotoxy(30,7);
printf("*");
gotoxy(42,7);
printf("*");
gotoxy(27,8);
printf("*");
gotoxy(45,8);
printf("*");
gotoxy(25,11);
printf("*");
gotoxy(47,11);
printf("*");
for(i=1,j=1;i<6,j<6;i++,j++)
{
gotoxy(25+i,11+j);
printf("*");
}
gotoxy(32,17);
printf("*");
gotoxy(34,18);
printf("*");
for(i=1,j=1;i<6,j<6;i++,j++)
{
gotoxy(47-i,11+j);
printf("*");
}
gotoxy(40,17);
printf("*");
gotoxy(38,18);
printf("*");
gotoxy(36,19);
printf("*");
Sleep(100);
gotoxy(55,16);
printf("Happy everyday!");
}
}
[ 本帖最后由 观弈寒儒 于 2011-1-12 09:53 编辑 ]