扑克牌游戏
poker类
public class poker { String color; String number; public poker(String color,String number){ this.color=color; this.number=number; } }
player类
import java.util.ArrayList; import java.util.List; public class player { String name; List<poker> shoupai=new ArrayList<poker>(); public player(String name){ this.name=name; } }
playPoker类
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class playPoker { public static void main(String[] args) { System.out.println("-----创建扑克牌-----"); List<poker> poker=new ArrayList<poker>(); String[] color = {"黑桃", "红桃", "梅花", "方片"}; String[] number = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J","Q","K", "A"}; for(int i=0;i<color.length;i++) for(int j=0;j<number.length;j++){ poker.add(new poker(color[i], number[j])); } System.out.println("-----扑克牌创建成功!-----"); System.out.print("当前的扑克牌为:"); for(int i=0;i<poker.size();i++){ System.out.print(poker.get(i).color + poker.get(i).number+ " "); } System.out.println(); System.out.println("-----开始洗牌-----"); Collections.shuffle(poker); System.out.println("-----洗牌结束-----"); List<player> player=new ArrayList(); Scanner in=new Scanner(System.in); System.out.println("请输入1号玩家姓名:"); String name=in.next(); player.add(new player(name)); System.out.println("请输入2号玩家姓名:"); String name2=in.next(); player.add(new player(name2)); System.out.println("欢迎"+player.get(0).name); System.out.println("欢迎"+player.get(1).name); System.out.println("-----开始发牌-----"); int count=0; for(int i=0; i<2;i++){ for(int j=0; j< player.size(); j++){ System.out.println(">玩家"+player.get(j).name+"拿牌"); player.get(j).shoupai.add(poker.get(count)); count++; } } System.out.println("-----发牌结束-----"); System.out.println("-----开始游戏 -----"); for(int i=0;i<player.size();i++){ System.out.print("玩家"+player.get(i).name+"的手牌为:[ "); for(int j=0;j<player.get(i).shoupai.size();j++){ System.out.print(player.get(i).shoupai.get(j).color+player.get(i).shoupai.get(j).number+" "); } System.out.println(" ]"); } } }
运行截图
还未完成比较功能,明天继续完成