예제 #1
0
 public void DeclarePat()
 {
     // COMPLETARE CU UI
     Debug.Log("Pat!");
     MenuListener.ShowMessage("Draw!", 120);
     RestartGame(settings);
 }
예제 #2
0
    public void Move(GameObject piece, Vector2Int gridPoint)
    {
        Piece pieceComponent = piece.GetComponent<Piece>();
        if (pieceComponent.type == PieceType.Pawn && !HasPawnMoved(piece))
        {
            movedPawns.Add(piece);
        }

        if (PieceAtGrid(gridPoint) != null) CapturePieceAt(gridPoint);

        Vector2Int startGridPoint = GridForPiece(piece);
        pieces[startGridPoint.x, startGridPoint.y] = null;
        pieces[gridPoint.x, gridPoint.y] = piece;
        board.MovePiece(piece, gridPoint);
        underCheck = false;

        // Smecheria aia cu rocada
        if (!movedPieces.Contains(piece)) movedPieces.Add(piece);
        if (pieceComponent.type == PieceType.King && Mathf.Abs(startGridPoint.x - gridPoint.x) > 1)
        {
            Vector2Int rook_start, rook_destination;
            // Verifica rocada mica
            if (gridPoint.x == 6)
            {
                rook_start = new Vector2Int(7, gridPoint.y);
                rook_destination = new Vector2Int(5, gridPoint.y);
            }
            // Rocada mare
            else
            {
                rook_start = new Vector2Int(0, gridPoint.y);
                rook_destination = new Vector2Int(2, gridPoint.y);
            }
            pieces[rook_destination.x, rook_destination.y] = pieces[rook_start.x, rook_start.y];
            board.MovePiece(pieces[rook_start.x, rook_start.y], rook_destination);
            pieces[rook_start.x, rook_start.y] = null;
        }

        // Alegere piesa noua
        if (pieceComponent.type == PieceType.Pawn && (gridPoint.y == 0 || gridPoint.y == 7))
        {
            if (!currentPlayer.AI)
            {
                board.GetComponent<MoveSelector>().TriggerPawnSelection(piece, gridPoint);
                MenuListener.ShowMessage("Chose a piece to replace your pawn", 120);
            }
            else
            {
                currentPlayer.pieces.Remove(piece);
                movedPawns.Remove(piece);
                Destroy(piece);
                pieces[gridPoint.x, gridPoint.y] = null;

                GameObject prefab;
                if (currentPlayer.name == "white") prefab = whiteQueen;
                else prefab = blackQueen;
                GameManager.instance.AddPiece(prefab, GameManager.instance.currentPlayer, gridPoint.x, gridPoint.y);
            }
        }
    }
예제 #3
0
    public void DebugButton(GameObject obj)
    {
        MenuListener.ShowMessage("Mesaj", 120);
        //var gameObject = Instantiate(obj);
        //PawnPicker.Prepare(gameObject); // setez pawn picker

        //PawnPicker.Activate(DebugChoice);
    }
예제 #4
0
    public void NextPlayer()
    {
        Vector2Int kingPos = new Vector2Int(-1, -1);
        for (int i = 0; i < 8; i++)
            for (int j = 0; j < 8; j++)
            {
                if (pieces[i, j] != null && pieces[i, j].GetComponent<Piece>().type == PieceType.King)
                {
                    if (otherPlayer.pieces.Contains(pieces[i, j]))
                    {
                        kingPos = new Vector2Int(i, j);
                    }
                }
            }

        if (kingPos == new Vector2Int(-1, -1))
        {
            Debug.LogWarning("Can't find the king of current player! Can't undeCheck for check");
            Player tmp = currentPlayer;
            currentPlayer = otherPlayer;
            otherPlayer = tmp;
            return;
        }

        foreach (var piece in currentPlayer.pieces)
        {
            List<Vector2Int> moves = MovesForPiece(piece);
            if (moves.Contains(kingPos))
            {
                underCheck = true;
                if (currentPlayer.AI)
                    MenuListener.ShowMessage("Check!", 120);
                break;
            }
        }

        Player tempPlayer = currentPlayer;
        currentPlayer = otherPlayer;
        otherPlayer = tempPlayer;

        bool pat = true;
        foreach (var piece in currentPlayer.pieces)
        {
            List<Vector2Int> moves = MovesForPiece(piece);
            if (moves.Count > 0)
            {
                pat = false;
                break;
            }
        }

        if (pat)
        {
            if (underCheck) DeclareWin(otherPlayer);
            else GameManager.instance.DeclarePat();
        }
    }