我正在尝试用 switch 语句替换我的 if 和 else if 语句。
Ball 类来自一个外部的 action script 文件,其中有一个变量,我将球的半径传递给它(radius = 30)。
我该如何将 if 和 else if 语句转换为 switch 语句?
代码:
private var ball:Ball;
private var left:Number = 0;
private var right:Number = stage.stageWidth;
private var top:Number = 0;
private var bottom:Number = stage.stageHeight;
if(ball.x >= right + ball.radius)
{
ball.x = left - ball.radius;
}
else if(ball.x <= left - ball.radius)
{
ball.x = right + ball.radius;
}
if(ball.y >= bottom + ball.radius)
{
ball.y = top - ball.radius;
}
else if(ball.y <= top - ball.radius)
{
ball.y = bottom + ball.radius;
}
谢谢您。