0
我有一個任務,使撲克遊戲。這是它的作用:它產生5個數字(0到52之間)。這五個數字將根據它們的值轉換爲符號和實際卡片值。我需要允許用戶更換最多4張卡片,而不是給他兩次相同的卡片。我的問題是:當他改變第一張牌時,情況很好,但如果他決定改變第二張牌,第一張牌也會改變。這裏是您的幫助的代碼,並感謝(評論是在法國,如果你不明白,請讓我知道)(也忽略了未使用的方法,因爲我還沒說完呢):撲克遊戲,改變數組值
package pkgtp2;
import java.util.*;
public class TP2 {
static int[] cards = new int[5];
static int[] sortes = new int[5];
static int balance = 100;
static int h = 0;
public static void Initialiser(boolean[] pack) {
pack = new boolean[52];
}
public static void Regles() {
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(" " + " QUINTE ROYALE = 500$");
System.out.println(" Vous avez :" + balance + " $");
}
public static void findcards(int[] cards, boolean[] pack) {
System.out.println();
char symboles[] = {'♥', '♦', '♣', '♠'};
String valeurs[] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
for (int i = 0; i < cards.length; i++) {
switch (cards[i]/13) {
case 0:
System.out.print(symboles[0]);
break;
case 1:
System.out.print(symboles[1]);
break;
case 2:
System.out.print(symboles[2]);
break;
case 3:
System.out.print(symboles[3]);
break;
}
switch (cards[i] % 13 + 1) {
case 1:
System.out.print(valeurs[0]);
break;
case 2:
System.out.print(valeurs[1]);
break;
case 3:
System.out.print(valeurs[2]);
break;
case 4:
System.out.print(valeurs[3]);
break;
case 5:
System.out.print(valeurs[4]);
break;
case 6:
System.out.print(valeurs[5]);
break;
case 7:
System.out.print(valeurs[6]);
break;
case 8:
System.out.print(valeurs[7]);
break;
case 9:
System.out.print(valeurs[8]);
break;
case 10:
System.out.print(valeurs[9]);
break;
case 11:
System.out.print(valeurs[10]);
break;
case 12:
System.out.print(valeurs[11]);
break;
case 13:
System.out.print(valeurs[12]);
break;
}
System.out.println();
}
}
public static void inicartes(int[] cards, boolean[] pack) {
Random give = new Random();
for (int i = 0; i < cards.length; i++) {
do {
cards[i] = give.nextInt(52);
} while (pack[cards[i]]);
pack[cards[i]] = true;
System.out.println(cards[i]);
}
}
public static void Mélanger() {
}
public static void Afficher5cartes() {
}
public static void changecards(int[] cards, boolean[] pack) {
Scanner read = new Scanner(System.in);
int cardchange;
Random give = new Random();
System.out.println("Veuillez entrer un chiffre de 1 a 5 correspondant aux"
+ "cartes que vous voulez changer (vous pouvez changer au plus 4 cartes). Si vous voulez conserver vos cartes, entrez '0' ");
cardchange = read.nextInt();
do {
if (cardchange < 0 || cardchange > 5) {
do {
System.out.println("Erreur, veuillez entrer un chiffre de 1 a 5 correspondant aux "
+ " cartes que vous voulez changer (vous pouvez changer au plus 4 cartes). Entrez '0' lorsque vos désirez garder vos cartes ");
cardchange = read.nextInt();
} while (cardchange < 0 || cardchange > 5);
} else if (cardchange > 0 && cardchange <= 5) {
System.out.println("\nVoici votre nouvelle main");
for (int i = 0; i < cards.length; i++) {
do {
cards[cardchange - 1] = give.nextInt(52);
} while (pack[cards[cardchange - 1]]);
pack[cards[i]] = true;
System.out.println(cards[i]);
}
h++;
System.out.println("");
cardchange = read.nextInt();
}
} while (h < 4 && cardchange <= 5 && cardchange > 0);
}
public static void EvalJeu() {
}
public static void Afficher$() {
}
public static void main(String[] args) {
boolean pack[] = new boolean[52];
Regles();
inicartes(cards, pack);
findcards(cards, pack);
changecards(cards, pack);
}
}