今天很忙,白天都在忙着坐车,晚上回来复习了会,快要期末考试了,没什么时间看java,不想打破自己每天写博客的习惯,正好把以前写的一点东西传上来。是个扑克牌的小游戏,目前只能实现每个人抓两张牌,比较最大的那张,本来快要时间扎金花的过程了,结果忘记保存然后断电了,就一直没有补写。

6ded0b566a331a475e485a7777f02989类


public class Player {
	private String ID;
	private String name;
	public Poker handpoker;
	public Player(String ID,String name){
		this.ID=ID;
		this.name=name;
		
	}
	public String getID() {
		return ID;
	}
	public void setID(String iD) {
		ID = iD;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	
}

扑克牌类

public class Poker implements Comparable {
	private String type;
    private String num;
    public Poker(String type ,String num){
	
	this.setType(type);
	this.setNum(num);
	}
public String getType() {
	return type;
}
public void setType(String type) {
	this.type = type;
}
public String getNum() {
	return num;
}
public void setNum(String num) {
	this.num = num;
}
@Override
public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((num == null) ? 0 : num.hashCode());
	result = prime * result + ((type == null) ? 0 : type.hashCode());
	return result;
}
@Override
public boolean equals(Object obj) {
	if (this == obj)
		return true;
	if (obj == null)
		return false;
	if (getClass() != obj.getClass())
		return false;
	Poker other = (Poker) obj;
	if (num == null) {
		if (other.num != null)
			return false;
	} else if (!num.equals(other.num))
		return false;
	if (type == null) {
		if (other.type != null)
			return false;
	} else if (!type.equals(other.type))
		return false;
	return true;
}
@Override
public int compareTo(Poker o) {
	String pokernum="2,3,4,5,6,7,8,9,10,J,Q,K,A";
	String pokertype="方块,梅花,红桃,黑桃";
	int result;
	result=pokernum.indexOf(this.getNum())-pokernum.indexOf(o.getNum());
	if(result==0){
		result=pokertype.indexOf(this.getType())-pokertype.indexOf(o.getType());
	}		
	return result;
}
	
}

游戏类

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Gameplay {
	Listpokerlist=new ArrayList();
	Listplayerlist=new ArrayList();
	Listplayer1handpoker=new ArrayList();
	Listplayer2handpoker=new ArrayList();
	String[]type={"方块","梅花","红桃","黑桃"};
	String[]point={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
/**
 * 首先创建的是一副扑克牌
 */
	public void creatPoker(){
		System.out.println("开始创建扑克牌");
		for(int i=0;imaxpkList=new ArrayList();
	    maxpkList.add(pk1Max);
	    maxpkList.add(pk2Max);
	    Collections.sort(maxpkList);
	    Poker Maxpk=maxpkList.get(maxpkList.size()-1);
	    if(player1handpoker.contains(Maxpk)){
	    	System.out.println("玩家"+playerlist.get(0).getName()+"获胜!");
	    }else{
	    	System.out.println("玩家"+playerlist.get(1).getName()+"获胜!");
	    }
		
	}
		
	
	
	
	/**
	 * 
	 * @param args
	 */
	public static void main(String [] args){
		Gameplay t1=new Gameplay();
		t1.creatPlayer();
		t1.creatPoker();
		t1.testCreatPoker();
		t1.shufflepoker();
		t1.deliverPoker();
		t1.comparenum();
	
	} 
	
}