#include<graphics.h>
#include<conio.h>
#include<Windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#define High 480
#define Width 640
int main()
{
int k;
char aj;
void zfc(int k);
int jishu(int x);
void xiangshang(int x, int y);
void huayuan(int x, int y, int r);
void huaxiaoyuan();
float ball_x, ball_y;
float ball_vx=1, ball_vy=1;
float radius = 20;
int i;
initgraph(Width, High);
setlinecolor(YELLOW); /*画线*/
line(0, 240, 210, 240);
line(430, 240, 640, 240);
line(210, 240, 210, 0);
line(430, 240, 430, 0);
huaxiaoyuan();
BeginBatchDraw();
ball_y = High-High / 4;
ball_x = radius;
setcolor(BLACK); /*画园 */
setfillcolor(BLACK);
fillcircle(ball_x, ball_y, radius);
while (1) /*运动*/
{
if (_kbhit())
{
break;
}
setcolor(BLACK);
setfillcolor(BLACK);
fillcircle(ball_x, ball_y, radius);
ball_x = ball_x + ball_vx;
if ((ball_x <= radius) || (ball_x >= Width - radius))
ball_vx = -ball_vx;
setcolor(YELLOW);
setfillcolor(GREEN);
fillcircle(ball_x, ball_y, radius);
FlushBatchDraw();
Sleep(1);
}
xiangshang(ball_x, ball_y);
k = jishu(ball_x);
zfc(k);
_getch();
EndBatchDraw();
closegraph();
return 0;
}
void huayuan(int x, int y, int r)
{
setcolor(GREEN);
setfillcolor(BLUE);
fillcircle(x, y, r);
}
void huaxiaoyuan()
{
void huayuan(int x, int y, int r);
huayuan(240, 20, 20);
huayuan(320, 20, 20);
huayuan(400, 20, 20);
huayuan(280, 60, 20);
huayuan(360, 60, 20);
huayuan(320, 100, 20);
}
void xiangshang(int x,int y)
{
int k = 0;
float ball_x, ball_y;
float ball_vx = 1, ball_vy = 1;
ball_x = x;
ball_y = y;
while (1) /*运动*/
{
setcolor(BLACK);
setfillcolor(BLACK);
fillcircle(ball_x, ball_y, 20);
ball_y = ball_y -ball_vy;
if (ball_x >= 0 && ball_x <= 230 || ball_x >= 410 && ball_x <= 640)
{
if ((ball_y - 240) == 20)
{
ball_vy = 0;
k = 1;
}
}
else
{
if (ball_y == 20)
{
ball_vy = 0;
}
}
setcolor(YELLOW);
setfillcolor(GREEN);
fillcircle(ball_x, ball_y, 20);
FlushBatchDraw();
Sleep(0.1);
}
}
int jishu(int x)
{
int k=0;
if (x >= 0 && x <= 210 || x >= 430 && x <= 640)
{
k = 0;
}
else
{
if (x > 230 && x <= 240 || x >= 400 && x < 410)
{
k = 1;
}
else if (x > 240 && x < 280 || x>360 && x < 400)
{
k = 3;
}
else if (x == 280 || x == 360)
{
k = 2;
}
else if (x > 280 && x < 320 || x>320 && x < 360)
{
k = 5;
}
else
{
k = 4;
}
}
return k;
}
void zfc(int k)
{
setbkmode(TRANSPARENT);
TCHAR text[1];
int score = k;
_stprintf_s(text, _T("得分:%d"), score);//将score转换成字符串
settextcolor(BLUE);//设置字体颜色为蓝色
settextstyle(50, 0, _T("宋体"));//设置字体
outtextxy(0, 0, text);
}
用outtextxy在这个位置zfc()输不出字符串。
问一下为什么