Пример #1
0
 public override void walk(int x, int y)  //计算棋子移动范围
 {
     if (tire == 0)
     {
         Plate.walk(x, y, 4, 4, x, y);
     }
 }
Пример #2
0
        public override void walk(int x, int y)  //计算棋子移动范围
        {
            int i;

            for (i = 1; i <= 6 && Plate.inside(x + i, y) && Plate.plate[x + i][y] == null; ++i)
            {
                Plate.plateCol[x + i][y] = Color.gray;
            }
            Plate.canStrike(player, x + i, y, 0, 0, x, y);
            for (i = 1; i <= 6 && Plate.inside(x - i, y) && Plate.plate[x - i][y] == null; ++i)
            {
                Plate.plateCol[x - i][y] = Color.gray;
            }
            Plate.canStrike(player, x - i, y, 0, 0, x, y);
            for (i = 1; i <= 6 && Plate.inside(x, y + i) && Plate.plate[x][y + i] == null; ++i)
            {
                Plate.plateCol[x][y + i] = Color.gray;
            }
            Plate.canStrike(player, x, y + i, 0, 0, x, y);
            for (i = 1; i <= 6 && Plate.inside(x, y - i) && Plate.plate[x][y - i] == null; ++i)
            {
                Plate.plateCol[x][y - i] = Color.gray;
            }
            Plate.canStrike(player, x, y - i, 0, 0, x, y);
        }
Пример #3
0
 public override void turnTurn(int srcx, int srcy)
 {
     if (wait == 1)
     {
         wait = 2;
     }
     else if (wait == 2)
     {
         int atkx = srcx, atky = srcy;
         for (int i = 1; i <= arrowLength; ++i)
         {
             atkx += Math.Sign(waitx - srcx);
             atky += Math.Sign(waity - srcy);
             if (Plate.plate[atkx][atky] != null)
             {
                 if (Plate.canStrike(player, atkx, atky, 0, 0, srcx, srcy, true))
                 {
                     Plate.plate[atkx][atky] = null;
                 }
                 break;
             }
         }
         wait = 0;
     }
 }
Пример #4
0
 public override void walk(int x, int y)  //计算棋子移动范围
 {
     for (int i = x - 2; i <= x + 2; ++i)
     {
         for (int j = y - 2; j <= y + 2; ++j)
         {
             Plate.canStrike(player, i, j, 2, 2, x, y);
         }
     }
 }
Пример #5
0
 public override void calSkill(int selx, int sely)
 {
     for (int i = 1; i <= arrowLength; ++i)
     {
         Plate.canStrike(player, selx + i, sely, 0, 0, selx, sely, true);
         Plate.canStrike(player, selx - i, sely, 0, 0, selx, sely, true);
         Plate.canStrike(player, selx, sely + i, 0, 0, selx, sely, true);
         Plate.canStrike(player, selx, sely - i, 0, 0, selx, sely, true);
     }
 }
Пример #6
0
 public override void calSkill(int selx, int sely)
 {
     Plate.canStrike(PlayerControl.player, selx + 1, sely, 2, 2, selx, sely);
     Plate.canStrike(PlayerControl.player, selx - 1, sely, 2, 2, selx, sely);
     Plate.canStrike(PlayerControl.player, selx, sely + 1, 2, 2, selx, sely);
     Plate.canStrike(PlayerControl.player, selx, sely - 1, 2, 2, selx, sely);
     Plate.canStrike(PlayerControl.player, selx + 2, sely, 2, 2, selx, sely);
     Plate.canStrike(PlayerControl.player, selx - 2, sely, 2, 2, selx, sely);
     Plate.canStrike(PlayerControl.player, selx, sely + 2, 2, 2, selx, sely);
     Plate.canStrike(PlayerControl.player, selx, sely - 2, 2, 2, selx, sely);
 }
Пример #7
0
        public override void calSkill(int selx, int sely)
        {
            int x = selx, y = sely;

            for (int i = 1; i <= 15; ++i)
            {
                x += (PlayerControl.curx - selx);
                y += (PlayerControl.cury - sely);
                if (!Plate.inside(x, y))
                {
                    return;
                }
                Plate.plateCol[x][y] = Color.gray;
            }
        }
Пример #8
0
 public override void walk(int x, int y)  //计算棋子移动范围
 //a true b true b; a true b false ab; a false a;
 {
     if (!Plate.walkable(x - 1, y) || !Plate.canStrike(PlayerControl.player, x - 2, y, 2, 2, x, y))
     {
         Plate.canStrike(PlayerControl.player, x - 1, y, 2, 2, x, y);
     }
     if (!Plate.walkable(x + 1, y) || !Plate.canStrike(PlayerControl.player, x + 2, y, 2, 2, x, y))
     {
         Plate.canStrike(PlayerControl.player, x + 1, y, 2, 2, x, y);
     }
     if (!Plate.walkable(x, y - 1) || !Plate.canStrike(PlayerControl.player, x, y - 2, 2, 2, x, y))
     {
         Plate.canStrike(PlayerControl.player, x, y - 1, 2, 2, x, y);
     }
     if (!Plate.walkable(x, y + 1) || !Plate.canStrike(PlayerControl.player, x, y + 2, 2, 2, x, y))
     {
         Plate.canStrike(PlayerControl.player, x, y + 1, 2, 2, x, y);
     }
 }
Пример #9
0
 public override void calSkill(int selx, int sely)
 {
     for (int i = 1; i <= arrowLength; ++i)
     {
         if (Plate.inside(selx + i, sely))
         {
             Plate.plateCol[selx + i][sely] = Color.gray;
         }
         if (Plate.inside(selx + i, sely + i))
         {
             Plate.plateCol[selx + i][sely + i] = Color.gray;
         }
         if (Plate.inside(selx, sely + i))
         {
             Plate.plateCol[selx][sely + i] = Color.gray;
         }
         if (Plate.inside(selx - i, sely + i))
         {
             Plate.plateCol[selx - i][sely + i] = Color.gray;
         }
         if (Plate.inside(selx - i, sely))
         {
             Plate.plateCol[selx - i][sely] = Color.gray;
         }
         if (Plate.inside(selx - i, sely - i))
         {
             Plate.plateCol[selx - i][sely - i] = Color.gray;
         }
         if (Plate.inside(selx, sely - i))
         {
             Plate.plateCol[selx][sely - i] = Color.gray;
         }
         if (Plate.inside(selx + i, sely - i))
         {
             Plate.plateCol[selx + i][sely - i] = Color.gray;
         }
     }
 }
Пример #10
0
        public override void turnTurn(int srcx, int srcy)
        {
            if (wait == 1)
            {
                wait = 2;
            }
            else if (wait == 2)
            {
                if (selectedSkill == "I")
                {
                    if (Plate.plate[waitx][waity] == null)
                    {
                        Plate.plate[waitx][waity] = new ArrowSnipeToken(waitx, waity, player);
                    }
                }
                if (Plate.canStrike(player, waitx, waity, 0, 0, srcx, srcy, true))
                {
                    Plate.plate[waitx][waity] = null;
                    wait = 0;
                }
                if (selectedSkill == "U")
                {
                    //箭雨和狙击技能共用一个变量。
                    //狙击技能只能放在空地,但是会放置一个token以阻止对方的前行。TODO:这个token有特殊之处,比如可以狙杀龙。
                    //箭雨技能则多两个格子。

                    int diffx = Math.Abs(waitx - srcx);
                    int diffy = Math.Abs(waity - srcy);
                    if (diffx > diffy)
                    {
                        if (Plate.canStrike(player, waitx, waity - 1, 0, 0, srcx, srcy, true))
                        {
                            Plate.plate[waitx][waity - 1] = null;
                        }
                        if (Plate.canStrike(player, waitx, waity + 1, 0, 0, srcx, srcy, true))
                        {
                            Plate.plate[waitx][waity + 1] = null;
                        }
                    }
                    else if (diffx < diffy)
                    {
                        if (Plate.canStrike(player, waitx - 1, waity, 0, 0, srcx, srcy, true))
                        {
                            Plate.plate[waitx - 1][waity] = null;
                        }
                        if (Plate.canStrike(player, waitx + 1, waity, 0, 0, srcx, srcy, true))
                        {
                            Plate.plate[waitx + 1][waity] = null;
                        }
                    }
                    else
                    {
                        if (Plate.canStrike(player, waitx, waity - Math.Sign(waity - srcy), 0, 0, srcx, srcy, true))
                        {
                            Plate.plate[waitx][waity - Math.Sign(waity - srcy)] = null;
                        }
                        if (Plate.canStrike(player, waitx - Math.Sign(waitx - srcx), waity, 0, 0, srcx, srcy, true))
                        {
                            Plate.plate[waitx - Math.Sign(waitx - srcx)][waity] = null;
                        }
                    }
                    wait = 0;
                }
            }
        }
Пример #11
0
        }                                       //是否为机械

        public virtual void walk(int x, int y)  //计算棋子移动范围
        {
            Plate.walk(x, y, 2, 2, x, y);
        }
Пример #12
0
 public override void walk(int x, int y)  //计算棋子移动范围
 {
     Plate.walk(x, y, 1, 1, x, y);
 }
Пример #13
0
        // Detect Mouse Inputs
        void GetMouseInputs()
        {
            Ray        _ray;
            RaycastHit _hitInfo;

            // Select a piece if the gameState is 0 or 1
            if (mode == 0)
            {
                // On Left Click
                if (Input.GetMouseButtonDown(0))
                {
                    _ray = PlayerCam.ScreenPointToRay(Input.mousePosition); // Specify the ray to be casted from the position of the mouse click

                    Debug.Log("click");
                    // Raycast and verify that it collided
                    if (Physics.Raycast(_ray, out _hitInfo))
                    {
                        Debug.Log("hit0");
                        // Select the piece if it has the good Tag
                        if (_hitInfo.collider.gameObject.tag == ("Cube"))
                        {
                            GameObject boardSquare = _hitInfo.collider.gameObject;
                            Debug.Log("hit" + player);
                            curx = boardSquare.GetComponent <BoardSquare>().posx;
                            cury = boardSquare.GetComponent <BoardSquare>().posy;
                            if (Plate.selectPiece())
                            {
                                Debug.Log("sel");

                                _GameManager.SelectPiece(boardSquare.GetComponent <BoardSquare>().piece);
                                mode    = 1;
                                isPush  = false;
                                issteal = false;
                                Plate.colRefresh();
                                Plate.calMove(curx, cury);
                                Debug.Log("123");
                                Plate.print();
                            }
                        }
                    }
                }
            }

            // Move the piece if the gameState is 1
            else if (mode == 1)
            {
                Vector3 selectedCoord;

                // On Left Click
                if (Input.GetMouseButtonDown(0))
                {
                    Plate.print();
                    _ray = PlayerCam.ScreenPointToRay(Input.mousePosition); // Specify the ray to be casted from the position of the mouse click

                    // Raycast and verify that it collided
                    if (Physics.Raycast(_ray, out _hitInfo))
                    {
                        // Select the piece if it has the good Tag
                        if (_hitInfo.collider.gameObject.tag == ("Cube"))
                        {
                            GameObject gameObject = _hitInfo.collider.gameObject;
                            selectedCoord = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + 1, gameObject.transform.position.z);
                            curx          = gameObject.GetComponent <BoardSquare>().posx;
                            cury          = gameObject.GetComponent <BoardSquare>().posy;

                            Plate.colRefresh();
                            Plate.calMove(Plate.selx, Plate.sely);
                            if (Plate.plate[Plate.selx][Plate.sely] != null && !Plate.plate[Plate.selx][Plate.sely].ismechanics())
                            {
                                if (Plate.selx > 0 && Plate.plate[Plate.selx - 1][Plate.sely] != null && Plate.plate[Plate.selx - 1][Plate.sely].ismechanics() && Plate.plate[Plate.selx - 1][Plate.sely].player == player ||
                                    Plate.sely > 0 && Plate.plate[Plate.selx][Plate.sely - 1] != null && Plate.plate[Plate.selx][Plate.sely - 1].ismechanics() && Plate.plate[Plate.selx][Plate.sely - 1].player == player ||
                                    Plate.selx < 14 && Plate.plate[Plate.selx + 1][Plate.sely] != null && Plate.plate[Plate.selx + 1][Plate.sely].ismechanics() && Plate.plate[Plate.selx + 1][Plate.sely].player == player ||
                                    Plate.sely < 14 && Plate.plate[Plate.selx][Plate.sely + 1] != null && Plate.plate[Plate.selx][Plate.sely + 1].ismechanics() && Plate.plate[Plate.selx][Plate.sely + 1].player == player)
                                {
                                    if (isPush)
                                    {
                                        Debug.Log(" O 关闭挟持");
                                    }
                                    else
                                    {
                                        Debug.Log(" O 开启挟持");
                                    }
                                }
                            }
                            issteal = false;
                            if (Plate.plate[Plate.selx][Plate.sely] != null && !Plate.plate[Plate.selx][Plate.sely].ismechanics())
                            {
                                if (Plate.selx > 0 && Plate.plate[Plate.selx - 1][Plate.sely] != null && Plate.plate[Plate.selx - 1][Plate.sely].ismechanics() && Plate.plate[Plate.selx - 1][Plate.sely].player != player ||
                                    Plate.sely > 0 && Plate.plate[Plate.selx][Plate.sely - 1] != null && Plate.plate[Plate.selx][Plate.sely - 1].ismechanics() && Plate.plate[Plate.selx][Plate.sely - 1].player != player ||
                                    Plate.selx < 14 && Plate.plate[Plate.selx + 1][Plate.sely] != null && Plate.plate[Plate.selx + 1][Plate.sely].ismechanics() && Plate.plate[Plate.selx + 1][Plate.sely].player != player ||
                                    Plate.sely < 14 && Plate.plate[Plate.selx][Plate.sely + 1] != null && Plate.plate[Plate.selx][Plate.sely + 1].ismechanics() && Plate.plate[Plate.selx][Plate.sely + 1].player != player)
                                {
                                    issteal = true;
                                    for (int i = Mathf.Max(0, Plate.selx - 2); i <= Mathf.Min(14, Plate.selx + 2); ++i)
                                    {
                                        for (int j = Mathf.Max(0, Plate.sely - 2 + Mathf.Abs(Plate.selx - i)); j <= Mathf.Min(14, Plate.sely + 2 - Mathf.Abs(Plate.selx - i)); ++j)
                                        {
                                            if (Plate.plate[i][j] != null && Plate.plate[i][j].player == 1 - player && !Plate.plate[i][j].ismechanics())
                                            {
                                                issteal = false;
                                            }
                                        }
                                    }
                                }
                                if (issteal)
                                {
                                    Debug.Log(" P 偷盗");
                                }
                            }


                            if (answer == "O")
                            {
                                isPush = !isPush;
                                if (isPush)
                                {
                                    for (int i = 0; i < 15; ++i)
                                    {
                                        for (int j = 0; j < 15; ++j)
                                        {
                                            if ((i != Plate.selx - 2 && i != Plate.selx - 1 && i != Plate.selx + 1 && i != Plate.selx + 2 || j != Plate.sely) &&
                                                (j != Plate.sely - 2 && j != Plate.sely - 1 && j != Plate.sely + 1 && j != Plate.sely + 2 || i != Plate.selx))
                                            {
                                                Plate.plateCol[i][j] = Color.black;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    Plate.colRefresh();
                                    Plate.calMove(Plate.selx, Plate.sely);
                                }
                            }
                            else if (answer == "P" && issteal)
                            {
                                if (curx > 0 && Plate.plate[curx - 1][cury] != null && Plate.plate[curx - 1][cury].ismechanics())
                                {
                                    Plate.plate[curx - 1][cury].player = player;
                                }
                                if (cury > 0 && Plate.plate[curx][cury - 1] != null && Plate.plate[curx][cury - 1].ismechanics())
                                {
                                    Plate.plate[curx][cury - 1].player = player;
                                }
                                if (curx < 14 && Plate.plate[curx + 1][cury] != null && Plate.plate[curx + 1][cury].ismechanics())
                                {
                                    Plate.plate[curx + 1][cury].player = player;
                                }
                                if (cury < 14 && Plate.plate[curx][cury + 1] != null && Plate.plate[curx][cury + 1].ismechanics())
                                {
                                    Plate.plate[curx][cury + 1].player = player;
                                }
                                turnTurn();
                                return;
                            }
                            else if (answer == "K")
                            {
                                mode = 0;
                                Plate.colRefresh();
                                return;
                            }
                            else
                            {
                                Debug.Log("J!");
                                int response = Plate.listenKey(answer);
                                Debug.Log("Respond!" + response);
                                if (response == 0)
                                { //移动,返回0
                                    if (isPush)
                                    {
                                        pushMec(Plate.selx, Plate.sely, curx, cury);
                                    }
                                    GameObject oldPiece = Plate.floors[curx][cury].GetComponent <BoardSquare>().piece;
                                    if (oldPiece != null)
                                    {
                                        Destroy(oldPiece);
                                    }
                                    Plate.floors[curx][cury].GetComponent <BoardSquare>().piece = Plate.floors[Plate.selx][Plate.sely].GetComponent <BoardSquare>().piece;
                                    _GameManager.MovePiece(selectedCoord);
                                    Plate.floors[Plate.selx][Plate.sely].GetComponent <BoardSquare>().piece = null;

                                    turnTurn();
                                    return;
                                }
                                else if (response != -1)
                                { //不是无效按键
                                    //!!!TODO skill
                                    mode = response;

                                    Plate.colRefresh();
                                    Plate.calSkill();
                                    return;
                                }
                                else
                                {
                                    mode = 0;
                                    Plate.colRefresh();
                                }
                            }
                        }
                        else
                        {
                            mode = 0;
                            Plate.colRefresh();
                        }
                    }
                    else
                    {
                        mode = 0;
                        Plate.colRefresh();
                    }
                }
            }
            else if (mode == 2)
            {
                if (Plate.releaseSkill())
                {
                    turnTurn();
                    return;
                }
            }
        }
Пример #14
0
        // Use this for initialization
        void DrawBoard()
        {
            Plate.init();
            Plate.floors = new GameObject[15][];
            for (int i = 0; i < 15; i++)
            {
                Plate.floors[i] = new GameObject[15];
            }

            for (int i = -1; i <= 15; ++i)
            {
                for (int j = -1; j <= 15; ++j)
                {
                    GameObject floor;

                    Vector3 position = offset + new Vector3(i * 2, 0f, j * 2);
                    if (i < 5 || i > 9)
                    {
                        position += new Vector3(0f, 0.5f, 0);
                    }
                    if (i >= 0 && i < 15 && j >= 0 && j < 15)
                    {
                        if ((i + j) % 2 == 0)
                        {
                            floor = Instantiate(floor01D, position, rotation);
                        }
                        else
                        {
                            floor = Instantiate(floor02D, position, rotation);
                        }
                        floor.transform.parent = gameObject.transform;

                        floor.GetComponent <BoardSquare>().posx = i;
                        floor.GetComponent <BoardSquare>().posy = j;

                        GameObject newplane = Instantiate(Plane, position + new Vector3(0f, 1.1f, 0f), rotation);
                        newplane.SetActive(false);
                        newplane.transform.parent = floor.transform;
                        Plate.floors[i][j]        = floor;
                    }
                    if (i == 15)
                    {
                        GameObject border, border2, border3;
                        if (j == 15)
                        {
                            border = Instantiate(blockSpike02D, position + new Vector3(-0.5f, 1.5f, -0.5f), rotation);
                            border.transform.parent = gameObject.transform;
                            border3 = Instantiate(blockS02D, position + new Vector3(0.5f, 1.5f, -0.5f), rotation);
                            border3.transform.parent = gameObject.transform;
                        }
                        else
                        {
                            border = Instantiate(blockS01D, position + new Vector3(-0.5f, 1.5f, -0.5f), rotation);
                            border.transform.parent = gameObject.transform;
                        }

                        if (j == -1)
                        {
                            border2 = Instantiate(blockSpike01D, position + new Vector3(-0.5f, 1.5f, 0.5f), rotation);
                            border2.transform.parent = gameObject.transform;
                            border3 = Instantiate(blockS01D, position + new Vector3(0.5f, 1.5f, 0.5f), rotation);
                            border3.transform.parent = gameObject.transform;
                        }
                        else
                        {
                            border2 = Instantiate(blockS02D, position + new Vector3(-0.5f, 1.5f, 0.5f), rotation);
                            border2.transform.parent = gameObject.transform;
                        }
                    }

                    if (i == -1)
                    {
                        GameObject border, border2, border3;
                        if (j == 15)
                        {
                            border = Instantiate(blockSpike01D, position + new Vector3(0.5f, 1.5f, -0.5f), rotation);
                            border.transform.parent = gameObject.transform;
                            border3 = Instantiate(blockS01D, position + new Vector3(-0.5f, 1.5f, -0.5f), rotation);
                            border3.transform.parent = gameObject.transform;
                        }
                        else
                        {
                            border = Instantiate(blockS02D, position + new Vector3(0.5f, 1.5f, -0.5f), rotation);
                            border.transform.parent = gameObject.transform;
                        }

                        if (j == -1)
                        {
                            border2 = Instantiate(blockSpike02D, position + new Vector3(0.5f, 1.5f, 0.5f), rotation);
                            border2.transform.parent = gameObject.transform;
                            border3 = Instantiate(blockS02D, position + new Vector3(-0.5f, 1.5f, 0.5f), rotation);
                            border3.transform.parent = gameObject.transform;
                        }
                        else
                        {
                            border2 = Instantiate(blockS01D, position + new Vector3(0.5f, 1.5f, 0.5f), rotation);
                            border2.transform.parent = gameObject.transform;
                        }
                    }
                    if ((j == -1 || j == 15) && i != -1 && i != 15)
                    {
                        float z = 0.5f;
                        if (j == 15)
                        {
                            z = -0.5f;
                        }
                        GameObject border, border2;
                        border = Instantiate(blockS01D, position + new Vector3(z, 1.5f, z), rotation);
                        border.transform.parent = gameObject.transform;
                        border2 = Instantiate(blockS02D, position + new Vector3(-z, 1.5f, z), rotation);
                        border2.transform.parent = gameObject.transform;
                    }
                }
            }
        }
Пример #15
0
        void turnTurn()
        {
            Plate.turnTurn();
            for (int p = 0; p <= 1; ++p)
            {
                if (flag[p])
                {
                    bool findflag = false;
                    bool findKing = false;
                    int  maxvalue = -1, maxx = 0, maxy = 0;
                    for (int i = 0; i < 15; ++i)
                    {
                        for (int j = 0; j < 15; ++j)
                        {
                            if (Plate.plate[i][j] == null || Plate.plate[i][j].player != p)
                            {
                                continue;
                            }
                            if (Plate.plate[i][j].dizzy > 0)
                            {
                                Plate.plate[i][j].dizzy--;
                            }
                            if (Plate.plate[i][j].value() > maxvalue)
                            {
                                if (maxvalue < Plate.plate[i][j].value())
                                {
                                    maxvalue = Plate.plate[i][j].value();
                                    maxx     = i; maxy = j;
                                }
                            }
                            if (Plate.plate[i][j] is King)
                            {
                                findKing = true;
                            }
                            if (Plate.plate[i][j] is Flag)
                            {
                                if ((p == 0 && i > 9) || (p == 1 && i < 5))
                                {
                                    Debug.Log("玩家" + p.ToString() + "通过插旗获得胜利。");
                                    //  string answer=Console.ReadKey().Key.ToString();
                                }
                                findflag = true;
                            }
                        }
                    }
                    if (findflag == false)
                    {
                        flag[p] = false;
                        Plate.plate[maxx][maxy] = null;
                    }
                    if (findKing == false)
                    {
                        Debug.Log("玩家" + (1 - p).ToString() + "获得胜利。");
                        //  string answer=Console.ReadKey().Key.ToString();
                    }
                }
            }

            mode   = 0;
            player = 1 - player;

            Debug.Log("turn!" + player);
            Plate.colRefresh();
        }