300行能干啥啊,你还不如自己做做练习题。
package suoha;
import java.util.ArrayList;import java.util.Random;
public class MainFunction {
private ArrayList<MyCard> cards = new ArrayList<MyCard>();
private int[] cardNumArr = new int[52];
private int[] mycards = new int[5];
private int[] p1cards = new int[5];
public static void main(String[] args) {
MainFunction mainfunc = new MainFunction();
mainfunc.makeCards();
mainfunc.cardNumArr = mainfunc.shuffleCards(mainfunc.cardNumArr);
mainfunc.catchCards();
mainfunc.showAllCardsOfHand();
//mainfunc.printNums();
}
/**
* 洗牌
* @param cardNums
* @return
*/
private int[] shuffleCards(int[] cardNums){
int size = cardNums.length;
int[] returnNums = new int[size];
//System.out.println(cardNums[0]+"=========================");
Random rand = new Random();
for(int i=size-1;i>0;i--){
int nextInt = rand.nextInt(i);
returnNums[size-1-i] = cardNums[nextInt];
cardNums[nextInt] = cardNums[i];
cardNums[i] = returnNums[size-1-i];
//System.out.println("suijishu:"+nextInt+"||zhi:"+returnNums[size-1-i]);
}
returnNums[size-1] = cardNums[0];
return returnNums;
}
/**
* 抓牌
*/
private void catchCards(){
for(int i=0;i<5;i++){
mycards[i] = cardNumArr[2*i];
p1cards[i] = cardNumArr[2*i+1];
}
}
private void showAllCardsOfHand(){
System.out.print("你手中的牌是:||");
for(int i=0;i<5;i++){
MyCard myCard = cards.get(mycards[i]-1);
System.out.print(myCard.toString()+"||");
}
System.out.println();
System.out.print("对家手中的牌是:||");
for(int i=0;i<5;i++){
MyCard myCard = cards.get(p1cards[i]-1);
System.out.print(myCard.toString()+"||");
}
}
/**
* 显示牌的顺序
*/
private void printNums(){
for(int i=0;i<cardNumArr.length;i++){
System.out.print(cardNumArr[i]+",");
}
}
/**
* 制作卡片
*/
private void makeCards(){
for(int i=1;i<=13;i++){
for(int j=1;j<=4;j++){
//System.out.println((i-1)*4+j);
MyCard card = new MyCard((i-1)*4+j, j, i);
cardNumArr[(i-1)*4+j-1] = (i-1)*4+j;
cards.add(card);
}
// MyCard card1 = new MyCard((i-1)*4+1, 1, i);
// MyCard card2 = new MyCard((i-1)*4+2, 2, i);
// MyCard card3 = new MyCard((i-1)*4+3, 3, i);
// MyCard card4 = new MyCard((i-1)*4+4, 4, i);
// cards.add(card1);
// cards.add(card2);
// cards.add(card3);
// cards.add(card4);
}
}
}
追问请问您的qq是?
追答495386023