java玩扑克牌,java-玩家分的扑克牌

本实验实现为玩家分一幅扑克牌,先为扑克洗牌再分牌

实现花色和点数 的分牌,玩家人数控制台输入

看看结果

0818b9ca8b590ca3270a3433284dd417.png

package card;

import java.util.*;

class Pocker {

private String[] Pocker = new String[52];

private String[] num = new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q","K"};

private String[] flower = new String[] {"黑桃","红桃","梅花","方块"};

private String[] boss={"小王","大王"};

public Pocker () {

int n = 0;

for (int i = 0; i

for (int j = 0; j

Pocker[n++] = (flower[i] + num[j]);

}

}

}

public void print () {

for(int i = 1; i <= Pocker.length; i++) {

System.out.printf("%5s",Pocker[i -1] );

if (i % num.length == 0) {

System.out.println ();

}

}

}

public void divide(int n)

{

for (int i = 1; i < n+1; i++)

{

System.out.println( "第"+i+"个人的牌为:");

for (int j = 1+(int)(Pocker.length/n)*(i-1); j < (int)(Pocker.length/n)*i; j++)

{

System.out.printf("%5s",Pocker[j]);

if((j)%5==0)

System.out.println ();

}

System.out.println();

}

System.out.println("多余的牌");

for (int i = Pocker.length-Pocker.length%n; i

{

System.out.printf("%5s",Pocker[i]);

}

}

public void shuffle () {

for(int i = 0; i < Pocker.length; i++) {

String temp = Pocker[i];

int n = (int)(Math.random() * Pocker.length);

Pocker[i] = Pocker[n];

Pocker[n] = temp;

}

}

}

public class TestCard {

public static void main (String[] args) {

Pocker m1 = new Pocker ();

System.out.println("洗牌前");

m1.print ();

System.out.println("洗牌后");

m1.shuffle();

m1.print();

Scanner in=new Scanner(System.in);

System.out.println("输入分给多少人");

int n=in.nextInt();

m1.divide(n);

}

} 游戏逻辑挺简单,自己看代码吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值