[音之国度进度]团队探索系统

        项目音之国度进入了尾声,需要临时加上一个团队探索系统。

        本身的逻辑控制并不复杂,比较麻烦的是这个系统并不是我写的,在合并代码的时候可能会造成很大麻烦。

        所以为了让之后的人比较容易的合成代码,大多数的概念首先进行接口的抽象。

       代码如下:

using UnityEngine;
using System.Collections;
using explorerModeConig;

namespace explorerModeConig
{
	public interface player
	{
		bool isLife ();
		void myturn ();
		void getboss (boss _b);
		void addyourPoint (int _x);
		int getyourPoint (); 
		bool isAttackEnd();
	}

	public interface boss
	{
		void bossturn();
		bool isAttackEnd ();
		bool isAttack();
		void behurt(player _p);
		bool isLife();
		void getgamer (player[] _ps);
	}

	public interface computeResult
	{
		void End_count (bool _isWin,player[] _ps,int[] _ls);
	}
}



public class explorerMode : MonoBehaviour {

	// Use this for initialization
	public player[] _p;
	public boss _b;
	public computeResult _cr;
	public float TimeOneturn;
	private float timer;
	private int temp_turn=0;
	bool game_start;
	bool game_end;
	bool isWin=false;
	void Start () 
	{
		game_start = false;
		game_end = false;
		isWin = false;
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(!game_start)
		{
			bool gamer=true;
			for(int i=0;i<_p.Length;i++)
			{
				if(!_p[i].isLife())
				{
					gamer = false;
					break;
				}
			}
			if(gamer)
			{
				game_start = true;
				for(int i=0;i<_p.Length;i++)
				{
					_p [i].getboss (_b);
				}
				_b.getgamer (_p);
			}
		}
		if (game_end) 
		{
			int[] points=new int[_p.Length];
			for(int i=0;i<_p.Length;i++)
			{
				points [i] = _p [i].getyourPoint ();
			}
			_cr.End_count (isWin,_p,points);
			Destroy (this);
		}
		if(game_start&&!game_end)
		{
			bool isEnd = true;
			for(int i=0;i<_p.Length;i++)
			{
				if(_p[i].isLife())
				{
					isEnd = false;
					break;
				}
			}
			if(!isEnd)
			{
				if(!_b.isLife())
				{
					isEnd = true;
					isWin = true;
				}
			}
			if(isEnd)
			{
				game_end = true;
				goto allend;
			}
			if (timer < TimeOneturn)
			{
				timer += Time.deltaTime;
			}
			else
			{
				timer = 0.0f;
				temp_turn++;
				temp_turn = temp_turn % (_p.Length+1);
			}
			if (temp_turn < _p.Length)
			{
				if (!_p [temp_turn].isAttackEnd ()&&_p[temp_turn].isLife()) 
				{
					_p [temp_turn].myturn ();
				} 
				else
				{
					timer = 0.0f;
					temp_turn++;
					temp_turn = temp_turn % (_p.Length + 1);
				}
			} 
			else
			{
				if (!_b.isAttackEnd ()&&!_b.isLife()) 
				{
					_b.bossturn ();
				}
				else
				{
					timer = 0.0f;
					temp_turn++;
					temp_turn = temp_turn % (_p.Length + 1);
				}
			}
		}
		allend:
		Debug.Log ("end");
	}
}
比如boss、player、以及结算方式,这里并不知道原先的人是怎么写的,所以我们可以先将其抽象出来,定义好我们需要的方法接口,先用抽象的东西写好流程控制,具体实现的时候,合代码的人只需要让原先已经实现过的这些类实现一下我的接口,并在初始化的时候将实际的实现类对象传进来,就可以比较容易合成几个不同的人写的代码。


逻辑方面很普通,就是一个正常的回合制游戏的流程控制。

猜你喜欢

转载自blog.csdn.net/qq_33999892/article/details/73385535
今日推荐