2017-08-07 1 views
0

で相互に排他的な値を作成します。私のコードはここにある:は、私は、出力を持つことができるように、私はどのような方法でこれを変更することができれば、私は思っていたリスト

import java.util.Random; 
import java.util.Arrays; 
import java.util.ArrayList; 

public class cardGame { 
    public static void main(String[] args) { 
    Random sad = new Random(); 
    ArrayList<String> all = new ArrayList<>(Arrays.asList("Ace of spades","2 of spades","3 of spades","4 of spades","5 of spades","6 of spades","7 of spades","8 of spades","9 of spades","10 of spades","Jack of spades","Queen of spades","King of spades","Ace of spades","2 of spades","3 of spades","4 of spades","5 of spades","6 of spades","7 of spades","8 of spades","9 of spades","10 of spades","Jack of spades","Queen of spades","King of spades","Ace of hearts","2 of hearts","3 of hearts","4 of hearts","5 of hearts","6 of hearts","7 of hearts","8 of hearts","9 of hearts","10 of hearts","Jack of hearts","Queen of hearts","King of hearts","Ace of diamonds","2 of diamonds","3 of diamonds","4 of diamonds","5 of diamonds","6 of diamonds","7 of diamonds","8 of diamonds","9 of diamonds","10 of diamonds","Jack of diamonds","Queen of diamonds","King of diamonds","Ace of clubs","2 of clubs","3 of clubs","4 of clubs","5 of clubs","6 of clubs","7 of clubs","8 of clubs","9 of clubs","10 of clubs","Jack of clubs","Queen of clubs","King of clubs")); 
    ArrayList<String> trump = new ArrayList<>(Arrays.asList("spades","hearts","diamonds","clubs")); 
    System.out.println("Boure hands and trump game."); 
    System.out.println(""); 
    System.out.println("Trump: " + trump.remove(sad.nextInt(trump.size())) + "."); 
    System.out.println(""); 
    System.out.println("P1 Hand: " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + "."); 
    System.out.println(""); 
    System.out.println("P2 Hand: " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + "."); 
    System.out.println(""); 
    System.out.println("P3 Hand: " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + "."); 
    System.out.println(""); 
    System.out.println("P4 Hand: " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + ", " + all.remove(sad.nextInt(all.size())) + "."); 
    } 
} 

ところで重複は一つの方法では役に立ちませんでした:それは配列が含まれていなかった、私が扱ってるものをしています。それが述べているように、私は質問を見て私がどこで変えることができないのか理解できませんでした。

+0

最初に読んだこと:[多型性:なぜ "リストリスト=新しいArrayList"の代わりに "リストリスト=新しいArrayList"を使用しますか?](https://stackoverflow.com/questions/9852831/polymorphism-why-use-list-リストアの代わりにarraylist-list-n) – Blasanka

+0

@Blasanka何をすべきか、私は修正するためのエラーを探しています。ところで、私はそこに助けは、質問をチェックアウトした。 –

+0

あなたは実際に何のエラーがありますか? –

答えて

2
カードの Deckから始め、次いで Deckからそれらを除去し、 PlayerCollectionたモデル Playerの手にそれらを追加することによって、各 Playerにカードを割り当てる

このようにして、プレイヤーはデッキからカードを入手することができ、適切なカードのいずれかでデッキを初期化することができます。

+0

ありがとう、私は今それを試しています。 –

+0

私はちょうどいくつかのポインタを必要としています:1.配列や何を使うか、2.削除と追加の方法3.各プレーヤーは 'String [] p1 = {}'か何かを取得しますか? –

+0

@BlazeDaBlur配列の代わりに。セットは、カードの順番が重要ではないため、セットが存在する場合にのみ重要です。 –

関連する問題