Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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 在手和扑克板之间复制Dack/卡阵列_Java_Arrays_Class_Methods_Poker - Fatal编程技术网

Java 在手和扑克板之间复制Dack/卡阵列

Java 在手和扑克板之间复制Dack/卡阵列,java,arrays,class,methods,poker,Java,Arrays,Class,Methods,Poker,编辑:我已经部分解决了这个问题。我之前已经从它自己的方法中删除了for循环,并将其放入main中,以便它工作,但由于某种原因,这次它不工作。这是因为一个新的Cards对象正在初始化(在//Flop注释下面),我想这会重置组。如果我删除它并将循环放置在那里,而不是它自己的方法,它就会工作。但是,这个问题仍然发生在方法中,因为我需要创建一个新对象来与deck类“通信”。我将尝试将对象作为参数传入,或者将其设置为可访问的位置,看看是否有效,然后我将重新编辑这篇文章 编辑2:将Cards对象作为参数传入

编辑:我已经部分解决了这个问题。我之前已经从它自己的方法中删除了for循环,并将其放入main中,以便它工作,但由于某种原因,这次它不工作。这是因为一个新的Cards对象正在初始化(在//Flop注释下面),我想这会重置组。如果我删除它并将循环放置在那里,而不是它自己的方法,它就会工作。但是,这个问题仍然发生在方法中,因为我需要创建一个新对象来与deck类“通信”。我将尝试将对象作为参数传入,或者将其设置为可访问的位置,看看是否有效,然后我将重新编辑这篇文章

编辑2:将Cards对象作为参数传入已起作用!将作为答案发布

职位开始: 我想为我的班级写一个德州扑克游戏。我正在尝试使用一些方法来整理main()。不幸的是,这张牌在我拥有的其他阵型(玩家的手牌、对手的手牌和棋盘)之间被复制。我似乎不在我老师的最爱列表中,所以当老师要求时,他没有提供太多帮助

以下是主要课程:

  public class PokerGame
{
    private int pot = 0;
    public static void main(String[] args)
    {
        //Create Objects to connect classes.
        Deck Cards = new Deck(0, "s");
        Player Player = new Player();
        Opponents Op1 = new Opponents();

        //Bring deck into this main class.
        Deck[] aDeck = new Deck[52];
        Deck[] fDeck = Cards.buildDeck(aDeck);
        Deck[] mDeck = Cards.shuffle(fDeck, 100);


        //Create the Board and Hand arrays.
        Deck[] Board = new Deck[5];
        Deck[] Burned = new Deck[3];
        Deck[] pHand = new Deck[2];
        Deck[] o1Hand = new Deck[2];

        int count;
        for(count = 0; count < pHand.length; count++)
        {
            pHand[count] = Cards.deal(mDeck);
            System.out.println("P " + pHand[count].namedRank + " of " + pHand[count].s);
            o1Hand[count] = Cards.deal(mDeck);
        }

        System.out.println("o1 " + o1Hand[0].namedRank + " of " + o1Hand[0].s);
        System.out.println("o1 " + o1Hand[1].namedRank + " of " + o1Hand[1].s);

        //The Flop
        Cards = new Deck(0, "s");
        Burned[0] = Cards.deal(mDeck);
        Board = flop(Board, mDeck);

        //The Turn
        Burned[1] = Cards.deal(mDeck);
        Board[3] = Cards.deal(mDeck);
        System.out.println("\n\n");
        System.out.println("Now the Board is...");

        for(int b = 0; b < 4; b++)
        {
            System.out.println(Board[b].namedRank + " of " + Board[b].s);
        }

        showdown(Board, pHand, o1Hand);
    }

    public static Deck[] flop(Deck[] Board, Deck[] mDeck)
    {
        Deck Cards = new Deck(0, "s");
        System.out.println();
        System.out.println("The Board is...");
        for(int b = 0; b < 3; b++)
        {
            Board[b] = Cards.deal(mDeck);
            System.out.println(Board[b].namedRank + " of " + Board[b].s);
        }
        return Board;
    }
公共类扑克游戏
{
私有int pot=0;
公共静态void main(字符串[]args)
{
//创建对象以连接类。
牌组卡=新牌组(0,“s”);
玩家=新玩家();
对手Op1=新对手();
//把甲板带到这个主舱里。
甲板[]阿德克=新甲板[52];
甲板[]fDeck=卡片.建筑甲板(aDeck);
牌组[]mDeck=牌。洗牌(fDeck,100);
//创建板和手阵列。
甲板[]板=新甲板[5];
甲板[]烧毁=新甲板[3];
甲板[]pHand=新甲板[2];
甲板[]O1手=新甲板[2];
整数计数;
用于(计数=0;计数
这是我洗牌和交易的甲板课

public class Deck
{
    public Deck[] Deck = new Deck[52];
    private int index = 0;
    public int rank;
    public String s;
    public String namedRank;
    private int x = 0;

    /**
     * Constructor for card Objects
     * 
     * Cannot get to work, not sure where issue is.
     */
    public Deck(int rank, String s)
    {
        if(rank == 1)
        {
            this.rank = 14;
        }
        else
        {
            this.rank = rank;
        }

        String numRank = String.valueOf(rank);
        if(this.rank == 11)
        {
            this.namedRank = "Jack";
        }
        else if(this.rank == 12)
        {   
            this.namedRank = "Queen";
        }
        else if(this.rank == 13)
        {   
            this.namedRank = "King";
        }
        else if(this.rank == 14)
        {   
            this.namedRank = "Ace";
        }
        else
        {
            this.namedRank = numRank;
        }
        this.s = s;
    }

    /**
     * Assigns each element in the array a card
     * 
     * @param Deck array before elements assigned
     * @return Deck array after elemnts assigned
     */
    public Deck[] buildDeck(Deck[] fDeck)
    {
        String[] suit = {"Club", "Diamond", "Heart", "Spade"};

        int c;
        String of = " of ";
        for(c = 0; c < suit.length; c++)
        {
            for(rank = 1; rank < 14; rank++)
            {
                s = suit[c];
                fDeck[x] = new Deck(rank, s);
                x++;
            }
        }
        return fDeck;
    }


    /**
     * Shuffles the cards by picking to random numbers and switching them
     * 
     * @param Deck array after elemetns assigned
     * @return Deck array after elements are mixed up
     */
    public Deck[] shuffle(Deck[] mDeck, int shuffle)
    {
        for(int count = 0; count < shuffle; count++)
        {
            int f = ((int)(Math.random() * 100) % 51 + 1);
            int s = 0;

            Deck move = mDeck[f];
            mDeck[f] = mDeck[s];
            mDeck[s] = move;

        }

        return mDeck;
    }

    /**
     * Deals the cards and keeps track by incrasing the index
     * 
     * @param Deck array after elements are mixed up
     * @return single Deck array element at whatever position int index is at
     */
    public Deck deal(Deck[] dDeck)
    {
        index++;
        return dDeck[index];
    }
}
公共类甲板
{
公共甲板[]甲板=新甲板[52];
私有整数指数=0;
公共int等级;
公共字符串s;
公共字符串名称;
私有整数x=0;
/**
*卡对象的构造函数
* 
*无法开始工作,不确定问题在哪里。
*/
公共甲板(整数列,字符串s)
{
如果(秩==1)
{
这个等级=14;
}
其他的
{
这个.等级=等级;
}
String numRank=String.valueOf(秩);
如果(this.rank==11)
{
this.name=“杰克”;
}
else if(this.rank==12)
{   
this.name=“Queen”;
}
else if(this.rank==13)
{   
this.name=“King”;
}
else if(this.rank==14)
{   
this.name=“Ace”;
}
其他的
{
this.name=numRank;
}
这个.s=s;
}
/**
*为数组中的每个元素分配一张卡
* 
*@param Deck数组在指定元素之前
*@分配元素后返回甲板阵列
*/
公共甲板[]建筑甲板(甲板[]fDeck)
{
字符串[]套装={“俱乐部”、“钻石”、“心脏”、“黑桃”};
INTC;
字符串of=“of”;
对于(c=0;c

从字面上说,任何帮助都是非常感谢的,因为我对此已经挠头很长时间了。在我开始工作之前,我将继续我可以处理的事情。

我不清楚甲板类实际上是一副牌还是一张牌。每个甲板似乎有52个甲板(本身)的阵列然后在主界面中,你为手创建了一系列的牌组,就像他们