为了账号安全,请及时绑定邮箱和手机立即绑定

运用早期知识完成作业,不足之处希望大家指正

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();

}


}


正在回答

3 回答

你这样的话,举个例子,红桃7,8岂不是比梅花J,Q大???

0 回复 有任何疑惑可以回复我~
#1

苦天昆吾 提问者

int[] pokeValue = { 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41,45, 49, 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51 }; 设置初始值错误了,已改正
2019-05-08 回复 有任何疑惑可以回复我~

你这没按题目要求来啊,要求一人发一张,先按点数比大小,点数一样,再按花色比。

0 回复 有任何疑惑可以回复我~
#1

苦天昆吾 提问者

我是直接赋值给每张扑克了,没比牌面数值。。。疏忽了
2019-05-08 回复 有任何疑惑可以回复我~
#2

tiger爱小狄 回复 苦天昆吾 提问者

能写出来已经很厉害了,有这个逻辑和意识,年薪百万的节奏啊!
2019-05-09 回复 有任何疑惑可以回复我~

nb 刚学都看不太懂

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

运用早期知识完成作业,不足之处希望大家指正

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信