2013-04-10 61 views
-1

我正在設計一個多人撲克遊戲。我有Human和Computer對象,它們都實現了一個Player接口,其中包含撲克玩家必需的方法。我有一個遊戲中的玩家的ArrayList,我需要去找每個玩家,並檢查他們是否想摺疊手或站立。如果每個人都摺疊了,那麼最後一個查看他們玩法的人會自動獲勝。對於每手牌,首發球員需要旋轉。首先,ArrayList的索引0中的人將首先進入。第二手,索引1中的人會先走。只是想反彈想法,聽取人們對如何實現這些功能的看法。如何旋轉起始玩家?

最初我有這樣的想法,

public void poker(ArrayList<Player> players){ 
    int foldCounter = 0; 
    int starter = 0; 

    while (weWantToPlay){ 
     for (int j = starter; j < players.size(); j++){ 
     //get the players game plan 
     players.get(j).getStand 

     //the player is folding 
     if (!player.stand()){ 
      foldCounter++; 
      //doStuff 
     else{ 
      //doStuff 
     } 
    } 

    //do more stuff and play poker 

    //increment starter so the next hand, the second person starts 
    // this obviously will not work, cause we need go to the end of the list, then wrap around 
    starter++; 

    //check who's folded to see if we automatically have a winner 
    if (foldCounter == players.size()-1){ 
     for (Player element:players){ 
      if (element.stand()){ 
       winner = element; 
       break; 
      } 
     } 
    } 
} 

}

+0

您的具體問題是什麼?如果你是在一般的架構討論之後,[programmers.stackexchange](http://programmers.stackexchange.com/faq)可能是一個更好的問題。 – simont 2013-04-10 04:39:32

+0

對不起,看起來我忘了指明我在這裏要求的是什麼。無論如何,我只是在尋找關於如何旋轉開始每場比賽的球員的不同想法。 – 2013-04-10 04:42:51

回答

1

我看不出有什麼問題,所以我不知道你要解決什麼問題。

如果這是'起動器問題':或許,您可以不使用增量的起動器,而只是遍歷從0到1的玩家列表,一旦完成,您在索引處移除玩家0並將其添加回列表末尾,並重新迭代等。

+0

輝煌的,只是彈出列表中的第一個元素,並重新添加它!謝了哥們!! – 2013-04-10 04:43:53

0
I am not much aware of the game poker but as per my understanding i understood that after each hand the starting player will be changed (i.e if A,B,C are three players then at first time A will be playing first then second time C will and third time B will be the first to play. 

    If this is the requirement then you can keep on rotating the players after each round and put your logic to find the winner. 

    The following code can be used for rotation 


    import java.util.ArrayList; 
    import java.util.Arrays; 
    import java.util.Collections; 
    import java.util.List; 

    public class Main { 
     public static void main(String[] args) { 
     List numbers = new ArrayList(); 

     for (int i = 0; i < 5; i++) { 
      numbers.add(i); 
     } 

     System.out.println("Original Array -" + Arrays.toString(numbers.toArray())); 

     for(int i=0;i<numbers.size();i++){ 
      Collections.rotate(numbers, 1); 

      System.out.println("After "+ i +" Rotation -"+ Arrays.toString(numbers.toArray())); 

      System.out.println("Element at first position - " +numbers.get(0)); 
     } 
     } 
    } 


    Output :- 

    Original Array -[0, 1, 2, 3, 4] 
    After 0 Rotation -[4, 0, 1, 2, 3] 
    Element at first position - 4 
    After 1 Rotation -[3, 4, 0, 1, 2] 
    Element at first position - 3 
    After 2 Rotation -[2, 3, 4, 0, 1] 
    Element at first position - 2 
    After 3 Rotation -[1, 2, 3, 4, 0] 
    Element at first position - 1 
    After 4 Rotation -[0, 1, 2, 3, 4] 
    Element at first position - 0 



NOTE:If you want to make rotation is some other fashion just change the digit in the following line 
Collections.rotate(numbers, 1);