Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.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 - Fatal编程技术网

Java扑克游戏创建头部检查器

Java扑克游戏创建头部检查器,java,Java,我已经创建了一个java扑克程序,我有一个这样的程序,我可以检查玩家或庄家是否有一对,如果他们有,中奖者将赌注存入他们的帐户余额。我现在想得到它,这样,如果一个球员有一个直接的皇家同花顺的程序将读取它,并把赢家帐户中的奖金。我想用一个循环。这是到目前为止我的代码 private int flush(List<PokerCard> hand) { List<PokerCard> handToSort = new ArrayList<PokerCard>(

我已经创建了一个java扑克程序,我有一个这样的程序,我可以检查玩家或庄家是否有一对,如果他们有,中奖者将赌注存入他们的帐户余额。我现在想得到它,这样,如果一个球员有一个直接的皇家同花顺的程序将读取它,并把赢家帐户中的奖金。我想用一个循环。这是到目前为止我的代码

private int flush(List<PokerCard> hand)
{
    List<PokerCard> handToSort = new ArrayList<PokerCard>();
    Collections.copy(handToSort, hand);
    Collections.sort(handToSort, new CardComparator());
    {
        List<PokerCard> deck = new ArrayList<PokerCard> ();
        for (int i = 0; i < 4; i ++)
        {
            for (int j = 8; j < 13; j ++)
            {
                System.out.println("You have a Royal Flush 10 through Ace!!");
                return flush;
            }
            else (int j = 0; j < 6; j++)
            {
                System.out.println("You have a straigth 2 through 6!!");
                return flush;
            }
            else (int j = 1; j < 7; j++)
            {
                System.out.println("You have a straigth 3 through 7!!");
                return flush;
            }
            else (int j = 2; j < 8; j ++)
            {
                System.out.println("You have a straigth 4 through 8!!");
                return flush;
            }
            else (int j = 3; j < 9; j++)
            {
                System.out.println("You have a straigth 5 through 9!!");
                return flush;
            }
            else (int j = 4; j < 10; j++)
            {
                System.out.println("You have a straigth 6 through 10!!");
                return flush;
            }
            else (int j = 5; j < 11; j++)
            {
                System.out.println("You have a straigth 7 through Jack!!");
                return flush;
            }
            else (int j =6; j < 12; j++)
            {
                System.out.println("You have a straigth 8 through Queen!!");
                return flush;
            }
            else (int j = 7; j < 13; j ++)
            {
                System.out.println("You have a straigth 9 through King!!");
                return flush;
            }
private int flush(手动列表)
{
List handToSort=new ArrayList();
收藏。复制(handToSort,hand);
Collections.sort(handToSort,newcardcomarator());
{
列表组=新的ArrayList();
对于(int i=0;i<4;i++)
{
对于(int j=8;j<13;j++)
{
System.out.println(“你通过Ace获得皇家同花顺10!!”;
回流冲洗;
}
else(int j=0;j<6;j++)
{
System.out.println(“您有一条从2到6的直线!!”;
回流冲洗;
}
else(int j=1;j<7;j++)
{
System.out.println(“您有一条从3到7的直线!!”;
回流冲洗;
}
else(int j=2;j<8;j++)
{
System.out.println(“您有一条从4到8的直线!!”;
回流冲洗;
}
else(int j=3;j<9;j++)
{
System.out.println(“您有一条从5到9的直线!!”;
回流冲洗;
}
else(int j=4;j<10;j++)
{
System.out.println(“您有一条从6到10的直线!!”;
回流冲洗;
}
else(int j=5;j<11;j++)
{
System.out.println(“你有一个通过Jack!!”的straigth 7);
回流冲洗;
}
else(int j=6;j<12;j++)
{
System.out.println(“你有一条8到皇后!!”;
回流冲洗;
}
else(int j=7;j<13;j++)
{
System.out.println(“你有一条9到国王!!”;
回流冲洗;
}

这段代码显示为一个错误,但我看不出哪里出了问题。我对编码还相当陌生,给自己设置了一个挑战,但我的程序已经吃得太多了

您的程序有一些问题

首先,您错误地使用了for循环和if-else语句。您可能打算编写的内容更像这样:

for(int i=0;i<4;i++)
{
    if(handToSort.get(i).value >= 8 || handToSort.get(i).value <=13)
    {
        System.out.println("You have a Royal Flush 10 through Ace!!");
    }
}

您也没有检查卡的套件是什么。这是检查您是否有同花顺的要求。

for
语句没有
else
组件。因此

        for (int j = 8; j < 13; j ++)
        {
            System.out.println("You have a Royal Flush 10 through Ace!!");
            return flush;
        }
        else (int j = 0; j < 6; j++)
        {
            System.out.println("You have a straigth 2 through 6!!");
            return flush;
        }
for(int j=8;j<13;j++)
{
System.out.println(“你通过Ace获得皇家同花顺10!!”;
回流冲洗;
}
else(int j=0;j<6;j++)
{
System.out.println(“您有一条从2到6的直线!!”;
回流冲洗;
}
会变成这样

        for (int j = 8; j < 13; j ++)
        {
            System.out.println("You have a Royal Flush 10 through Ace!!");
            return flush;
        }
        for (int j = 0; j < 6; j++)
        {
            System.out.println("You have a straight 2 through 6!!");
            return flush;
        }
for(int j=8;j<13;j++)
{
System.out.println(“你通过Ace获得皇家同花顺10!!”;
回流冲洗;
}
对于(int j=0;j<6;j++)
{
System.out.println(“你有一个2到6的直线!!”;
回流冲洗;
}
看起来您可能希望返回布尔值而不是整数,这会将函数的签名更改为

private boolean flush(List<PokerCard> hand)

        for (int j = 8; j < 13; j ++)
        {
            System.out.println("You have a Royal Flush 10 through Ace!!");
            return true;
        }
        for (int j = 0; j < 6; j++)
        {
            System.out.println("You have a straight 2 through 6!!");
            return true;
        }
private boolean flush(手动列表)
对于(int j=8;j<13;j++)
{
System.out.println(“你通过Ace获得皇家同花顺10!!”;
返回true;
}
对于(int j=0;j<6;j++)
{
System.out.println(“你有一个2到6的直线!!”;
返回true;
}
在所有检查的最后,您希望添加一个
return false
。这里有布尔值的其他替代方法,但似乎最适合这个问题,“这只手是齐平的吗?”


这个函数还有很多多余的代码,你可以消除它们,然后继续做同样的工作。一旦你让它工作起来,你应该投入一些精力。

你把for循环和if-else语句混在一起,为else创建了某种不神圣的
for-else
构造。Javac不喜欢这样。我建议你使用一些基本的tu保守党(以及驱魔)。
private boolean flush(List<PokerCard> hand)

        for (int j = 8; j < 13; j ++)
        {
            System.out.println("You have a Royal Flush 10 through Ace!!");
            return true;
        }
        for (int j = 0; j < 6; j++)
        {
            System.out.println("You have a straight 2 through 6!!");
            return true;
        }