qq_43549968 2019-05-09 21:54 采纳率: 0%
浏览 337

类与类之间的吧变量传递问题该怎么解决呢?初始位置的随机设置为什么无法通过编译?希望大佬解释一下

类与类之间的吧变量传递问题该怎么解决呢?为什么小球不能动?还有初始位置的随机设置为什么无法通过编译?希望大佬解释一下,拜托
#include
#include
#include
#include
using namespace std;
#define MAXSTEP 9

class Box
{
private:
int a;
int b;
public:
Box(int high,int width)
{
a=high;
b=width;
initgraph(high, width);
}
int getHigh(){return a;}
int getWidth(){return b;}
};

class ball
{
private:
int R,X,Y,speed_x,speed_y;
int a,b;
COLORREF color;
int date_from_Box;
public:
ball(int r,int x,int y,int vx,int vy)
{
R=r;
X=x;
Y=y;
speed_x=vx;
speed_y=vy;
color=HSLtoRGB(float(rand()%360),1.0,0.5);
//初始位置随机
step.x=((rand()%2*2-1)*(rand()%MAXSTEP+1);
step.y=((rand()%2*2-1)*(rand()%MAXSTEP+1);
}
void show()
{
BeginBatchDraw();
cleardevice();
// 画渐变的天空(通过亮度逐渐增加)
float H = 190; // 色相
float S = 1; // 饱和度
float L = 0.7f; // 亮度
for(int y = 0; y < b; y++)
{
L += 0.0005f;
setlinecolor( HSLtoRGB(H, S, L) );
line(0, y, a-1, y);
}
//填充颜色 随机
setfillcolor(color);
color=HSLtoRGB(float(rand()%360),1,0.5);

    solidellipse(X-R,Y-R,X+R,Y+R);
    FlushBatchDraw();
    EndBatchDraw();
}   
void move()
{
    //有一定阻力
    if(speed_x!=0)
        X+=speed_x;
        speed_x-=0.01;
    if(speed_x!=0)
        Y+=speed_y;
        speed_y-=0.01;
    show();
}
void check_change()
{
    //碰撞变色
    if(X-R<=0 || X+R>=a){
        speed_x*=-1;
        color=HSLtoRGB(float(rand()%360),1,0.5);}
    if(Y-R<=0 || Y+R>=b){
        speed_y*=-1;
        color=HSLtoRGB(float(rand()%360),1,0.5);}
}

};
int main()
{
int a,b;
cin>>a>>b;
initgraph(a,b);
ball myball(10,20,20,3,3);
while(1)
{

myball.check_change();
myball.move();
}
getch();
return 0;
}

出错在初始位置随机处
G:\1.cpp(42) : error C2958: the left parenthesis '(' found at 'G:\1.cpp(41)' was not matched correctly
  • 写回答

1条回答 默认 最新

  • 江的海 2019-05-11 12:54
    关注

    设置APK路径或者更新版本

    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误