2016-12-02 1 views
-1

私が行っているコードの部分には、ユーザーが多数の単位を入力し、オブジェクトが入力番号を上昇するように求めるダイアログボックスがあります。
しかし、ユニット数によってオブジェクトのy-位置= 0が発生すると、警告がポップアップし、オブジェクトは移動しません。私は、オブジェクトがそれを旅にした後でのみ動作するものを持っています。 Java:オブジェクトがそこに到達する前の場所を確認する方法

この

は、私がこれまで持っているものである:それは

+0

ヒント:非常に高いレベルの問題について質問したり考えたりしないでください。変数、座標などについて考える必要があります。 – zapl

答えて

0

if(getCapsule().getYPos() - inputNum <=0)

このような。

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(); 
     // calculate new position here 
     calculateNewPosition(); 
     if (getCapsule().getYPos() <= 0) { 
     OUDialog.alert("Rocket Will Not Launch"); 
     } else { 
     this.animateRocket(inputNum); 
     } 

    } 
+0

申し訳ありません、それはそれを行っていません。まだ警告がありません –

0

私は方法は何をすべきか分からない行う必要がありますが、あなたが何かにあなたのロジックを変更する必要があり

/* 
    * 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"); 



     } 

    } 
+0

これは、どちらも動作していないようです:/ごめんなさい –

関連する問題