2016-09-14 3 views
-5

私のような初心者のためにこのゲームは "人気"が高いとわかっていますが、本当に問題が残っています。2人のプレイヤーの頭と尾のゲームシミュレーション

これは私のプログラムはこの瞬間(メインプログラム)にどのように見えるかです: -

public class Proiect1 { 
    public static void main(String [] args){ 

     System.out.println("Enter the number of throws: "); 
       Scanner sc=new Scanner(System.in); 
         int n=sc.nextInt(); 
          game p1=new game(); 
          game p2=new game(); 
           int score1=0,score2=0; 
           int coin; 

    System.out.println("The game rules:"+"\n-if coin =1 that means 
        HEAD"+"\n-if coin =2 that means TAILS"+"\nEnjoy the game!"); 
    System.out.println("The first player will throw the coin! 
         Let's see if the second player can quess the coin side!"); 
     for(int k=0;k<n;k++){ 
      p2.Player2Choice(); 
      coin=(int)((Math.random()*2)+1); 
                         if(coin!=p2.getDecisionPlayer2()){ 
      System.out.println("You lost!"+"Coin side was: "+coin); 
      score1++; 
      }    //close if         
      else{ 
       System.out.println("You win! "+" Coin side was: "+coin); 
       score2++; 
      } //close else 

     System.out.println("Player1 won: "+scor1+" times"); 
     System.out.println("Player2 won: "+scor2+" times"); 
     }close for 
     System.out.println("Win rate for player1: "+(int)((scor1*100.0f)/n)+"%"); 
     System.out.println("Win rate for player2: "+(int)((scor2*100.0f)/n)+"%"); 
    } //close main 
}  //close class 

私の問題は、私はPlayer2がコイン側と逆を推測する場合Player2でPlayer1を切り替えたいということです。アイデアはありましたが、結果は失敗でした!

私は本当にあなたの時間のおかげでいくつかの助けが必要です!

+3

あなたの質問は何ですか?あなたは単にコードや要求をダンプすることはできませんし、あなたの助けなしに私たちが働くことを期待することはできません。 – SamTebbs33

+0

あなたはインデントが混乱している場合は、それは助ける – khelwood

+0

どのように私は選手の間で切り替えることができますか?それは私の質問です.. – Zamfi

答えて

0

これはわずか2人のゲームです。したがって、単にブール値を設定してプレイヤー間を切り替えることができます。
など。
ブール値を初期値として

ブール値isPlayer1Chance = true;ループの内側など万が一のALTER値の後

すると、

(isPlayer1Choice)であれば、他の{
//プレイヤー1プレイ
を行う} {
//ドゥプレイヤー2は
を再生します}
isPlayer1Choice =!isPlayer1Choice;

+0

あなたの助けとサポートのためのおかげでジャック: – Zamfi

+0

WC Zamfi、しかし、次回からのみ問題のステートメントと全体のコードを貼り付ける:) – Jack

関連する問題