2016-12-20 2 views
-6

プレーヤーとコンピュータの間にサイコロゲームを作成します。ゲームのポイントは、サイコロを回して最初のものを100勝にすることです。いずれかのプレイヤーが2をロールした場合、合計は自動的に減少します2。彼らが他の役割を果たしている場合は、合計に加算されます。拳1> = 100勝。誰が最初にロールするかを決定するために、0と2の間の乱数を生成します。 0の場合、プレーヤーが最初にロールします(コンピュータが最初にロールします)。Javaダイスゲームの問題 - fast please

私は高校の初心者のプログラマーで、これに多くの問題があります。私はダイスロールを個別に表示する方法を考えました。その方法を使って最初の1〜100を見つける方法を見つけることができないので、誰かが私により簡単な方法を見せてくれれば素晴らしいだろう。

public class problemTwo { 

    public static void main(String[] args) { 

     // TODO Auto-generated method stub 
     int d1=(int)(Math.random()*6+1); 
     int d2=(int)(Math.random()*6+1); 
     int dSum= d1 + d2; 
     System.out.println("Player Roll 1 total is ;" +dSum); 

     int d3=(int)(Math.random()*6+1); 
     int d4=(int)(Math.random()*6+1); 
     int dSum2= d3 + d4; 
     System.out.println("Player Roll 2 total is ;" +dSum2); 

     int d5=(int)(Math.random()*6+1); 
     int d6=(int)(Math.random()*6+1); 
     int dSum3= d5 + d6; 
     System.out.println("Player Roll 3 total is ;" +dSum3); 

     int d7=(int)(Math.random()*6+1); 
     int d8=(int)(Math.random()*6+1); 
     int dSum4= d7 + d8; 
     System.out.println("Player Roll 4 total is ;" +dSum4); 

     int d9=(int)(Math.random()*6+1); 
     int d10=(int)(Math.random()*6+1); 
     int dSum5= d9 + d10; 
     System.out.println("Player Roll 5 total is ;" +dSum5); 

     int d11=(int)(Math.random()*6+1); 
     int d12=(int)(Math.random()*6+1); 
     int dSum6= d11 + d12; 
     System.out.println("Player Roll 6 total is ;" +dSum6); 

     int d13=(int)(Math.random()*6+1); 
     int d14=(int)(Math.random()*6+1); 
     int dSum7= d13 + d14; 
     System.out.println("Player Roll 7 total is ;" +dSum7); 

     int d15=(int)(Math.random()*6+1); 
     int d16=(int)(Math.random()*6+1); 
     int dSum8= d15 + d15; 
     System.out.println("Player Roll 8 total is ;" +dSum8); 

     int d17=(int)(Math.random()*6+1); 
     int d18=(int)(Math.random()*6+1); 
     int dSum9= d17 + d17; 
     System.out.println("Player Roll 9 total is ;" +dSum9); 

     int d19=(int)(Math.random()*6+1); 
     int d20=(int)(Math.random()*6+1); 
     int dSum10= d19 + d20; 
     System.out.println("Player Roll 10 total is ;" +dSum10); 

    System.out.println("Roll "+ " total is" +(dSum + dSum2 + dSum3 + dSum4 + dSum5+ + dSum6+ + dSum7+ + dSum8+ + dSum9+ + dSum10)); 
    } 

} 
+0

「すばらしい」とはどういう意味ですか? – Bathsheba

+0

あなたがすでに書いたコードを投稿してください。 – DimaSan

+7

「fastplease」タグがないようです。 – Berger

答えて

0

ここで重要なことは、サイコロが巻き取られる回数を制限することです。あなたのコードでは、各プレイヤーが最大10回のロールを掛けます。つまり、1回のロールごとに得点が低い場合、決して100に達することはありません。
あなたがしたいのは、同じコードを実行するwhileループを使用することです条件に達するまで質問のこの種のはよくこのサイトで受信されていないこと)

while(no player reached a score of 100) { 
    player 1 roll the dice 
    add the result to player 1 score 
    player 2 roll the dice 
    add the result to player 2 score 
} 

注;ここで はスケルトンで、私はあなたが残りを把握せていただきます。あなたがしなければならないことは、コードのどの部分がうまく動作しないかを理解することです。課題を投稿すると、あなたには(特にタイトルの「すばやい」で)否定的な投票しか得られず、あなたの質問は削除されます。タイトルをSimulate dice game between two playerのように変更し、質問を書き直してください。