java代码打印扑克牌 纸牌游戏java实现

java语言编程扑克牌一:import java.util.Scanner;
public class Play {
/**
* 玩牌
*/
public static void main(String[] args) {
Poker poker = new Poker();
boolean over = false;
Scanner cin=new Scanner(System.in);
while(!over){
System.out.println("打牌输入1,展示剩余牌输入其他字符:");
String c=cin.nextLine();
if("1".equals(c)){
int index= (int) (Math.random()*poker.getSize());
poker.remove(index);
}else{
poker.ShowPages();
}
}
/*for(int i = 0;i54;i++){
int index= (int) (Math.random()*poker.getSize());
poker.remove(index);
poker.ShowPages();
}
*/
}
}二://牌
public class Page { private String huase = "";
private String haoma = "";
public Page(String huase,String haoma){
this.huase = huase;
this.haoma = haoma;
}
public String show(){
return this.huase+this.haoma;
}
}三:import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* 一副扑克
*/
public class Poker {
private List pages = new ArrayList();
public Poker(){
String huase[] = new String[]{"黑桃","红桃","草花","方块"};
String haoma[] = new String[]{"A","2","3","4","5","6","7","8","9","10"
,"J","Q","K"};
for(int i = 0;ihaoma.length;i++){
for(int j = 0;jhuase.length;j++){
pages.add(new Page(huase[j],haoma[i]));
}
}
pages.add(new Page("","大王"));
pages.add(new Page("","小王"));
}
public void ShowPages(){
System.out.println("展示剩余牌:");
for(Iterator i = pages.iterator();i.hasNext();){
System.out.println(((Page)i.next()).show());
}
}
//打牌
public void remove(int index){
pages.remove(index);
}
//剩余牌数
public int getSize(){
return pages.size();
}
}
JAVA扑克牌编程1.定义扑克的对象有两个参数a 。花色,b数字Poke{intnumber,String color,Poker(String color,int number) {this.color=color;this.number=number;}} 2.每一张牌都实例化一个扑克对象 。poke1=new Poke("红桃","10");poke2=new Poke("黑桃","9"); 3.定义游戏规则类 , 类里定义一个方法,用来比较大小 。public comparePoke(Poke poke1,Poke poke2){if(花色比较){return 结果;}if(数字比较){return 结果;}} 。调用方法就能比较
JAVA 扑克牌package justforjoke.pkGame;
//花色
public class CardsType {
private static final String [] ct={
"黑桃",
"红桃",
"梅花",
"方块"
};
public static String getType(int i){
return ct[i];
}
public static int com(String s,String c){
int s1=find(s);
int s2=find(c);
if(s1==-1)return 100;
if(s2==-1)return -100;
return s2-s1;
}
private static int find(String s){
int i=-1;
for(String st:ct ){
i++;
if(st.equals(s))return i;
}
return i;
}
}
package justforjoke.pkGame;
//牌码
public class Num {
private static final String[]n={
"0","2","3","4","5","6","7","8","9","10","J","Q","K","A"
};
public static String getN(int i){
if(i1||i13)return null;
return n[i];
}
}
package justforjoke.pkGame;
//每张牌
public class Cards implements Comparable{
private String type;
private int num;
public Cards(){}
public Cards(String s,int n){
this.type=s;
this.num=n;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;

推荐阅读