java集合框架实践简单扑克牌比较游戏

简单的扑克牌比较游戏
1. 创建一副扑克牌,不考虑大小王
2. 创建两名玩家,玩家至少要有ID、姓名、手牌等属性
3. 洗牌,将之前创建的扑克牌顺序打乱(说明集合是有序的)
4. 发牌,将洗牌之后的扑克牌集合,从第一张开始,发给两名玩家,按照一人一张的方式,每人发两张
5. 开始游戏,比大小,取两人各自的点数最大的牌进行比较,点数大的赢,若大小相同比花色(黑红梅方)
package com.poker;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class PlayPoker {
	List cards ;  //牌
	List players;   //玩家
	//static Player[] players = new Player[2];
	PlayPoker(){
		this.cards =  new ArrayList();
		this.players = new ArrayList();
	}
	public static void main(String[] args) {		
		PlayPoker play = new PlayPoker();
		play.addCards();
		play.foreach();
		play.reCards();
		play.addplayer();
		play.playerGetCards();
		play.playerForeach();
		play.campareCards();
	}
	//加入牌52张无大小王
	public void addCards() {
		String[] colors = {"黑桃","红心","草花","方块"};
		String[] num = {"2","3","4","5","6","7","8","9","10","J","Q","K","A",};
		System.out.println("---------添加牌-------");
		for(int i = 0; i 0)
		{
			System.out.println(player1.name + "获胜");
		}
		if(card1.compareTo(card2)==0) {
			System.out.println("平");
		}
		if(card1.compareTo(card2)<0) {
			System.out.println(player2.name + "获胜");
		}
	}
	if(card1.num.compareToIgnoreCase(card2.num)>0) {
		System.out.println(player1.name + "获胜");
	}
	if(card1.num.compareToIgnoreCase(card2.num)<0) {
		System.out.println(player2.name + "获胜");
	}
}
}
package com.poker;
public class Card implements Comparable {
   public String color;
   public String num;
   public Card(String color,String num) {
	   this.color = color;
	   this.num = num;	   
   }
@Override
public int compareTo(Object o) {
	// TODO Auto-generated method stub
	return this.color.compareTo(((Card)o).color);
}
}
package com.poker;
import java.util.ArrayList;
import java.util.List;
public class Player {
		public int id;
		public String name;
		public List cards;
      public Player(int id,String name) {
    	  this.id = id;
    	  this.name = name;  
    	  this.cards = new ArrayList();
        }
      public Player()
      {
    	  this.cards = new ArrayList(); 
      }
}
package com.poker;
import java.util.Comparator;
public class CardComparator implements Comparator {
	@Override
	public int compare(Card o1, Card o2) {
		// TODO Auto-generated method stub
		return o1.num.compareTo(o2.num);
	}
}

你可能感兴趣的:(Java,Standard,Edition)