package mooc;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
public class puke implements Comparable<puke> {
String name;
String num;
Integer j;
public puke(Integer j,String name,String num){
this.name=name;
this.num=num;
this.j=j;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getnum() {
return num;
}
public void setnum(String num) {
this.num = num;
}
public int getj() {
return j;
}
public void setj(Integer j) {
this.j = j;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("——————————————创建扑克牌——————————————");
System.out.println("——————————————扑克牌创建成功——————————————");
List<puke>list=new ArrayList<>();
int k=5;
for(int i=2;i<11;i++){
list.add(new puke(k,"方块",""+i));
list.add(new puke(k+1,"梅花",""+i));
list.add(new puke(k+2,"红桃",""+i));
list.add(new puke(k+3,"黑桃",""+i));
k=k+4;
}
list.add(new puke(3,"红桃","A"));
list.add(new puke(43,"红桃","j"));
list.add(new puke(47,"红桃","Q"));
list.add(new puke(51,"红桃","K"));
list.add(new puke(4,"黑桃","A"));
list.add(new puke(44,"黑桃","j"));
list.add(new puke(48,"黑桃","Q"));
list.add(new puke(52,"黑桃","K"));
list.add(new puke(2,"梅花","A"));
list.add(new puke(42,"梅花","j"));
list.add(new puke(46,"梅花","Q"));
list.add(new puke(50,"梅花","K"));
list.add(new puke(1,"方块","A"));
list.add(new puke(41,"方块","j"));
list.add(new puke(45,"方块","Q"));
list.add(new puke(49,"方块","K"));
Iterator<puke>it=list.iterator();
while(it.hasNext()){
puke pk=(puke) it.next();
System.out.println(pk.j+pk.name+pk.num);
}
System.out.println("——————————————开始洗牌——————————————");
Collections.shuffle(list);
System.out.println("——————————————洗牌结束——————————————");
System.out.println("创建玩家");
System.out.println("请输入第一位玩家的ID和姓名");
System.out.println("请输入ID");
Scanner input=new Scanner(System.in);
int id1=input.nextInt();
System.out.println("请输入姓名");
String name1=input.next();
System.out.println("请输入第二位玩家的ID和姓名");
System.out.println("请输入ID");
int id2=input.nextInt();
System.out.println("请输入姓名");
String name2=input.next();
System.out.println("——————————————欢迎玩家"+name1);
System.out.println("——————————————欢迎玩家"+name2);
System.out.println("——————————————开始发牌——————————————");
System.out.println("玩家"+name1+"拿牌");
List<puke>wj1=new ArrayList<>();
wj1.add((puke)list.get(0));//玩家1的第1张手牌
System.out.println("玩家"+name2+"拿牌");
List<puke>wj2=new ArrayList<>();
wj2.add((puke)list.get(1));//玩家2的第1张手牌
System.out.println("玩家"+name1+"拿牌");
wj1.add((puke)list.get(2));//玩家1的第2张手牌
System.out.println("玩家"+name2+"拿牌");
wj2.add((puke)list.get(3));//玩家2的第2张手牌
System.out.println("——————————————发牌结束——————————————");
System.out.println("——————————————开始游戏——————————————");
Collections.sort(wj1);
puke max1 =wj1.get(1);
System.out.println("玩家"+name1+"最大手牌为"+max1.name+max1.num);
Collections.sort(wj2);
puke max2 =wj2.get(1);
System.out.println("玩家"+name2+"最大手牌为"+max2.name+max2.num);
if(max1.j>max2.j){
System.out.println("玩家"+name1+"胜利");
}else{
System.out.println("玩家"+name2+"胜利");
}
for(puke max:wj1){
System.out.println("玩家"+name1+"手牌为"+max.name+max.num);
}
for(puke max:wj2){
System.out.println("玩家"+name2+"手牌为"+max.name+max.num);
}
}
@Override
public int compareTo(puke o) {
// TODO Auto-generated method stub
return this.j.compareTo(o.j);
}
}
点击查看更多内容
8人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦