Exemple #1
0
 // Start is called before the first frame update
 void Start()
 {
     playerHealth.text = "Health: 100";
     foe       = enemy.GetComponent <EnemyBehaviour>();
     character = player.GetComponent <PlayerBehaviour>();
     buffed    = character;
     debuffed  = foe;
 }
Exemple #2
0
    public void OnClickEnter()
    {
        switch (gameObject.tag)
        {
        case "BuffA":
            buffed          = new BuffAttack(buffed);
            damageText.text = "Took " + (debuffed.GetDamage() - buffed.GetDefense()) + " damage";
            break;

        case "BuffD":
            buffed          = new BuffDefense(buffed);
            damageText.text = "Took " + (debuffed.GetDamage() - buffed.GetDefense()) + " damage";
            break;

        case "DebuffA":
            debuffed        = new DebuffAttack(debuffed);
            damageText.text = "Took " + (debuffed.GetDamage() - buffed.GetDefense()) + " damage";
            break;

        case "DebuffD":
            debuffed        = new DebuffDefense(debuffed);
            damageText.text = "Took " + (debuffed.GetDamage() - buffed.GetDefense()) + " damage";
            break;

        default:
            foe.health -= (buffed.GetDamage() + debuffed.GetDefense());
            character.anim.SetBool("isAttacking", true);
            damageText.text = "Took " + (debuffed.GetDamage() - buffed.GetDefense()) + " damage\n" +
                              "Dealt " + (buffed.GetDamage() + debuffed.GetDefense()) + " damage";
            break;
        }
        character.health -= (debuffed.GetDamage() - buffed.GetDefense());
        playerHealth.text = "Health: " + character.health;
        foe.anim.SetBool("isAttacking", true);
        Invoke("ResetAnim", 0.5f);
        Debug.Log("Char stats " + character.health + " " + buffed.GetDefense() + " " + buffed.GetDamage() + "\nEnemy stats " + foe.health + " " +
                  debuffed.GetDamage() + " " + debuffed.GetDefense());
    }
Exemple #3
0
 public DebuffAttack(AttackAndDefend enemy)
 {
     this.enemy = enemy;
 }
Exemple #4
0
 public BuffDefense(AttackAndDefend player)
 {
     this.player = player;
 }
Exemple #5
0
    private List <AttackAndDefend> VCF_RenewVCFLocation(int Color)
    {
        int[] DeltaX        = { 0, 1, 1, 1 };
        int[] DeltaY        = { 1, -1, 0, 1 };
        int   OpponentColor = 3 - Color;
        List <AttackAndDefend> ValidPoints = new List <AttackAndDefend>();
        Point mc = VCF_Order[VCF_Order.Count - 2]; //我的最后一个棋子  mc=my chessman
        Point oc = VCF_Order[VCF_Order.Count - 1]; //对手的最后一个棋子  oc=opponent chessman
        //先判断对方是否有冲四
        Point dp = VCF_IfFour(oc, OpponentColor);

        if (dp.X < width)//如果对方有冲四
        {
            ValidPoints.Add(new AttackAndDefend(dp));
            VCF_DynamicValidPoints = new List <AttackAndDefend>(ValidPoints);
            return(ValidPoints);
        }
        else if (dp.X == width + 2)//如果对方形成活四
        {
            return(ValidPoints);
        }
        //把aad中所有含有mc与oc的项删掉
        for (int i = 0; i < VCF_DynamicValidPoints.Count; i++)
        {
            AttackAndDefend aad = VCF_DynamicValidPoints[i];
            if (aad.Attack.Equals(mc) || aad.Defend.Equals(mc) || aad.Attack.Equals(oc) || aad.Defend.Equals(oc))
            {
                VCF_DynamicValidPoints.RemoveAt(i);
                i--;
            }
        }
        //将四个方向4格内的 空格 存储到ValidRange内
        List <Point> ValidRange = new List <Point>();

        for (int d = 0; d <= 3; d++)
        {
            //正方向
            for (int i = 1; i <= 4; i++)
            {
                int mx = DeltaX[d] * i + mc.X, my = DeltaY[d] * i + mc.Y;
                if (mx >= width || my < 0 || my >= height)
                {
                    break;
                }
                if (Chessboard[mx, my] != 0)
                {
                    continue;
                }
                Point p = new Point(mx, my);
                if (!ValidRange.Contains(p))
                {
                    ValidRange.Add(new Point(mx, my));
                }
            }
            for (int i = 1; i <= 4; i++)
            {
                int ox = DeltaX[d] * i + oc.X, oy = DeltaY[d] * i + oc.Y;
                if (ox >= width || oy < 0 || oy >= height)
                {
                    break;
                }
                if (Chessboard[ox, oy] != 0)
                {
                    continue;
                }
                Point p = new Point(ox, oy);
                if (!ValidRange.Contains(p))
                {
                    ValidRange.Add(new Point(ox, oy));
                }
            }
            //负方向
            for (int i = -1; i >= -4; i--)
            {
                int mx = DeltaX[d] * i + mc.X, my = DeltaY[d] * i + mc.Y;
                if (mx < 0 || my < 0 || my >= height)
                {
                    break;
                }
                if (Chessboard[mx, my] != 0)
                {
                    continue;
                }
                Point p = new Point(mx, my);
                if (!ValidRange.Contains(p))
                {
                    ValidRange.Add(new Point(mx, my));
                }
            }
            for (int i = -1; i >= -4; i--)
            {
                int ox = DeltaX[d] * i + oc.X, oy = DeltaY[d] * i + oc.Y;
                if (ox < 0 || oy < 0 || oy >= height)
                {
                    break;
                }
                if (Chessboard[ox, oy] != 0)
                {
                    continue;
                }
                Point p = new Point(ox, oy);
                if (!ValidRange.Contains(p))
                {
                    ValidRange.Add(new Point(ox, oy));
                }
            }
        }
        //将ValidRange内的ValidPoint删掉
        foreach (Point p in ValidRange)
        {
            for (int i = 0; i < VCF_DynamicValidPoints.Count; i++)
            {
                AttackAndDefend aad = VCF_DynamicValidPoints[i];
                if (aad.Attack.Equals(p))
                {
                    VCF_DynamicValidPoints.RemoveAt(i);
                    break;
                }
            }
        }
        //在ValidRange内判断是否是冲四点
        foreach (Point p in ValidRange)
        {
            Chessboard[p.X, p.Y] = Color;
            Point p2 = VCF_IfLevelAboveFour(p, Color);
            if (p2.X < width)
            {
                //insert的效果会比add好,add会导致频繁转移战场
                VCF_DynamicValidPoints.Insert(0, new AttackAndDefend(p, p2));
            }
            //p2.X == width + 2这句语句理论上在VCF迭代中永远不会被执行到,这里以防万一
            else if (p2.X == width + 2)
            {
                return new List <AttackAndDefend> {
                           new AttackAndDefend(p)
                }
            }
            ;
            Chessboard[p.X, p.Y] = 0;
        }
        //按照棋子价值降序排列
        //VCF_DynamicValidPoints.Sort((a, b) => -VCF_EvaluateSingleChessman(a.Attack, Color).CompareTo(VCF_EvaluateSingleChessman(b.Attack, Color)));
        return(new List <AttackAndDefend>(VCF_DynamicValidPoints));
    }
Exemple #6
0
    private List <AttackAndDefend> VCF_GenerateVCFLocation(int Color)//使用Chessboard
    {
        int[] DeltaX        = { 0, 1, 1, 1 };
        int[] DeltaY        = { 1, -1, 0, 1 };
        int   OpponentColor = 3 - Color;
        List <AttackAndDefend> VCFValidPoints = new List <AttackAndDefend>();

        //先判断对手是否有冲四
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                if (Chessboard[i, j] == Color)
                {
                    continue;
                }
                for (int k = 0; k <= 3; k++)//k表示方向
                {
                    int   ChessmanCount = 5;
                    Point KeyPoint      = new Point(-1, -1);
                    Point BugPoint      = new Point(-1, -1);//如果对方活四,直接return,不返回任何坐标
                    if (i + 2 * DeltaX[k] < 0 || i + 2 * DeltaX[k] >= width || j + 2 * DeltaY[k] >= height || j + 2 * DeltaY[k] < 0 ||
                        i - 2 * DeltaX[k] < 0 || i - 2 * DeltaX[k] >= width || j - 2 * DeltaY[k] >= height || j - 2 * DeltaY[k] < 0)
                    {
                        continue;
                    }
                    for (int m = -2; m <= 2; m++)
                    {
                        int x = i + m * DeltaX[k], y = j + m * DeltaY[k];
                        if (Chessboard[x, y] == Color)
                        {
                            ChessmanCount = 0; break;
                        }
                        ;
                        if (Chessboard[x, y] == 0)
                        {
                            ChessmanCount -= 1;
                            if (ChessmanCount < 4)
                            {
                                break;
                            }
                            KeyPoint = new Point(x, y);
                            if (m == -2)
                            {
                                int bx = i + 3 * DeltaX[k], by = j + 3 * DeltaY[k];
                                if (bx < width && bx >= 0 && by < height && by >= 0)
                                {
                                    BugPoint = new Point(bx, by);
                                }
                            }
                            else if (m == 2)
                            {
                                int bx = i - 3 * DeltaX[k], by = j - 3 * DeltaY[k];
                                if (bx < width && bx >= 0 && by < height && by >= 0)
                                {
                                    BugPoint = new Point(bx, by);
                                }
                            }
                        }
                    }
                    if (ChessmanCount == 4)
                    {
                        if (BugPoint.X != -1)
                        {
                            if (Chessboard[BugPoint.X, BugPoint.Y] == 0)
                            {
                                return(new List <AttackAndDefend>());
                            }
                        }
                        VCFValidPoints.Add(new AttackAndDefend(KeyPoint));
                        return(VCFValidPoints);
                    }
                }
            }
        }

        //若没有对手的,则生成自己的
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                if (Chessboard[i, j] == OpponentColor)
                {
                    continue;
                }
                for (int k = 0; k <= 3; k++)//k表示方向
                {
                    int   ChessmanCount = 5;
                    Point KeyPoint1     = new Point(-1, -1);
                    Point KeyPoint2     = new Point(-1, -1);
                    if (i + 2 * DeltaX[k] < 0 || i + 2 * DeltaX[k] >= width || j + 2 * DeltaY[k] >= height || j + 2 * DeltaY[k] < 0 ||
                        i - 2 * DeltaX[k] < 0 || i - 2 * DeltaX[k] >= width || j - 2 * DeltaY[k] >= height || j - 2 * DeltaY[k] < 0)
                    {
                        continue;
                    }
                    //正负方向+2-2
                    for (int m = -2; m <= 2; m++)
                    {
                        int x = i + m * DeltaX[k], y = j + m * DeltaY[k];
                        if (Chessboard[x, y] == OpponentColor)
                        {
                            ChessmanCount = 0; break;
                        }
                        ;
                        if (Chessboard[x, y] == 0)
                        {
                            ChessmanCount -= 1;
                            if (ChessmanCount < 3)
                            {
                                break;
                            }
                            if (KeyPoint1.X == -1)
                            {
                                KeyPoint1 = new Point(x, y);
                            }
                            else
                            {
                                KeyPoint2 = new Point(x, y);
                            }
                        }
                    }
                    if (ChessmanCount >= 3)//如果为4,则表示成五已胜
                    {
                        AttackAndDefend aad1 = new AttackAndDefend(KeyPoint1, KeyPoint2);
                        AttackAndDefend aad2 = new AttackAndDefend(KeyPoint2, KeyPoint1);
                        if (!VCFValidPoints.Contains(aad1))
                        {
                            VCFValidPoints.Add(aad1);
                        }
                        if (!VCFValidPoints.Contains(aad2))
                        {
                            VCFValidPoints.Add(aad2);
                        }
                    }
                }
            }
        }
        //VCFValidPoints.Sort((a, b) => -VCF_EvaluateSingleChessman(a.Attack, Color).CompareTo(VCF_EvaluateSingleChessman(b.Attack, Color)));
        return(VCFValidPoints);
    }