Example #1
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;
                }
            }
        }
Example #2
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();
        }