一种小游戏模型 嗯 类似RPG?

package com.example.com_skillu;
//package com.example.com_skillu;
import java.util.Vector;
import java.util.Random;
import java.util.Collections;
import android.widget.TextView;
public class GameJudge {
	Vector<Unit> UnitSet=new Vector<Unit>();
	Vector<Double> GroupBuff=new Vector<Double>();
	Vector<Leader> BattleGroup=new Vector<Leader>();
	Vector<Leader> LeaderSet=new Vector<Leader>();
	Vector<Integer> TargetList=new Vector<Integer>();
	TextView MessageBox;
	int MessageLoop=0;
	Random rand=new Random();
	int Judge_Loop=0;
	class Unit{
		String Name;
		int Damage[]=new int[5],Shield[]=new int[5],Life,Cost,Find;
		Unit(String _Name,int _Cost,int _Life,int _Find,int _Damage1,int _Damage2,int _Damage3,int _Damage4,
				int _Shield1,int _Shield2,int _Shield3,int _Shield4){
			Name=_Name;
			Damage[0]=_Damage1;
			Damage[1]=_Damage2;
			Damage[3]=_Damage3;
			Damage[4]=_Damage4;
			Shield[0]=_Shield1;
			Shield[1]=_Shield2;
			Shield[3]=_Shield3;
			Shield[4]=_Shield4;
			Life=_Life;
			Cost=_Cost;
			Find=_Find;
		}
	}
	class Attack{
		int Damage,LeaderIndex,Round,From;
		Attack(int _D,int _L,int _R,int _F){Damage=_D;LeaderIndex=_L;Round=_R;From=_R;}
	}
	class Item{
		String Name;
		int Life,Find,DamageUpper,ShieldUpper,Armor;
	}
	class Buff{
		double Value=1;
	}
	class Leader implements Comparable<Leader>{
		int Index,TypeIndex,Owner;
		String Name,Nation,SkillName,SkillInfo;
		int IQ,FQ,CommandValue=420,Life,Max_Life,Find;
		Vector<Integer> Units=new Vector<Integer>();
		Leader(String _Name,String _Nation,String _SkillName,String _SkillInfo,int _TypeIndex,int _FQ,int _IQ){
			Name=_Name;Nation=_Nation;SkillName=_SkillName;SkillInfo=_SkillInfo;FQ=_FQ;IQ=_IQ;
			CommandValue=420;
			Index=-1;
			TypeIndex=_TypeIndex;
			Owner=-1;
			Life=Max_Life=0;
			Find=0;
		}
		boolean Push_Unit(int Index){
			if(UnitSet.get(Index).Cost>CommandValue)return false;
		    CommandValue-=UnitSet.get(Index).Cost;
		    Units.add(Index);
			return true;
		}
		Attack OnAttack(int Round){
			double Buff_AttackUp=0;
		    int _Damage=0,i;
		    if(Round>3)Round%=4;
		    else if(TypeIndex==7)Buff_AttackUp+=1;
		    for(i=0;i!=Units.size();i++)_Damage+=UnitSet.get(Units.get(i)).Damage[Round];
			
		    if(TypeIndex==0)Buff_AttackUp+=0.1;
		    if(TypeIndex==3&&Max_Life-Life==0)Buff_AttackUp+=0.3;
		    if(TypeIndex==17)Life+=0.1*_Damage;
		    Enginee_Show(Name+"发起了攻击,造成"+(int)(_Damage*(1+Buff_AttackUp)*(GroupBuff.get(Owner)))+"伤害");
		    if(_Damage==0)Judge_Loop++;
		    return new Attack((int)(_Damage*(1+Buff_AttackUp)*(GroupBuff.get(Owner))),TypeIndex,Round%4,Index);
		}
		int OnDamage(Attack D){
			int Buff_AttackDown=0,i;
		    int _Shield=0;
		    D.Damage*=(1-Buff_AttackDown);
		    if(D.Round>3)D.Round%=4;
		    if(TypeIndex==15&&D.Round==0)return 0;
		    for(i=0;i!=Units.size();i++)_Shield+=UnitSet.get(Units.get(0)).Shield[D.Round];
		    if(TypeIndex==8)_Shield*=1.15;
		    else if(TypeIndex==16)_Shield*=0.3;
		    else if(D.LeaderIndex==6)_Shield=_Shield<300?0:(_Shield-300);
			else if(D.LeaderIndex==13){Life-=0.5*D.Damage;/*GameMessage(UNIT_ONDAMAGE,Name,"",D.Damage*0.5);D.Damage*=0.5;*/}
			else if(D.LeaderIndex==14)_Shield*=0.3;
		    D.Damage-=_Shield;
			//GameMessage(UNIT_ONDAMAGE,Name,"",D.Damage);
		    if(D.Damage>0){Enginee_Show(Name+"受到"+D.Damage+"伤害");Judge_Loop=0;}
		    else Judge_Loop++;
		    Life-=D.Damage;
			return D.Damage;
		}
		void Destroy(){
			/*GroupBuff Missed*/
		}
		void Create(){
			//GroupBuff Missed
			for(int i=0;i!=Units.size();i++){
				Life+=UnitSet.get(Units.get(i)).Life;
				Find+=UnitSet.get(Units.get(i)).Find;
				Life+=IQ/2;
				Find+=IQ/2;
			}
			if(TypeIndex==1)Find+=500;
			else if(TypeIndex==2)Life+=300;
			else if(TypeIndex==9)Find+=100000;
			else if(TypeIndex==12)Find*=2;
			Max_Life=Life;
		}
		@Override
		public int compareTo(Leader arg0) {
			// TODO Auto-generated method stub
			return arg0.Find-Find;
		}
		Leader(Leader o){
			Name=o.Name;
			Nation=o.Nation;
			SkillName=o.SkillName;
			SkillInfo=o.SkillInfo;
			FQ=o.FQ;
			IQ=o.IQ;
			CommandValue=o.CommandValue;
			Index=o.Index;
			TypeIndex=o.TypeIndex;
			Owner=o.Owner;
			Life=o.Life;
			Max_Life=o.Max_Life;
			Find=o.Find;
		}
	}
	void Code_Test(int Amount){
		for(int i=0;i!=Amount;i++){
			Leader AIBot=new Leader(LeaderSet.get(rand.nextInt(LeaderSet.size())));
			System.out.printf("%s\n",AIBot.Name);
			AIBot.Index=i;
			AIBot.Owner=i<Amount/2?2:1;
			AIBot.CommandValue=420;
			while(AIBot.Push_Unit(rand.nextInt(UnitSet.size())));
			GroupBuff.add(1.0);
			GroupBuff.add(1.0);
			GroupBuff.add(1.0);
			Enginee_Push(AIBot);
		}
	}
	static int i=0;
	static int select=-1;
	static int Round=0;
	int OnUnitAttack(int From,int To,int Round,int i,boolean Reverse){
		Enginee_Refresh();
		To=TargetList.get(To);
		int ActualDamage=BattleGroup.get(To).OnDamage(BattleGroup.get(From).OnAttack(Round));
	    if(BattleGroup.get(To).Life<0){
			if(Reverse==false)(i)-=(BattleGroup.get(From).TypeIndex==4?1:0)+(To<From?1:0);
			else i--;
	        Enginee_Show(To+"-"+BattleGroup.get(To).Name+"被击败,退出战场");
	        BattleGroup.get(To).Destroy();
	        BattleGroup.remove(To);
	    }
	    else if(ActualDamage>0&&BattleGroup.get(To).TypeIndex==11){
			return OnUnitAttack(To,From,Round,i,!Reverse);
	    }
	    if(i!=From)select=i-1;
	    return i;
	}
	void Enginee_Refresh(){
		TargetList.clear();
		for(int j=0;j!=BattleGroup.size();j++)if(BattleGroup.get(j).Owner!=BattleGroup.get(i).Owner)TargetList.add(j);
	}
	boolean Enginee_GameStart(int Target)
	{
		if(i==0&&select==-1)Collections.sort(BattleGroup);
		while(true){
			for(;i!=BattleGroup.size();i++){
				Enginee_Refresh();
				if(TargetList.isEmpty()){i=0;select=-1;return true;}
				if(BattleGroup.get(i).Owner==0){
					if(select==i){
						if(Target==-1)Target=rand.nextInt(TargetList.size());
						i=OnUnitAttack(i,Target,Round,i,false);
					}
					else{
						select=i;
						return false;
					}
				}
				else{
					Target=rand.nextInt(TargetList.size());
					i=OnUnitAttack(i,Target,Round,i,false);
				}
			}
			i=0;
			select=-1;
			Round++;
			if(Judge_Loop>20){Judge_Loop=0;i=0;select=-1;return true;}
		}
	}
	void Enginee_Push(Leader Now){
		BattleGroup.add(Now);
		BattleGroup.get(BattleGroup.size()-1).Create();
	}
	void Enginee_Initialize(){
		int iLoop=0;
		LeaderSet.add(new Leader("Name", "Nation", "SkillName", "SkillInfo",91,97,iLoop++));
		UnitSet.add(new Unit("ItemName",180,300,180,480,0,0,0,0,0,0,0));
	}
	void Enginee_Show(String Text){
		if(MessageLoop%20==0)MessageBox.setText("");
		MessageBox.setText(MessageBox.getText()+Text+"\n");
		MessageLoop++;
	}
	
	void Command(String CommandAnalyse){
		Enginee_Initialize();
		Code_Test(Integer.parseInt(CommandAnalyse));
		Enginee_GameStart(-1);
	}

	GameJudge(TextView _MessageBox){
		MessageBox=_MessageBox;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值