#include "stdafx.h"
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
void DrawBall(int x, int y)
{
setcolor(RED);
setfillcolor(RED);
fillcircle(x,y,16);
Sleep(4);
setcolor(BLACK);
setfillcolor(BLACK);
fillcircle(x,y,16);
}
void DrawStick(int x, int y, int COLOR)
{
setcolor(COLOR);
setfillcolor(COLOR);
fillrectangle(x,y,x+100,y+8);
}
int main()
{
int i;
int x=319,y=39;
int deltax=4, deltay=3;
int xs =300, ys=0;
int deltaxs = 4;
int xsdir = 1;
initgraph(640,480);
setcolor(RED);
DrawStick(xs,ys,YELLOW);
while(1)
{
if(_kbhit()!=0)
{
char a = _getch();
if (a=='j')
xsdir=-1;
else if (a=='k')
xsdir=1;
else if (a==27)
break;
DrawStick(xs,ys,BLACK);
xs += (xsdir*deltaxs);
DrawStick(xs,ys,YELLOW);
}
DrawBall(x,y);
x+=deltax;
y+=deltay;
if (x>=620 || x<=20)
deltax = - deltax ;
if (y<=20)
deltay = - deltay;
if (y>=462)
{
if (x>=xs && x<= xs+100)
deltay = - deltay;
else
{
outtextxy(290,240,_T("YOU LOST!"));
break;
}
}
}
getch();
closegraph();
return 0;
}
怎么做啊!!!!求大神。。。
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
void DrawBall(int x, int y)
{
setcolor(RED);
setfillcolor(RED);
fillcircle(x,y,16);
Sleep(4);
setcolor(BLACK);
setfillcolor(BLACK);
fillcircle(x,y,16);
}
void DrawStick(int x, int y, int COLOR)
{
setcolor(COLOR);
setfillcolor(COLOR);
fillrectangle(x,y,x+100,y+8);
}
int main()
{
int i;
int x=319,y=39;
int deltax=4, deltay=3;
int xs =300, ys=0;
int deltaxs = 4;
int xsdir = 1;
initgraph(640,480);
setcolor(RED);
DrawStick(xs,ys,YELLOW);
while(1)
{
if(_kbhit()!=0)
{
char a = _getch();
if (a=='j')
xsdir=-1;
else if (a=='k')
xsdir=1;
else if (a==27)
break;
DrawStick(xs,ys,BLACK);
xs += (xsdir*deltaxs);
DrawStick(xs,ys,YELLOW);
}
DrawBall(x,y);
x+=deltax;
y+=deltay;
if (x>=620 || x<=20)
deltax = - deltax ;
if (y<=20)
deltay = - deltay;
if (y>=462)
{
if (x>=xs && x<= xs+100)
deltay = - deltay;
else
{
outtextxy(290,240,_T("YOU LOST!"));
break;
}
}
}
getch();
closegraph();
return 0;
}
怎么做啊!!!!求大神。。。

