目前类的结构如下(部分在前面已经描述过):
其中的方法在(一)中已经描述,主要fightlord包
-------------------------
Squeezer.java
牌的描述类
/*
* Created on 2006-3-20
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.leqi.fightlord;
/**
* * @author Administrator
*
* create 2006-3-20
*
* msn: lesqi1027@hotmail.com
*
* qq: 26826880
*
* mail: filippo.le@gmail.com
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Squeezer {
private byte type = 1;
private byte value = 2;
private byte sign = 0;
/**
*
*/
public Squeezer() {
super();
// TODO Auto-generated constructor stub
}
/**
* @return Returns the type.
*/
public byte getType() {
return type;
}
/**
* @param type The type to set.
*/
public void setType(byte type) {
this.type = type;
}
/**
* @return Returns the value.
*/
public byte getValue() {
return value;
}
/**
* @param value The value to set.
*/
public void setValue(byte value) {
this.value = value;
}
/**
* @return Returns the sign.
*/
public byte getSign() {
return sign;
}
/**
* @param sign The sign to set.
*/
public void setSign(byte sign) {
this.sign = sign;
}
}
------------------------
InitSqueezer.java
对54张牌进行初始化工作
/*
* Created on 2006-3-20
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.leqi.fightlord;
/**
* * @author Administrator
*
* create 2006-3-20
*
* msn: lesqi1027@hotmail.com
*
* qq: 26826880
*
* mail: filippo.le@gmail.com
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class InitSqueezer {
public static Squeezer[] init(){
Squeezer squeezer;
Squeezer[] squeezers = null;
squeezers = new Squeezer[54];
int i = 0;
byte type = 8;
int value = 1;
for(type = 8; type >= 1;type >>>=1){
for(value = 1; value < 14; i++, value++){
squeezer = new Squeezer();
squeezer.setType(type);
squeezer.setValue((byte)value);
squeezer.setSign((byte)(0));
squeezers[i] = squeezer;
}
}
squeezer = new Squeezer();
squeezer.setType(type);
squeezer.setValue((byte)0);
squeezer.setSign((byte)(0));
squeezers[i] = squeezer;
i++;
squeezer = new Squeezer();
squeezer.setType(type);
squeezer.setValue((byte)1);
squeezer.setSign((byte)(0));
squeezers[i] = squeezer;
return squeezers;
}
}
-------------------------------
Deal.java
这是游戏初始的一个关键类,根据斗地主游戏的规则,对InitSqueezer类初始好的牌进行分发:随机保留下三张牌,做为底牌,将剩下的51张牌随机分配给三个用户。
/*
* Created on 2006-3-20
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.leqi.fightlord;
import java.util.Random;
/**
* * @author Administrator
*
* create 2006-3-20
*
* msn: lesqi1027@hotmail.com
*
* qq: 26826880
*
* mail: filippo.le@gmail.com
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Deal {
private static Squeezer[] squeezers;
/**
*
*/
public Deal() {
super();
// TODO Auto-generated constructor stub
}
public static Squeezer[] deal(Squeezer[] squs) {
squeezers = squs;
Random random = new Random();
//随机找出三张做底牌
for(int i=0; i<3;){
int n = 0;
n = random.nextInt();
n>>>=26;
byte sign = (byte)(n%54);
if(squeezers[sign].getSign() == (byte)0){
squeezers[sign].setSign((byte)4);
i++;
}
}
//将剩下的51张牌随机分为三份
//设置第1份
for(int i=0; i<17;){
int n = 0;
n = random.nextInt();
n>>>=26;
byte sign = (byte)(n%54);
if(squeezers[sign].getSign() == (byte)0){
squeezers[sign].setSign((byte)1);
i++;
}
}
// 设置第2份
for(int i=0; i<17;){
int n = 0;
n = random.nextInt();
n>>>=26;
byte sign = (byte)(n%54);
if(squeezers[sign].getSign() == (byte)0){
squeezers[sign].setSign((byte)2);
i++;
}
}
// 设置第3份
for(int i=0; i<54; i++){
if(squeezers[i].getSign() == (byte)0){
squeezers[i].setSign((byte)3);
}
}
//打印分牌的信息
// for(int i=0; i<54; i++){
// System.out.println(squeezers[i].getSign()+"hava:"
// + squeezers[i].getType()+"values:" +
// squeezers[i].getValue());
// }
return squeezers;
}
}