package com.GameDemo; public class GameDemo { public static void main(String[] args) { Room s=new Room(); //启动游戏 s.start(); } }
package com.GameDemo; public class Card { private String number; private String color; //每张牌存在大小 private int size; public Card() { } public Card(String number, String color, int size) { this.number = number; this.color = color; this.size = size; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public int getSize() { return size; } public void setSize(int size) { this.size = size; } @Override public String toString() { return color + number; } }
package com.GameDemo; import java.util.*; public class Room { //必须有一副牌 private List<Card> allCard=new ArrayList<>(); //无参构造器 public Room(){ //1.做出54张牌,存入到集合allCard //a.点数:个数确定了,类型确定 String[] numbers={"3","4","5","6","7","8","9","10","J","Q","K","A","2"}; //b.花色:个数确定了,类型确定 String[] colors={"♠","♥","♣","♦"}; int size=0;//表示每张牌大小 //c.遍历点数:再遍历花色,组织牌 for (String number : numbers) { //number="3" size++;//1 2 ..... for (String color : colors) { //得到一张牌 Card c=new Card(number,color,size); allCard.add(c); } } //单独存入小大王 Card c1=new Card(""," 标签:String,斗地主,number,allCard,案例,集合,public,Card,size From: https://www.cnblogs.com/Karl-hut/p/17452786.html