Exemplo n.º 1
0
    public void SetPosition(GameObject obj)
    {
        Chessman cm = obj.GetComponent <Chessman>();

        //Overwrites either empty space or whatever was there
        positions[cm.GetXBoard(), cm.GetYBoard()] = obj;
    }
Exemplo n.º 2
0
        public void LineMovePlate(int xIncrement, int yIncrement, string name)
        {
            GameObject objeto     = GameObject.Find(name);
            Chessman   chesspiece = objeto.GetComponent <Chessman>();
            GameObject Controller = GameObject.FindGameObjectWithTag("GameController");

            /*A variavel do tipo game "sc" vai receber um componente
             * do objeto Controller,sendo esse componente o script Game*/
            Game sc = Controller.GetComponent <Game>();

            /*recebemos o x e o y da peça no tabuleiro e icrementamos
             * de acordo com os argumentos do método*/
            int x = chesspiece.GetXBoard() + xIncrement;
            int y = chesspiece.GetYBoard() + yIncrement;

            /*enquanto a posição no tabuleiro existir,e não ouver nada
             * nessa posição*/
            while (sc.PositionOnBoard(x, y) && sc.GetPosition(x, y) == null)
            {
                //Coloca um moveplate no tabuleiro na posição x e y
                movePlateSpawner.MovePlateSpawn(x, y, Tipos.Normal, chesspiece.name);
                x += xIncrement;
                y += yIncrement;
            }

            /*se a posição existir e a posição for de um jogador que
             * não é o jogador atual*/
            if (sc.PositionOnBoard(x, y) && sc.GetPosition(x, y).GetComponent <Chessman>().GetPlayer() != chesspiece.GetPlayer())
            {
                //Cria um moveplate de ataque
                movePlateSpawner.MovePlateSpawn(x, y, Tipos.Attack, chesspiece.name);
            }
        }
Exemplo n.º 3
0
    //Coloca as peças na matriz
    public void SetPosition(GameObject obj)
    {
        Chessman cm = obj.GetComponent <Chessman>();

        //sobrescreve o espaço vazio ou qualquer coisa que esteja la
        //adiciona no x e y a peça de xadrez.
        Positions[cm.GetXBoard(), cm.GetYBoard()] = obj;
    }
Exemplo n.º 4
0
        public void VerifyEnPassant(string name)
        {
            GameObject objeto     = GameObject.Find(name);
            Chessman   chesspiece = objeto.GetComponent <Chessman>();
            int        Xboard     = chesspiece.GetXBoard();
            int        Yboard     = chesspiece.GetYBoard();

            if (Xboard == 0)
            {
                if (chesspiece.tipo == TiposPeca.white_pawn && PieceExist(Xboard + 1, Yboard, TiposPeca.black_pawn))
                {
                    EnPassantMovePlate(1, 1, name);
                }
                else if (chesspiece.tipo == TiposPeca.black_pawn && PieceExist(Xboard + 1, Yboard, TiposPeca.white_pawn))
                {
                    EnPassantMovePlate(1, -1, name);
                }
            }
            else if (Xboard == 7)
            {
                if (chesspiece.tipo == TiposPeca.white_pawn && PieceExist(Xboard - 1, Yboard, TiposPeca.black_pawn))
                {
                    EnPassantMovePlate(-1, 1, name);
                }
                else if (chesspiece.tipo == TiposPeca.black_pawn && PieceExist(Xboard - 1, Yboard, TiposPeca.white_pawn))
                {
                    EnPassantMovePlate(-1, -1, name);
                }
            }
            else
            {
                if (chesspiece.tipo == TiposPeca.white_pawn)
                {
                    if (PieceExist(Xboard + 1, Yboard, TiposPeca.black_pawn))
                    {
                        EnPassantMovePlate(1, 1, name);
                    }
                    if (PieceExist(Xboard - 1, Yboard, TiposPeca.black_pawn))
                    {
                        EnPassantMovePlate(-1, 1, name);
                    }
                }
                if (chesspiece.tipo == TiposPeca.black_pawn)
                {
                    if (PieceExist(Xboard + 1, Yboard, TiposPeca.white_pawn))
                    {
                        EnPassantMovePlate(1, -1, name);
                    }
                    if (PieceExist(Xboard - 1, Yboard, TiposPeca.white_pawn))
                    {
                        EnPassantMovePlate(-1, -1, name);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void SurroundMovePlate(string name)
        {
            GameObject objeto     = GameObject.Find(name);
            Chessman   chesspiece = objeto.GetComponent <Chessman>();
            int        Xboard     = chesspiece.GetXBoard();
            int        Yboard     = chesspiece.GetYBoard();

            PointMovePlate(Xboard, Yboard + 1, name);
            PointMovePlate(Xboard, Yboard - 1, name);
            PointMovePlate(Xboard - 1, Yboard + 0, name);
            PointMovePlate(Xboard - 1, Yboard - 1, name);
            PointMovePlate(Xboard - 1, Yboard + 1, name);
            PointMovePlate(Xboard + 1, Yboard + 0, name);
            PointMovePlate(Xboard + 1, Yboard - 1, name);
            PointMovePlate(Xboard + 1, Yboard + 1, name);
        }
Exemplo n.º 6
0
        public void CheckCastling(string name)
        {
            GameObject Controller = GameObject.FindGameObjectWithTag("GameController");
            Game       jogo       = Controller.GetComponent <Game>();
            string     player     = Controller.GetComponent <Game>().GetCurrentPlayer();

            if (player == "white")
            {
                Chessman rei    = GameObject.Find("white_king1").GetComponent <Chessman>();
                Chessman torre1 = GameObject.Find("white_rook1").GetComponent <Chessman>();
                Chessman torre2 = GameObject.Find("white_rook2").GetComponent <Chessman>();
                //jogo.GetPosition();
                if (rei.GetXBoard() == 4 && rei.GetYBoard() == 0 && rei.Moves == 0)
                {
                    if (torre1.GetXBoard() == 0 && torre1.GetYBoard() == 0 && torre1.Moves == 0 && jogo.GetPosition(1, 0) == null &&
                        jogo.GetPosition(2, 0) == null && jogo.GetPosition(3, 0) == null)
                    {
                        movePlateSpawner.MovePlateSpawn(0, 0, Tipos.Castling, name);
                    }
                    if (torre2.GetXBoard() == 7 && torre2.GetYBoard() == 0 && jogo.GetPosition(5, 0) == null &&
                        jogo.GetPosition(6, 0) == null && torre2.Moves == 0)
                    {
                        movePlateSpawner.MovePlateSpawn(7, 0, Tipos.Castling, name);
                    }
                }
            }
            else
            {
                Chessman rei    = GameObject.Find("black_king1").GetComponent <Chessman>();
                Chessman torre1 = GameObject.Find("black_rook1").GetComponent <Chessman>();
                Chessman torre2 = GameObject.Find("black_rook2").GetComponent <Chessman>();
                if (rei.GetXBoard() == 4 && rei.GetYBoard() == 7 && rei.Moves == 0)
                {
                    if (torre1.GetXBoard() == 0 && torre1.GetYBoard() == 7 && torre1.Moves == 0 && jogo.GetPosition(1, 7) == null &&
                        jogo.GetPosition(2, 7) == null && jogo.GetPosition(3, 7) == null)
                    {
                        movePlateSpawner.MovePlateSpawn(0, 7, Tipos.Castling, name);
                    }
                    if (torre2.GetXBoard() == 7 && torre2.GetYBoard() == 7 && torre2.Moves == 0 && jogo.GetPosition(5, 7) == null &&
                        jogo.GetPosition(6, 7) == null)
                    {
                        movePlateSpawner.MovePlateSpawn(7, 7, Tipos.Castling, name);
                    }
                }
            }
        }
Exemplo n.º 7
0
        void EnPassantMovePlate(int x, int y, string name)
        {
            GameObject Controller = GameObject.FindGameObjectWithTag("GameController");
            Game       game       = Controller.GetComponent <Game>();
            GameObject objeto     = GameObject.Find(name);
            Chessman   chesspiece = objeto.GetComponent <Chessman>();
            int        Xboard     = chesspiece.GetXBoard();
            int        Yboard     = chesspiece.GetYBoard();
            GameObject Posicao    = Controller.GetComponent <Game>().GetPosition(Xboard + x, Yboard);

            if (Posicao.GetComponent <Chessman>().GetXBoard() == game.LastMoves[0] &&
                Posicao.GetComponent <Chessman>().GetYBoard() == game.LastMoves[1] &&
                Posicao.GetComponent <Chessman>().Moves == 1 &&
                Posicao.GetComponent <Chessman>().PawnDoubleMove == true)
            {
                movePlateSpawner.MovePlateSpawn(Xboard + x, Yboard + y, Tipos.EnPassant, name);
            }
        }
Exemplo n.º 8
0
    public void SetPosition(GameObject obj)
    {
        Chessman cm = obj.GetComponent <Chessman>();

        positions[cm.GetXBoard(), cm.GetYBoard()] = obj;
    }
Exemplo n.º 9
0
        public void InitiateMovePlates(string name)
        {
            int        len        = name.Length;
            string     realName   = name.Substring(0, len - 1);
            GameObject objeto     = GameObject.Find(name);
            Chessman   chesspiece = objeto.GetComponent <Chessman>();
            int        Xboard     = chesspiece.GetXBoard();
            int        Yboard     = chesspiece.GetYBoard();

            switch (chesspiece.tipo)
            {
            //se for uma rainha preta ou branca
            case TiposPeca.queen:
                //Moveplates nas seguintes posições
                movePlateSpawnTypes.LineMovePlate(1, 0, name);
                movePlateSpawnTypes.LineMovePlate(0, 1, name);
                movePlateSpawnTypes.LineMovePlate(1, 1, name);
                movePlateSpawnTypes.LineMovePlate(-1, 0, name);
                movePlateSpawnTypes.LineMovePlate(0, -1, name);
                movePlateSpawnTypes.LineMovePlate(-1, -1, name);
                movePlateSpawnTypes.LineMovePlate(-1, 1, name);
                movePlateSpawnTypes.LineMovePlate(1, -1, name);
                break;

            //se for um cavalo preto ou branco
            case TiposPeca.knight:
                movePlateSpawnTypes.LMovePlate(name);
                break;

            //se for um bispo preto ou branco
            case TiposPeca.bishop:
                //Moveplates nas seguintes posições
                movePlateSpawnTypes.LineMovePlate(1, 1, name);
                movePlateSpawnTypes.LineMovePlate(1, -1, name);
                movePlateSpawnTypes.LineMovePlate(-1, 1, name);
                movePlateSpawnTypes.LineMovePlate(-1, -1, name);
                break;

            //se for um Rei preto ou branco
            case TiposPeca.king:
                //Moveplates nas seguintes posições
                //Obs:Provavel erro pois ele se move nas diagonais
                movePlateSpawnTypes.SurroundMovePlate(name);
                specialMoves.CheckCastling(name);
                break;

            //se for uma torre preta ou branca
            case TiposPeca.rook:
                //Moveplates nas seguintes posições
                movePlateSpawnTypes.LineMovePlate(1, 0, name);
                movePlateSpawnTypes.LineMovePlate(0, 1, name);
                movePlateSpawnTypes.LineMovePlate(-1, 0, name);
                movePlateSpawnTypes.LineMovePlate(0, -1, name);
                break;

            //se for um peão preto
            case TiposPeca.black_pawn:
                //Moveplates nas seguintes posições
                movePlateSpawnTypes.PawnMovePlate(Xboard, Yboard - 1, name);
                //VerifyEnPassant("black");
                if (Yboard == 3)
                {
                    specialMoves.VerifyEnPassant(name);
                }
                break;

            case TiposPeca.white_pawn:
                // se for um peão branco
                //Moveplates nas seguintes posições
                movePlateSpawnTypes.PawnMovePlate(Xboard, Yboard + 1, name);
                if (Yboard == 4)
                {
                    specialMoves.VerifyEnPassant(name);
                }

                break;
            }
        }