/** * @author FANGSUO2CPU * */ package playGameF; import java.util.List; import java.util.Scanner; import java.util.ArrayList; public class Players { private int id; private String name; } public Players() { } public Players(int id,String name) { this.id =id; this.name =name; } public int getId() { return id; } public String getName() { return name; } private List<Players> handOfPoke = new ArrayList<Players>();//存放玩家 //创建玩家,并存放List<Players> handOfPoke列表 public void createPlayer() { Scanner input=new Scanner(System.in); for(int i=0;i<2;i++) {//i设置玩家个数 System.out.println("---------输入玩家的姓名:------------"); handOfPoke.add(new Players(i,input.next())); } input.close(); } //打印玩家 public void printPlayer() { System.out.println("---------打印玩家的ID和姓名:-----------"); for(int i=0;i<handOfPoke.size();i++) { System.out.println(handOfPoke.get(i).id+" "+ handOfPoke.get(i).name+" "); } } public List<Players> getPlayers(){ return handOfPoke; } } /** * @author FANGSUO2CPU * */ package playGameF; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Poke { private String point; private String flower; public Poke() { } public Poke(String flower, String point) { this.flower =flower; this.point =point; } private static final String[] points={"2","3","4","5","6","7","8","9","10","J","Q","K","A"}; private static final String[] flowers= {"方","梅","红","黑"}; private List<Poke> pokes=new ArrayList<>();//用于存放扑克牌 /*public static String[] getPoint() { return points; } public static String[] getFlower() { return flowers; }*/ //创建扑克牌放入List<Poke> Pokes列表 public void createPoke() { for(int i=0; i < flowers.length; i++) { for(int j=0; j < points.length; j++) { pokes.add(new Poke( flowers[i],points[j])); } } System.out.println("创建扑克牌成功!"); } //打印扑克牌 public void printPoke() { System.out.println("打印扑克牌:"); for(int i=0;i<pokes.size();i++) { System.out.print(pokes.get(i).flower+pokes.get(i).point+" "); } System.out.println(); System.out.println("总计:"+pokes.size()); } //洗牌 public void shuffle() { Collections.shuffle(pokes); System.out.println("洗牌后:"); for(int i=0;i<pokes.size();i++) { System.out.print(pokes.get(i).flower+pokes.get(i).point+" "); } System.out.println(); System.out.println("总计:"+pokes.size()); } public List<Poke> getPoke(){ return pokes; } }
/** * @author FANGSUO2CPU * */ package playGameF; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class PokeGame { public static void main(String[] args) { // TODO 自动生成的方法存根 List<String> playerHavePoke =new ArrayList<String>();//??????????? Players play=new Players(); play.createPlayer(); Poke p=new Poke(); p.createPoke(); p.shuffle(); //发牌 for(int i=0; i<play.getPlayers().size(); i++) {//人数 playerHavePoke.add(play.getPlayers()); System.out.println("playerHavePoke.get("+i+"):"+playerHavePoke.get(i)); } } }
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦