package com.peiandsky;
import java.util.Random;
import java.util.Vector;
import android.widget.Toast;
public class Poke {
public static Random rand = new Random();
public static void show(String text, int time) {
Toast t = Toast.makeText(DDZ.ddz, text, time);
t.show();
}
public static boolean inRect(int x, int y, int rectX, int rectY, int rectW,
int rectH) {
if (x < rectX || x > rectX + rectW || y < rectY || y > rectY + rectH) {
return false;
}
return true;
}
// 0-53表示54张牌
public static void shuffle(int[] pokes) {
int len = pokes.length;
// 对于54张牌中的任何一张,都随机找一张和它互换,将牌顺序打乱。
for (int l = 0; l < len; l++) {
int des = rand.nextInt(54);
int temp = pokes[l];
pokes[l] = pokes[des];
pokes[des] = temp;
}
}
public static int getDZ() {
return rand.nextInt(3);
// return 0;
}
// 对pokes进行从大到小排序,采用冒泡排序
public static void sort(int[] pokes) {
for (int i = 0; i < pokes.length; i++) {
for (int j = i + 1; j < pokes.length; j++) {
if (pokes[i] < pokes[j]) {
int temp = pokes[i];
pokes[i] = pokes[j];
pokes[j] = temp;
}
}
}
}
/**
* 16小王,17大王
*/
public static int getPokeValue(int poke) {
// 当扑克值为52时,是小王
if (poke == 52) {
return 16;
}
// 当扑克值为53时,是大王
if (poke == 53) {
return 17;
}
// 其它情况下返回相应的值(3,4,5,6,7,8,9,10,11(J),12(Q),13(K),14(A),15(2))
return poke / 4 + 3;
}
public static int getImageRow(int poke) {
return poke / 13;
}
public static int getImageCol(int poke) {
return poke % 13;
}
/**
* 是不是一个有效的牌型
*
* @param pokes
* @return
*/
public static boolean isCard(int[] pokes) {
if (getPokeType(pokes) == PokeType.error)
return false;
return true;
}
/**
* pokes中的牌的顺序要按照牌的值排列,顺牌中不包含2
*
* @param pokes
* @return
*/
public static int getPokeType(int[] pokes) {
int len = pokes.length;
// 当牌数量为1时,单牌
if (len == 1) {
return PokeType.danpai;
}
// 当牌数量为2时,可能是对牌和火箭
if (len == 2) {
if (pokes[0] == 53 && pokes[1] == 52) {
return PokeType.huojian;
}
if (getPokeValue(pokes[0]) == getPokeValue(pokes[1])) {
return PokeType.duipai;
}
}
// 当牌数为3时,只可能是三顺
if (len == 3) {
if (getPokeValue(pokes[0]) == getPokeValue(pokes[1])
&& getPokeValue(pokes[2]) == getPokeValue(pokes[1])) {
return PokeType.sanzhang;
}
}
// 当牌数为4时,可能是三带一或炸弹
if (len == 4) {
int firstCount = getPokeCount(pokes, pokes[0]);
if (firstCount == 3 || getPokeCount(pokes, pokes[1]) == 3) {
return PokeType.sandaiyi;
}
if (firstCount == 4) {
return PokeType.zhadan;
}
}
// 当牌数大于5时,判断是不是单顺
if (len >= 5) {
if (shunzi(pokes)) {
return PokeType.danshun;
}
}
// 当牌数为6时,四带二
if (len == 6) {
boolean have4 = false;
boolean have1 = false;
for (int i = 0; i < len; i++) {
int c = getPokeCount(pokes, pokes[i]);
if (c == 4) {
have4 = true;
}
if (c == 1) {
have1 = true;
}
}
if (have4 && have1) {
return PokeType.sidaier;
}
}
// 当牌数大于等于6时,先检测是不是双顺和三顺
if (len >= 6) {
// 双顺
boolean shuangshunflag = true;
for (int i = 0; i < len; i++) {
if (getPokeCount(pokes, pokes[i]) != 2) {
shuangshunflag = false;
break;
}
}
if (shuangshunflag) {
int[] tempPokes = new int[len / 2];
for (int i = 0; i < len / 2; i++) {
tempPokes[i] = pokes[i * 2];
}
if (shunzi(tempPokes)) {
return PokeType.shuangshun;
}
}
System.out.println("shuangshun:" + shuangshunflag);
// 三顺
boolean sanshunflag = true;
for (int i = 0; i < len; i++) {
if (getPokeCount(pokes, pokes[i]) != 3) {
sanshunflag = false;
break;
}
}
if (sanshunflag) {
int[] tempPokes = new int[len / 3];
for (int i = 0; i < len / 3; i++) {
tempPokes[i] = pokes[i * 3];
}
if (shunzi(tempPokes)) {
return PokeType.sanshun;
}
}
}
// 当牌数大于等于8,且能够被4整除时,判断是不是飞机
if (len >= 8 && len % 4 == 0) {
UniqInt ui = new UniqInt();
int have1 = 0;
for (int i = 0; i < pokes.length; i++) {
int c = getPokeCount(pokes, pokes[i]);
if (c == 3) {
ui.addInt(pokes[i]);
} else if (c == 1) {
have1++;
}
}
if (ui.size() == have1) {
int[] tempArray = ui.getArray();
sort(tempArray);
if (shunzi(tempArray)) {
return PokeType.feiji;
}
}
}
// 如果不是可知牌型,返回错误型
return PokeType.error;
}
/**
* 判断是不是顺子
*
* @param pokes
* @return
*/
public static boolean shunzi(int[] pokes) {
int start = getPokeValue(pokes[0]);
// 顺子中不能包含2,king
if (start >= 15) {
return false;
}
int next;
for (int i = 1; i < pokes.length; i++) {
next = getPokeValue(pokes[i]);
if (start - next != 1) {
return false;
}
start = next;
}
return true;
}
// 统计一手牌中同值的牌出现的次数来判断是对牌,三顺,三带一,炸弹,四代二等
public static int getPokeCount(int[] pokes, int poke) {
int count = 0;
for (int i = 0; i < pokes.length; i++) {
if (getPokeValue(pokes[i]) == getPokeValue(poke)) {
count++;
}
}
return count;
}
// 通过给给出的一手牌,来返回它的牌值大小,pokes中的顺序是排列好的
public static int getPokeTypeValue(int[] pokes, int pokeType) {
// 这几种类型直接返回第一个值
if (pokeType == PokeType.danpai || pokeType == PokeType.duipai
|| pokeType == PokeType.danshun || pokeType == PokeType.sanshun
|| pokeType == PokeType.shuangshun
|| pokeType == PokeType.sanzhang || pokeType == PokeType.zhadan) {
return getPokeValue(pokes[0]);
}
// 三带一和飞机返回数量为3的牌的最大牌值
if (pokeType == PokeType.sandaiyi || pokeType == PokeType.feiji) {
for (int i = 0; i <= pokes.length - 3; i++) {
if (getPokeValue(pokes[i]) == getPokeValue(pokes[i + 1])
&& getPokeValue(pokes[i + 1]) == getPokeValue(pokes[i + 2])) {
return getPokeValue(pokes[i]);
}
}
}
// 四带二返回数量为4的牌值
if (pokeType == PokeType.sidaier) {
for (int i = 0; i < pokes.length - 3; i++) {
if (getPokeValue(pokes[i]) == getPokeValue(pokes[i + 1])
&& getPokeValue(pokes[i + 1]) == getPokeValue(pokes[i + 2])
&& getPokeValue(pokes[i + 2]) == getPokeValue(pokes[i + 3])) {
return getPokeValue(pokes[i]);
}
}
}
return 0;
}
/**
* true 第一个大
*
* @param f
* @param s
* @return
*/
public static boolean compare(Card f, Card s) {
// 当两种牌型相同时
if (f.pokeType == s.pokeType) {
// 两手牌牌型相同时,数量不同将无法比较,默认为第二个大,使s不能出牌
if (f.pokes.length != s.pokes.length)
return false;
// 牌型相同,数量相同时,比较牌值
return f.value > s.value;
}
// 在牌型不同的时候,如果f的牌型是火箭,则返回true
if (f.pokeType == PokeType.huojian) {
return true;
}
if (s.pokeType == PokeType.huojian) {
return false;
}
// 排除火箭的类型,炸弹最大
if (f.pokeType == PokeType.zhadan) {
return true;
}
if (s.pokeType == PokeType.zhadan) {
return false;
}
// 无法比较的情况,默认为s大于f
return false;
}
public int[] findBigThanCard(Card card, int pokes[]) {
return null;
}
public static int[] outCardByItsself(int pokes[], Person last, Person next) {
AnalyzePoke analyze = AnalyzePoke.getInstance();
analyze.setPokes(pokes);
int cardArray[] = null;
Vector<int[]> card_danpai = analyze.getCard_danpai();
Vector<int[]> card_sanshun = analyze.getCard_sanshun();
int danpai = card_danpai.size();
int sanshun = card_sanshun.size();
i
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android源码---斗地主 (482个子文件)
all-wcprops 5KB
all-wcprops 5KB
all-wcprops 5KB
all-wcprops 1KB
all-wcprops 503B
all-wcprops 200B
all-wcprops 194B
all-wcprops 95B
all-wcprops 85B
all-wcprops 85B
all-wcprops 84B
all-wcprops 81B
all-wcprops 81B
all-wcprops 81B
all-wcprops 81B
resources.ap_ 1.93MB
DDZGameForBook.apk 1.96MB
Poke.class 13KB
AnalyzePoke.class 10KB
Desk.class 10KB
Person.class 5KB
MenuView.class 4KB
GameView.class 3KB
Card.class 2KB
R$drawable.class 2KB
DDZ.class 1KB
GameView$1.class 1KB
UniqInt.class 1KB
MenuView$1.class 1KB
DDZ$1.class 937B
PokeType.class 552B
R.class 459B
R$string.class 412B
R$layout.class 379B
R$attr.class 325B
.classpath 280B
Thumbs.db 89KB
Thumbs.db 89KB
Thumbs.db 89KB
classes.dex 41KB
entries 6KB
entries 6KB
entries 6KB
entries 2KB
entries 833B
entries 345B
entries 342B
entries 279B
entries 213B
entries 213B
entries 207B
entries 203B
entries 203B
entries 196B
entries 193B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
Poke.java 25KB
AnalyzePoke.java 16KB
Desk.java 11KB
Person.java 5KB
MenuView.java 4KB
R.java 3KB
GameView.java 2KB
Card.java 1KB
DDZ.java 1KB
UniqInt.java 839B
PokeType.java 294B
poker3552.png 108KB
poker3552.png 108KB
poker3552.png 108KB
vbg1.png 97KB
vbg1.png 97KB
vbg1.png 97KB
fg.png 80KB
fg.png 80KB
fg.png 80KB
menubk.png 74KB
menubk.png 74KB
menubk.png 74KB
vbg2.png 66KB
vbg2.png 66KB
vbg2.png 66KB
jiaodz.png 47KB
jiaodz.png 47KB
jiaodz.png 47KB
menu.png 41KB
共 482 条
- 1
- 2
- 3
- 4
- 5
Bison
- 粉丝: 43
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页