进度描述

此次对《java项目:炉石传说》进行了更新,来到ver 2.0。

更新内容

新添玩法:

  1. (Cost)费用:每个随从都有召唤费用,通常为 (AP+HP)/2,需要消耗对应的水晶才能召唤进战场;

  2. (CardLibrary)牌库:游戏开始时,给每个玩家初始化30张牌(随从),相同的随从可以重复出现最多3次;

  3. (Cemetery)墓地:随从被击杀时,将从战场中移出,并置入每个玩家各自拥有的墓地中;

  4. (HandCard)手牌:游戏开始时,每个玩家从牌库中依序抽出前3张牌作为手牌,手牌最多10张;

  5. 先手:游戏通过抛硬币的方式决定先手玩家;(等概率公平随机)

  6. 抽牌:先手玩家从自己的牌库中抽第4张牌并开始游戏;每个玩家在自己回合开始时都会抽1张牌;若牌库没有牌可抽,将按1、2、4、8的方式扣除英雄的生命值(直至英雄死亡);若手牌已有10张, 抽牌后11张,则需要选择1张牌置入墓地后再继续其他操作。

  7. 水晶:每个回合开始时玩家将收获水晶;水晶在回合结束后将清空;第1回合双方拥有2个水晶,此后每个回合增加1个水晶,直到达到最大值10个水晶。

代码说明

由于暂时还没找炉石的牌库,所以决定先随机生成卡牌(名称、攻击力、生命值),并用牌堆(CardPile)储存。

Role类

public Role(){
	this.hero = new Hero();
	this.Servant = new battlefiledCard();
	crystal = 2;
	this.handCard = new HandCard();
	this.cemetery = new Cemetery();	
	this.cardLibrary = new CardLibrary();
}

public Hero hero;
public battlefiledCard Servant;
public int crystal;
public HandCard handCard;
public Cemetery cemetery;
public CardLibrary cardLibrary;

public void getCrystal() {
	this.crystal++;
}

public int checkCrystal() {
	return this.crystal;
}

public void Draw() {
	this.handCard.Add(cardLibrary.CardInit.get(0));
	this.cardLibrary.Remove(0);
}

public void Deployment(int attacker,int hCard) {
	this.Servant.servant.add(attacker, handCard.handCard.get(hCard));
	this.handCard.remove(hCard);
}

抽卡行为Draw和部署行为Deployment,以及一些新添的内容

Hero类

public int HP;
public String name;
public Skill skill;
public Hero(){
	System.out.println("请选择你想要的英雄:");
	Scanner scanner = new Scanner(System.in);
	this.name = scanner.next();
	this.HP = 30;
	this.skill = new Skill();
	String Name = name;
	skill.getSkillType(Name);
	skill.getSkill();
}
public void hurt(int hurtHP) {
	this.HP -= hurtHP;
}
public int getHP() {
	return HP;
}

新添技能Skill和name

battlefiledCard类(原Servant类)

ArrayList<Card> servant;
public battlefiledCard(){this.servant = new ArrayList<Card>();}

public void hurt(int defender,int injure) {
	this.servant.get(defender).HP -= injure;
	
}
public void remove(int defender) {
	this.servant.remove(defender);
}

更名为战场牌(battlefiledCard类)

Cemetery类

ArrayList<Card> dead;
public Cemetery(){
	dead = new ArrayList<Card>();
}
public void add(Card gee) {
	dead.add(gee);
}

墓地

Skill类

public String type;
public int cost;
public int value;
public Skill(){}
public void getSkillType(String name) {
	if(name.equals("pastor") == true) {
		System.out.println("你选择的英雄是牧师");
		this.type = "cure";
	}
	else if(name.equals("hunter") == true) {
		System.out.println("你选择的英雄是猎人");
		this.type = "attack";
	}
	else {
		this.type = null;
	}
}
public void getSkill() {
	if(type == "cure") {
		this.cost = 2;
		this.value = 2;
	}
	if(type == "attack") {
		this.cost = 2;
		this.value = 2;
	}
}

此为所选英雄技能的初始化。

Card类

public String name;
	public int cost;
	public int AP;
	public int HP;
	public void CardBuild(){
		this.name = getStringRandom(5);
		this.cost = getCostRandom();
		this.AP = getAPRandom();
		this.HP = getHPRandom();
	}
	//生成随机卡牌费用
	public int getCostRandom() {
		Random random = new Random();
		int expense = random.nextInt(10) + 1;
		return expense;
	}
	//生成随机用户名,数字和字母组成,
    public String getStringRandom(int length) {

        String val = "";
        Random random = new Random();

        //参数length,表示生成几位随机数
        for(int i = 0; i < length; i++) {

            String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
            //输出字母还是数字
            if( "char".equalsIgnoreCase(charOrNum) ) {
                //输出是大写字母还是小写字母
                int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
                val += (char)(random.nextInt(26) + temp);
            } else if( "num".equalsIgnoreCase(charOrNum) ) {
                val += String.valueOf(random.nextInt(10));
            }
        }
        return val;
    }
    //生成随机卡牌的攻击力
    public int getAPRandom() {
    	Random random = new Random();
    	int Ap;
    	Ap = random.nextInt(cost + 2) + 1;
    	return Ap;
    }
    //生成随机卡牌的生命值
    public int getHPRandom() {
    	Random random = new Random();
    	int AHp,Hp;
    	AHp = random.nextInt(3*cost+1-AP) + AP+1;
    	Hp = AHp - AP;
    	return Hp;
    }

此为卡牌类,包括卡牌的基础属性、费用、以及卡牌的初始化方法。初始化方法用的是随机生成数值,并带有根据费用带来的一定限制。

CardPile类

ArrayList<Card> TotalCard;
	public CardPile(){
		this.TotalCard = new ArrayList<Card>();	
		Card aCard = new Card();
		for(int i = 0;i < 100;i ++) {			
			aCard.CardBuild();
			this.TotalCard.add(aCard);
		}
	}

简单的生成一个牌堆。

CardLibrary类

ArrayList<Card> CardInit;
	public CardLibrary(){		
		this.CardInit = new ArrayList<Card>();
	}
	public void Init(ArrayList<Card>TotalCard) {
		Random random = new Random();
		int judge[] = new int[100];
		int select,amount,sum = 0;
		while(sum<30) {
			select = random.nextInt(100);
			amount = random.nextInt(3) + 1;
			if(sum > 27) amount = 30 - sum;  
			while(judge[select] == 1) {
				select = random.nextInt(100);
			}
			judge[select] = 1;
			for(int i = 0;i < amount;i ++) {
				this.CardInit.add(TotalCard.get(select));
			}
			sum += amount;
		}		
	}
	public void Remove(int delete) {
		this.CardInit.remove(delete);
	}

生成玩家自己的牌库,从牌堆中随机挑选(暂时先随机挑选吧)。

HandCard类

ArrayList<Card> handCard;
	public HandCard() {
		this.handCard = new ArrayList<Card>();
	}
	public void Add(Card card) {
		this.handCard.add(card);
		if(this.handCard.size() > 10) {
			System.out.println("你的卡牌超过10,请选择一张放入墓地");
			Scanner scanner = new Scanner(System.in);
			int number = scanner.nextInt();
			this.remove(number);
		}
	}
	public void remove(int number) {
		this.handCard.remove(number);
	}

手牌类,需要进行最大容量判断和移除操作。

总结

能力和时间都有限,有些知识还没学,先更新到这里,后面还有版本前瞻,可以先看看。

版本前瞻

加点功能

英雄

1、增加名称、头像

2、技能类增加特殊随从召唤

卡牌

1、给每个卡牌增加正反两面的图案(看时间)

2、初始时卡牌都在右侧的牌库,堆叠、背面朝上

3、卡牌使用后(或随从被击杀)依次放在左侧的队列,正面朝上

4、增加战场中的卡牌状态
休息:刚被召唤进战场或本次行动后
可用:玩家回合一开始时
其他状态自己增加

做个界面

就尽量往炉石的界面做,争取能进行基本游戏操作即可。

先去学一学异常处理机制、文件输入输出流、GUI和网络进行开发。

人机对战

每个回合,每个玩家可以执行的动作其实只有(回合开始自动)“抽牌”、“召唤”(选那些牌)、“攻击”(选谁攻击谁)和结束回合这么几种,当然因为召唤有消耗,具体会有不同的随从召唤策略,同时攻击也有攻击哪个随从或玩家的差异。可以设计多种的机器智能,使机器玩家也能进行游戏。