Beispiel #1
0
    //分别对应攻击和移动的函数
    protected virtual IEnumerator MoveToTar()
    {
        List <Part> route = new List <Part>();

        route      = Chess_manager.searchRoute(currentPart.GetComponent <Part>(), tarChess.GetComponent <Part>());
        audio.clip = music[0];
        audio.PlayOneShot(music[0]);
        for (int i = 0; i < route.Count; i++)
        {
            yield return(new WaitForSeconds(0.5f));

            transform.position = Vector3.Lerp(transform.position, route[i].getPosition(), 0.99f);
            currentPart        = route[i].transform;
            if (currentPart.GetComponent <Part>().life == 0)
            {
                currentPart.GetComponent <Part>().belong = true;
            }
            if (i == route.Count - 1)
            {
                animator.SetBool("ismove", false);
                currentPart.GetComponent <Part>().isControl = true;
            }
        }
        GameManager.instance.anbeavior = true;
        GameManager.instance.game_state.update_Townlist();
        now_movelim--;
    }
Beispiel #2
0
    protected override IEnumerator MoveToTar()
    {
        audio.clip = music[0];
        audio.PlayOneShot(music[0]);
        if (now_movelim > 0)
        {
            for (int i = 0; i <= now_movedis; i++)
            {
                yield return(new WaitForSeconds(0.5f));

                transform.position = Vector3.Lerp(transform.position, show_List[i].getPosition(), 0.99f);
                if (tarChess == show_List[i].GetComponent <Transform>())
                {
                    currentPart = show_List[i].transform;
                    if (currentPart.GetComponent <Part>().life == 0)
                    {
                        currentPart.GetComponent <Part>().belong = false;
                    }
                    currentPart.GetComponent <Part>().isControl = true;
                    animator.SetBool("ismove", false);
                    break;
                }
                currentPart = show_List[i].transform;
                if (currentPart.GetComponent <Part>().life == 0)
                {
                    currentPart.GetComponent <Part>().belong = false;
                }
            }
        }

        GameManager.instance.anbeavior = true;
        GameManager.instance.game_state.update_Townlist();
        if (near_player != null)
        {
            int tempdis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), near_player.GetComponent <ChessControl>().currentPart.GetComponent <Part>());
            now_movelim--;
            if (tempdis <= now_attck_dis && now_attacklim > 0)
            {
                Invoke("Chess_Attack", 0.6f);
            }
            else
            {
                isdone = true;
            }
        }
    }
Beispiel #3
0
 void attack_atTown()
 {
     getnearest_chess_and_dis();
     if (near_player != null)
     {
         int tempdis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), near_player.GetComponent <ChessControl>().currentPart.GetComponent <Part>());
         now_movelim--;
         if (tempdis <= now_attck_dis && now_attacklim > 0)
         {
             Invoke("Chess_Attack", 0.6f);
         }
         else
         {
             isdone = true;
         }
     }
 }
Beispiel #4
0
    protected virtual void Chess_Move()
    {
        //Debug.Log("选择移动点");
        if (init)
        {
            getnowPart();
            show_move_Dis(true, now_movedis, true);
            init = false;
        }

        animator.SetBool("ismove", true);
        if (Input.GetMouseButtonDown(1))
        {
            //show_move_Dis(false, now_movedis, true);
            Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit mouseHit;
            if (Physics.Raycast(mouseRay, out mouseHit))
            {
                if (mouseHit.transform.GetComponent <Part>() != null && !mouseHit.transform.GetComponent <Part>().isControl)
                {
                    tarChess = mouseHit.transform;

                    int dis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), tarChess.GetComponent <Part>());
                    if (dis <= now_movedis)
                    {
                        float temp = tarChess.position.x - currentPart.position.x;
                        if (temp > 0)
                        {
                            this.GetComponent <SpriteRenderer>().flipX = true;
                        }
                        else
                        {
                            this.GetComponent <SpriteRenderer>().flipX = false;
                        }
                        StartCoroutine(MoveToTar());
                        currentPart.GetComponent <Part>().isControl = false;//离开当前part
                    }
                }
                Chess_ideal();

                animator.SetBool("ismove", false);
            }
            show_move_Dis(false, now_movedis, true);
        }
    }
Beispiel #5
0
    public void update_Townlist()//更新所控制的城镇
    {
        enemy_town.Clear();
        play_town.Clear();
        List <Part> temp = null;

        temp = Chess_manager.PartTyeToList(PartType.CASTLE);
        for (int i = 0; i < temp.Count; i++)
        {
            if (!temp[i].belong)
            {
                enemy_town.Add(temp[i]);
            }
            else
            {
                play_town.Add(temp[i]);
            }
        }
    }
Beispiel #6
0
 //显示周围距离内的棋子
 protected void show_move_Dis(bool state, int ditance, bool isremove)
 {
     if (!state)
     {
         foreach (Part p in show_List)
         {
             //Debug.Log("ok");
             if (p != null)
             {
                 p.isShowArea = false;
             }
         }
         show_List.Clear();
     }
     else
     {
         if (currentPart != null)
         {
             //show_move_Dis(false,0, isremove);
             show_List.Clear();
             show_List = Chess_manager.getShowArea(currentPart.GetComponent <Part>(), ditance, isremove);
             //if(arm_type == Arm_type.Naval)
             //{
             //    foreach (Part p in show_List)
             //    {
             //        if (p.thistype == PartType.WATER)
             //        {
             //            show_List.Remove(p);
             //        }
             //    }
             //}
             foreach (Part p in show_List)
             {
                 if (p != null)
                 {
                     p.isShowArea = state;
                 }
             }
         }
     }
 }
Beispiel #7
0
 protected virtual void Chess_Attack()
 {
     if (init)
     {
         getnowPart();
         show_move_Dis(true, now_attck_dis, false);
         init = false;
     }
     if (Input.GetMouseButtonDown(1))
     {
         //show_move_Dis(false, now_attck_dis, false);
         Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit mouseHit;
         if (Physics.Raycast(mouseRay, out mouseHit))
         {
             if (mouseHit.transform.GetComponent <EnemyBehavior>() != null &&
                 mouseHit.transform.CompareTag("Enemy"))
             {
                 //Debug.Log(mouseHit.transform);
                 tarChess = mouseHit.transform;
                 int dis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), tarChess.GetComponent <EnemyBehavior>().currentPart.GetComponent <Part>());
                 if (dis <= now_attck_dis)
                 {
                     float temp = tarChess.position.x - currentPart.position.x;
                     if (temp > 0)
                     {
                         this.GetComponent <SpriteRenderer>().flipX = true;
                     }
                     else
                     {
                         this.GetComponent <SpriteRenderer>().flipX = false;
                     }
                     StartCoroutine(AttackTar());
                 }
             }
         }
         show_move_Dis(false, now_attck_dis, false);
         Chess_ideal();
     }
 }
Beispiel #8
0
    void chooseTarget()
    {
        List <Part> List_Town = new List <Part>();
        Part        min       = null;
        float       mindis    = 99999;

        if (GameManager.instance.getEnemyNum() < GameManager.instance.getPlayerNum())
        {
            List_Town = GameManager.instance.game_state.enemy_town;
        }
        else
        {
            List_Town = GameManager.instance.game_state.play_town;
        }
        foreach (Part p in List_Town)
        {
            if (p == null)
            {
                continue;
            }
            int dis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), p);
            if (mindis > dis)
            {
                mindis = dis;
                min    = p;
            }
        }
        if (min != null)
        {
            show_List = Chess_manager.searchRoute(currentPart.GetComponent <Part>(), min);
            near_city = min.transform;
            if (show_List.Count > 2)
            {
                if (!show_List[now_movedis].isControl && show_List[now_movedis].thistype != PartType.WATER)
                {
                    tarChess = show_List[now_movedis].GetComponent <Transform>();
                }
                else
                {
                    show_List = Chess_manager.getShowArea(currentPart.GetComponent <Part>(), now_movedis, true);
                    //Debug.Log(show_List.Count);
                    int standdis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), min);
                    for (int i = 0; i < show_List.Count; i++)
                    {
                        int dis = Chess_manager.GetRouteDis(show_List[i], min);
                        if ((show_List[i] != null && show_List[i].thistype == PartType.WATER && arm_type == Arm_type.ARMY) || (dis > standdis))
                        {
                            show_List.Remove(show_List[i]);
                        }
                    }
                    int index1 = (int)(Random.Range(0, 1) * (show_List.Count - 1));
                    if (show_List[index1].isControl || (show_List[index1].thistype == PartType.WATER && this.arm_type == Arm_type.ARMY))
                    {
                        tarChess = currentPart;
                    }
                    else
                    {
                        tarChess = show_List[index1].GetComponent <Transform>();
                    }
                }
            }
            else
            {
                tarChess = currentPart;
            }
        }
        show_List = Chess_manager.searchRoute(currentPart.GetComponent <Part>(), tarChess.GetComponent <Part>());
    }
Beispiel #9
0
    void getnearest_chess_and_dis()
    {
        show_List.Clear();
        List <ChessControl> player_arm = new List <ChessControl>();

        player_arm = GameManager.player_arm;
        ChessControl min    = null;
        float        mindis = 99999;

        getnowPart();
        foreach (ChessControl p in player_arm)
        {
            if (p == null)
            {
                continue;
            }
            int dis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), p.currentPart.GetComponent <Part>());
            if (mindis > dis)
            {
                mindis = dis;
                min    = p;
            }
        }
        if (min != null)
        {
            show_List   = Chess_manager.searchRoute(currentPart.GetComponent <Part>(), min.currentPart.GetComponent <Part>());
            near_player = min.transform;
            if (show_List.Count > 2)
            {
                if (!show_List[now_movedis].isControl)
                {
                    tarChess = show_List[now_movedis].GetComponent <Transform>();
                }
                else
                {
                    show_List = Chess_manager.getShowArea(currentPart.GetComponent <Part>(), now_movedis, true);
                    //Debug.Log(show_List.Count);
                    int standdis = Chess_manager.GetRouteDis(currentPart.GetComponent <Part>(), min.currentPart.GetComponent <Part>());
                    for (int i = 0; i < show_List.Count; i++)
                    {
                        int dis = Chess_manager.GetRouteDis(show_List[i], min.currentPart.GetComponent <Part>());
                        if ((show_List[i] != null && show_List[i].thistype == PartType.WATER && arm_type == Arm_type.ARMY) || (dis > standdis))
                        {
                            show_List.Remove(show_List[i]);
                        }
                    }
                    int index1 = (int)(Random.Range(0, 1) * (show_List.Count - 1));
                    if (show_List[index1].isControl || (show_List[index1].thistype == PartType.WATER && this.arm_type == Arm_type.ARMY))
                    {
                        tarChess = currentPart;
                    }
                    else
                    {
                        tarChess = show_List[index1].GetComponent <Transform>();
                    }
                }
            }
            else
            {
                tarChess = currentPart;
            }
        }
        show_List = Chess_manager.searchRoute(currentPart.GetComponent <Part>(), tarChess.GetComponent <Part>());
    }