最近学了很多的知识,脑容量小,记不清,还是得做做练习!
今天就做了一个扑克牌的练习
首先呢..这个逻辑一定要非常清楚,我们要想做出一副扑克牌,必定要弄清楚每一张牌和整的一副牌
首先分析 一张扑克
一张牌里面有什么?相信大家看图(图不是我写的)就应该懂了,一张扑克有属于它自己的花色(红桃,黑桃,梅花,方块) 以及自己的点数(A,2,3…..J,Q,K)就这两种属性,对吧!
那么花色符号,点数符号是个啥? 花色符号就是来代替我们的花色的,我们不可能拿着“红桃”这种文字写进程序吧!所以我们可以用数字来代替
我们就按照下面的,一 一对应
/**
* 王 ♥ ♠ ♣ ♦
* 1 2 3 4 5
* A J Q K 小王 大王
* 1 11 12 13 14 15
**/
好了,我们已经把每张特殊一点的扑克给对应好了!我们可以开始写代码了
我的代码文件:
APoker.java————–一张扑克
Poker.java—————-一副扑克
Test.java——————测试
APoker.java先给大家展示
public class APoker {
//implements Comparable
//花色
private int color;
//点数
private int count;
//花色符号
private String colorText;
//点数符号
private String countText;
//写构造方法
public APoker(int color, int count, String colorText, String countText) {
super();
this.color = color;
this.count = count;
this.colorText = colorText;
this.countText = countText;
}
//GET SET 方法,进行封装
public int getColor() {
return color;
}
public void