Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从数组中随机选取精确的数量_Java_Eclipse - Fatal编程技术网

Java 如何从数组中随机选取精确的数量

Java 如何从数组中随机选取精确的数量,java,eclipse,Java,Eclipse,例如,我有一副牌,我希望玩家每轮随机发送一张或四张牌。直到甲板在其中一轮中耗尽 int playerOneDeck[] = new int[12]; 抱歉,信息太少了。当然,我可以提供更多信息,有了这个i类洗牌牌牌组,4名玩家可获得48张牌,4名玩家可获得12张牌: public class ShuffleCards{public void shuffle (int one[], int two[], int three[], int[] four) { int play

例如,我有一副牌,我希望玩家每轮随机发送一张或四张牌。直到甲板在其中一轮中耗尽

int playerOneDeck[] = new int[12];
抱歉,信息太少了。当然,我可以提供更多信息,有了这个i类洗牌牌牌组,4名玩家可获得48张牌,4名玩家可获得12张牌:

public class ShuffleCards{public void shuffle (int one[], int two[], int three[], int[] four)
{       
    int player = 0;
    int numberToDistribute = 1;
    int count1=0, count2=0, count3=0, count4=0;
    for(int i = 0; i < 48; i++)
    {
        player = rnd.nextInt(4);
        if((player==0)&&(count1<12))
        {
            one[count1] = numberToDistribute;
            count1++;
        }
        else if (count2<12)
        {
            two[count2] = numberToDistribute;
            count2++;
        }

        else if (count3<12)
        {
            three[count3] = numberToDistribute;
            count3++;
        }

        else if (count4<12)
        {
            four[count4] = numberToDistribute;
            count4++;
        }
        if(numberToDistribute %12==0)
        {
            numberToDistribute=1;
        }
        else
        {
            numberToDistribute++;
        }
    }
}}
public-class-ShuffleCards{public-void-shuffle(int-one[],int-two[],int-three[],int-three[],int-three[]四)
{       
int-player=0;
int numberToDistribute=1;
int count1=0,count2=0,count3=0,count4=0;
对于(int i=0;i<48;i++)
{
player=rnd.nextInt(4);

如果((玩家==0)和(&&)(计数1)可以显示开始牌组和结束牌组吗?也可以显示几轮。
public class Controller implements ActionListener, WindowListener, MouseListener{

int deckPlayer1[] = new int[12];
int deckPlayer2[] = new int[12];
int deckPlayer3[] = new int[12];
int deckPlayer4[] = new int[12];
int discardDeck[] = new int [48];
int initialNumberRound = 0;
int actualCardPlayer1 = 0;
int actualCardPlayer2 = 0;
int actualCardPlayer3 = 0;
int actualCardPlayer4 = 0;
int one,two,three,four;

public Controller(ShuffleCards shuffle, viewPlaying playing)
{
    public void mouseClicked(MouseEvent event)
    {       
        int x = event.getX();
        int y = event.getY();

        //TURNS
        if((x>=340)&&(x<=449)&&(y>=65)&&(y<=215)&&(turn==0))
        {
            //PLAYER 1 TURN
            //SHOW CARD DECK 1
            try 
            {
                this.viewPlaying.showCardDeck1(deckPlayer1[actualCardPlayer1]);
                actualCardPlayer1 ++;
                turn = 1;
                System.out.println("Player one sent a card, player two, is your turn.");

            } 
            catch(ArrayIndexOutOfBoundsException e) 
            {
                System.out.println("the player one doesn’t have cards, he won the match.");
            }
        }


        //PLAYER 2 TURN
        else if ((x>=340)&&(x<=449)&&(y>=295)&&(y<=445)&&(turn==1))
        {


            //SHOW CARD DECK 2
            try 
            {
                this.viewPlaying.showCardDeck2

                (deckPlayer2 [actualCardPlayer2]);
                actualCardPlayer2 ++;
                turn = 2;
                System.out.println("Player two sent a card, player three, is your turn.");
                catch(ArrayIndexOutOfBoundsException e) 
                {
                    System.out.println("The player two doesn’t have cards, he won the match");
                }
            }


            //PLAYER 3 TURN
            else if((x>=60)&&(x<=169)&&(y>=180)&&(y<=330)&&(turn==2))
            {
                //SHOW CARD DECK 3
                try 
                {
                    this.viewPlaying.showCardDeck3(deckPlayer3[actualCardPlayer3]);
                    actualCardPlayer3++;
                    turn = 3;
                    System.out.println("Player three sent a card, player four, is your turn ");
                } 
                catch(ArrayIndexOutOfBoundsException e) 
                {
                    System.out.println("The player three doesn’t have cards, he won the match");
                }
            }
            else if((x>=650)&&(x<=759)&&(y>=180)&&(y<=330)&&(turn==3))
            {
                //PLAYER 4 TURN
                //SHOW CARD DECK 4
                try 
                {
                    this.viewPlaying.showDeck4(deckPlayer4[actualCardPlayer4]);
                    actualCardPlayer4++;
                    turn=0;
                    System.out.println("Player four sent a card, player one is your turn.");

                } 
                catch(ArrayIndexOutOfBoundsException e) 
                {
                    System.out.println("The player four doesn’t have cards, he won the match");
                }
            }
        }