我要做的代碼部分有一個對話框,要求用戶輸入一定數量的單位,並要求對象提升輸入數字。
但是,如果單位的數量會導致對象的y位置= 0,那麼會彈出一個警告,並且該對象不會移動。我有一些可行的東西,但只有在對象完成了旅程之後。Java:如何檢查對象在它到達之前的位置
這是我到目前爲止有:
/*
* Prompts the user to enter the number of units they want the
* rocket to move upwards.
*
* If the number the units provided would cause the tip of the
* capsule to go past the top of the Graphical Display, the user
* is informed via a dialogue box that the rocket will not launch.
*
* Otherwise the rocket launches as required.
*/
public void launch()
{
String inputNumString;
int inputNum;
inputNumString = OUDialog.request("Please Enter Number of Units You Wish the Rocket to Ascend");
inputNum = Integer.parseInt(inputNumString);
this.ignition();
this.animateRocket(inputNum);
this.getCapsule().getYPos();
if (getCapsule().getYPos() <= 0)
{
OUDialog.alert("Rocket Will Not Launch");
}
}
提示:不要問/想想非常高的水平的問題,你需要考慮的變量,座標和這些條款。 – zapl