运用早期知识完成作业,不足之处希望大家指正
package poke;
import java.util.Scanner;
public class gameOn {
public static void main(String[] args) {
// 建立牌组,同时赋值,同位置一一对应。
int[] pokeValue = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51 };
String[] pokeFace = { "方块2", "方块3", "方块4", "方块5", "方块6", "方块7", "方块8", "方块9", "方块10", "方块J", "方块Q", "方块K",
"方块A", "梅花2", "梅花3", "梅花4", "梅花5", "梅花6", "梅花7", "梅花8", "梅花9", "梅花10", "梅花J", "梅花Q", "梅花K", "梅花A",
"红心2", "红心3", "红心4", "红心5", "红心6", "红心7", "红心8", "红心9", "红心10", "红心J", "红心Q", "红心K", "红心A", "黑桃2",
"黑桃3", "黑桃4", "黑桃5", "黑桃6", "黑桃7", "黑桃8", "黑桃9", "黑桃10", "黑桃J", "黑桃Q", "黑桃K", "黑桃A" };
Scanner input = new Scanner(System.in);
System.out.println("玩家入场");
System.out.println("请输入1号玩家姓名:");
String cusName1 = input.next();
System.out.println("请输入2号玩家姓名:");
String cusName2 = input.next();
// System.out.println("---------------洗牌前---------------");
// for (int i = 0; i < pokeFace.length; i++) {
// System.out.print(pokeFace[i] + " ");
// } 洗牌前牌组
System.out.println("");
System.out.println("---------------洗牌huahuahua.....Loading-------------");
for (int j = 0; j < pokeFace.length; j++) {
int a = (int) (Math.random() * pokeFace.length);
String temStr;
temStr = pokeFace[j];
pokeFace[j] = pokeFace[a];
pokeFace[a] = temStr;
int temInt;
temInt = pokeValue[j];
pokeValue[j] = pokeValue[a];
pokeValue[a] = temInt;
}
// for (int i = 0; i < pokeFace.length; i++) {
// System.out.print(pokeFace[i] + " ");
// } 洗牌后牌组
//检测洗牌后效果 System.out.println(pokeFace[3]+" "+pokeValue[3]);
// 存储随机数,作为手牌
int[] cardNum = new int[4];
for (int k = 0; k < 4; k++) {
int b = (int) (Math.random() * pokeFace.length);
cardNum[k] = b;
for (int l = 0; l < k; l++) {
if (b == cardNum[l]) {
k--;
break;
}
}
}
// for(int i=0;i<cardNum.length;i++) {
// System.out.println(cardNum[i]);
// } //测试抽排合理性
System.out.print(cusName1 + "的手牌为:");
System.out.print(pokeFace[cardNum[0]] + " " + pokeFace[cardNum[1]]);
System.out.println("");
System.out.print(cusName2 + "的手牌为:");
System.out.print(pokeFace[cardNum[2]] + " " + pokeFace[cardNum[3]]);
System.out.println("");
int temCard = 0;
int p = 0;
for (int i = 0; i < cardNum.length; i++) {
if (temCard < pokeValue[cardNum[i]]) {
temCard = pokeValue[cardNum[i]];
p = i;
}
}
if (p < 2) {
System.out.println("胜者为" + cusName1);
} else {
System.out.println("胜者为" + cusName2);
}
input.close();
}
}