2016-09-14 72 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 

我的問題是,我想切換PLAYER1與Player2如果Player2猜硬幣側面和反向。我有一個想法,但結果是失敗!

我真的需要一些幫助,謝謝你的時間!

+3

什麼是你的問題?你不能只是轉儲代碼或需求,並期望我們在沒有任何幫助的情況下開始工作。 – SamTebbs33

+0

你的縮進是一團糟,如果有幫助 – khelwood

+0

我如何讓玩家之間切換?這是我的問題.. – Zamfi

回答

0

這是隻有2名球員的比賽。所以你可以簡單地設置布爾值來在玩家之間切換。
例如
初始化布爾值爲

boolean isPlayer1Chance = true;

當任何機會後改變值在for循環中,

如果(isPlayer1Choice){
//做播放器播放1次
}其他{
//完成播放2播放
}
isPlayer1Choice =!isPlayer1Choice;

+0

謝謝傑克的幫助和支持:) – Zamfi

+0

WC Zamfi,但記住從下次只粘貼問題的聲明,而不是整個代碼:) – Jack