Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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_Loops_Conditional Statements - Fatal编程技术网

Java 程序执行并无故停止

Java 程序执行并无故停止,java,loops,conditional-statements,Java,Loops,Conditional Statements,所以我为我的任务做了一个扑克游戏。 这一切都很好(至少我相信是这样)。简单来说:玩家有100美元的余额,根据他的手牌,赢钱或输钱。 我提出了一个条件,只要玩家的平衡力高于,游戏就会继续给他一个新牌。 然而,在7或8次重新启动后,程序只显示白色,并且无论您键入什么,它都将永远运行 这是代码,希望你们能提供帮助。另外,如果大部分代码都是法语,很抱歉,我用英语对这些方法进行了评论,以帮助你们理解: package pkgtp2; import java.util.*; public class T

所以我为我的任务做了一个扑克游戏。
这一切都很好(至少我相信是这样)。简单来说:玩家有100美元的余额,根据他的手牌,赢钱或输钱。
我提出了一个条件,只要玩家的平衡力高于,游戏就会继续给他一个新牌。
然而,在7或8次重新启动后,程序只显示白色,并且无论您键入什么,它都将永远运行

这是代码,希望你们能提供帮助。另外,如果大部分代码都是法语,很抱歉,我用英语对这些方法进行了评论,以帮助你们理解:

package pkgtp2;

import java.util.*;

public class TP2 {

static boolean straight;
static boolean flush;
static int paires;
static int gains;
static int balance = 100;
static char[] cardsSymbols = new char[5];
static String[] cardsValues = new String[5];
static int hand[] = new int[5];
static boolean pack[] = new boolean[52];

public static void menu(int gains) {
    System.out.println("**************            " + " AUCUNE COMBINAISON = -10$");
    System.out.println("*Jeu de Poker*            " + " 1 PAIRE = 0$");
    System.out.println("**************            " + " 2 PAIRES = 20$");
    System.out.println("                          " + " BRELAN <3> = 35$");
    System.out.println("                          " + " SUITE = 50$");
    System.out.println("                          " + " FULL = 75$");
    System.out.println("                          " + " COULEUR = 100$");
    System.out.println("                          " + " CARRÉ = 150$");
    System.out.println("                          " + " STRAIGHT FLUSH = 500$");
} // The Game Menu showing every possible hand

public static void drawCards(int[] hand, boolean[] pack) {

    Random give = new Random();

    for (int i = 0; i < hand.length; i++) {
        do {
            hand[i] = give.nextInt(52);
        } while (pack[hand[i]]);
        pack[hand[i]] = true;
    }
} // Gives the user 5 unique random numbers

public static void cardSymbol(int[] cards, char[] cardssymbols) {
    char symboles[] = {'♥', '♦', '♣', '♠'};
    int numOfSymbol;
    for (int i = 0; i < cards.length; i++) {
        numOfSymbol = cards[i] / 13;
        cardsSymbols[i] = symboles[numOfSymbol];
    }

} // Converts the 5 numbers into values

public static void cardValue(int[] cards, String[] cardsvalues) {
    String valeurs[] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
    int numOfValues;
    for (int i = 0; i < cards.length; i++) {
        numOfValues = cards[i] % 13;
        cardsValues[i] = valeurs[numOfValues];
    }
} // Converts the 5 numbers into actual cards values

public static void printCards(char[] cardsymbols, String[] cardsvalues) {
    System.out.println("Voici vos cartes : \n");
    for (int i = 0; i < hand.length; i++) {
        System.out.print(cardsymbols[i]);
        System.out.print(cardsvalues[i] + "   ");
    }
} // Prints the Cards

public static void changeCards(int[] cards, boolean[] pack) {
    Scanner read = new Scanner(System.in);
    int cardchange = 0;
    Random give = new Random();
    System.out.println();

    for (int i = 0; i < 4; i++) {
        do {
            System.out.println(" Entrez des chiffres de 1 à 5 correspondant aux cartes que vous désirez changer (vous pouvez changer au plus 4 cartes)"
                    + " \n Si vous voulez conserver vos cartes, entrez 0 ");
            while (!read.hasNextInt()) {
                System.out.println("Veuillez entrer un chiffre ");
                read.next();
            }
            cardchange = read.nextInt();
        } while (cardchange < 0 || cardchange > 5);

        if (cardchange == 0) {
            i = 5;
        } else {
            System.out.print("\nLa carte  " + cardchange + " va être changée\n ");
            do {
                cards[cardchange - 1] = give.nextInt(52);
            } while (pack[cards[cardchange - 1]]);
            pack[cards[cardchange - 1]] = true;
        }

        cardSymbol(cards, cardsSymbols);
        cardValue(cards, cardsValues);
        printCards(cardsSymbols, cardsValues);

    }

} // Lets the user change up to 4 cards, press 0 to not change any card and skip

public static int checkPairs(char[] cardsSymbols, String[] cardsvalues) {
    int paires = 0;
    for (int i = 0; i < cardsvalues.length; i++) {
        for (int j = i + 1; j < cardsvalues.length; j++) {
            if (cardsvalues[i].equals(cardsvalues[j])) {
                paires++;
            }
        }
    }
    return paires;
} // Checks if the cards values match so the program can determine if the user has a pair, two pair, three of a kind, full house or quads

public static boolean checkFlush(char[] cardsSymbols) {
    boolean flush = false;
    if (cardsSymbols[0] == cardsSymbols[1] && cardsSymbols[1] == cardsSymbols[2] && cardsSymbols[2] == cardsSymbols[3] && cardsSymbols[3] == cardsSymbols[4]) {
        flush = true;
    }
    return flush;
} // checks for a flush

public static boolean checkStraight(String[] cardsvalues) {
    boolean straight = false;
    int numOfValues;
    int[] straightTab = new int[5];
    for (int i = 0; i < hand.length; i++) {
        numOfValues = hand[i] % 13;
        straightTab[i] = numOfValues;
    }
    Arrays.sort(straightTab);

    if (straightTab[0] + 1 == straightTab[1] && straightTab[1] + 1 == straightTab[2] && straightTab[2] + 1 == straightTab[3] && straightTab[3] + 1 == straightTab[4]) {
        straight = true;
    }
    return straight;
} // checks for a straight

public static int combinaisons(int paires, boolean straight, boolean flush) {
    int gains;
    if (straight && flush) {
        System.out.println("Vous avez une Quinte !");
        gains = 500;
    } else if (flush) {
        System.out.println("Vous avez une Couleur !");
        gains = 100;
    } else if (straight) {
        System.out.println("Vous avez une Suite !");
        gains = 50;
    } else if (paires == 6) {
        System.out.println("Vous avez un Carré !");
        gains = 150;
    } else if (paires == 4) {
        System.out.println("Vous avez un Full !");
        gains = 75;
    } else if (paires == 3) {
        System.out.println("Vous avez un Brelan !");
        gains = 35;
    } else if (paires == 2) {
        System.out.println("Vous avez Deux Paires !");
        gains = 20;
    } else if (paires == 1) {
        System.out.println("Vous avez une Paire !");
        gains = 0;
    } else {
        System.out.println("Vous n'avez Aucune Combinaison !");
        gains = -10;
    }
    return gains;
} // gives the user money based on his hand strength

public static int profit(int gains) {
    balance = balance + gains;
    System.out.println("Vos gains sont  de " + gains + " $");
    System.out.println("Vous avez donc " + balance + " $");
    return gains;
} // Gives the user his profit and his new balance

public static void main(String[] args) { 
    do {
        menu(gains);
        drawCards(hand, pack);
        cardSymbol(hand, cardsSymbols);
        cardValue(hand, cardsValues);
        printCards(cardsSymbols, cardsValues);
        changeCards(hand, pack);
        paires = checkPairs(cardsSymbols, cardsValues);
        flush = checkFlush(cardsSymbols);
        straight = checkStraight(cardsValues);
        gains = combinaisons(paires, straight, flush);
        profit(gains);
    }while (balance > 0);
    }// Here is my problem, the program just stops for a reason ...

}
包pkgtp2;
导入java.util.*;
公共级TP2{
静态布尔直;
静态布尔刷新;
静态整数对;
静态整数增益;
静态整数平衡=100;
静态字符[]cardsSymbols=新字符[5];
静态字符串[]cardsValues=新字符串[5];
静态int hand[]=新int[5];
静态布尔包[]=新布尔值[52];
公共静态无效菜单(整数增益){
System.out.println(“**********”+“AUCUNE组合=-10$”;
System.out.println(“*Jeu de Poker*”+“1 PAIRE=0$”;
System.out.println(“*************”+“2对=20$”;
System.out.println(“+”BRELAN=35$”;
System.out.println(“+”SUITE=50$”;
System.out.println(“+”FULL=75$”;
System.out.println(“+”COULEUR=100$”;
System.out.println(“+”CARRÉ=150$”;
System.out.println(“+”直齐=500$”;
}//显示每一手牌的游戏菜单
公共静态无效提款卡(整数[]手,布尔[]包){
随机给定=新随机();
对于(int i=0;i5);
如果(cardchange==0){
i=5;
}否则{
系统输出打印(“\nLa carte”+cardchange+“vaêtre change\n”);
做{
卡片[cardchange-1]=give.nextInt(52);
}而(打包(卡片(换卡1));;
pack[卡片[cardchange-1]]=true;
}
卡片符号(卡片、卡片符号);
cardValue(卡片、CardsValue);
打印卡(卡片符号、卡片值);
}
}//允许用户最多更改4张卡,按0不更改任何卡并跳过
公共静态int校验对(char[]cardsSymbols,String[]cardsvalue){
整数对=0;
for(int i=0;ipublic static void reset_pack(){
    for(int i=0; i<pack.length;i++){
        pack[i] = false;
    }
}
...
profit(gains);
reset_pack();
for (int i=0;i<hand.length;i++){
pack[hand[i]] = false;
}