Exemple #1
0
        public bool Castle(Position pos)
        {
            if (!isHighlighted())
            {
                return(false);
            }
            if (!isCorrectCastling(pos))
            {
                return(false);
            }

            if (gametype == GameType.ServerGame && state == GameState.HighlightedWhite)
            {
                server.NewMove(highlightedfigurepos, pos);
            }

            if (gametype == GameType.ClientGame && state == GameState.HighlightedBlack)
            {
                client.NewMove(highlightedfigurepos, pos);
            }
            Figure fig  = Field.GetFigureAt(highlightedfigurepos);
            Figure rook = Field.GetFigureAt(pos);

            if (pos.GetX() == 1)
            {
                // длинная рокировка
                int y = pos.GetY();
                fig.SetPosition(new Position(pos.GetX() + 2, y));
                rook.SetPosition(new Position(pos.GetX() + 3, y));
            }
            if (pos.GetX() == 8)
            {
                // короткая рокировка
                int y = pos.GetY();
                fig.SetPosition(new Position(pos.GetX() - 1, y));
                rook.SetPosition(new Position(pos.GetX() - 2, y));
            }

            switch (state)
            {
            case GameState.HighlightedBlack:
                state = GameState.WaitWhite;
                break;

            case GameState.HighlightedWhite:
                state = GameState.WaitBlack;
                break;
            }
            return(true);
        }
Exemple #2
0
        public bool InMoveAttack(Position pos)
        {
            if (!isHighlighted())
            {
                return(false);
            }
            if (!isCorrectInMoveAttack(pos))
            {
                return(false);
            }
            if (inmoveattacks.Contains(pos))
            {
                if (gametype == GameType.ServerGame && state == GameState.HighlightedWhite)
                {
                    server.NewMove(highlightedfigurepos, pos);
                }

                if (gametype == GameType.ClientGame && state == GameState.HighlightedBlack)
                {
                    client.NewMove(highlightedfigurepos, pos);
                }
                Figure fig   = Field.GetFigureAt(highlightedfigurepos);
                int    delta = (fig.Side == Side.Black) ? +1 : -1;
                fig.SetPosition(new Position(pos.GetX(), pos.GetY() - delta));
                Figure killedfig = Field.GetFigureAt(pos);
                Field.Kill(killedfig);
            }

            switch (state)
            {
            case GameState.HighlightedBlack:
                state = GameState.WaitWhite;
                break;

            case GameState.HighlightedWhite:
                state = GameState.WaitBlack;
                break;
            }
            return(true);
        }
Exemple #3
0
        public bool Move(Position pos)
        {
            if (!isHighlighted())
            {
                return(false);
            }
            if (!isCorrectMove(pos))
            {
                return(false);
            }

            if (moves.Contains(pos) || attacks.Contains(pos))
            {
                if (gametype == GameType.ServerGame && state == GameState.HighlightedWhite)
                {
                    server.NewMove(highlightedfigurepos, pos);
                }

                if (gametype == GameType.ClientGame && state == GameState.HighlightedBlack)
                {
                    client.NewMove(highlightedfigurepos, pos);
                }
                Figure fig = Field.GetFigureAt(highlightedfigurepos);
                fig.SetPosition(pos);
            }
            if (!blockmove)
            {
                switch (state)
                {
                case GameState.HighlightedBlack:
                    state = GameState.WaitWhite;
                    break;

                case GameState.HighlightedWhite:
                    state = GameState.WaitBlack;
                    break;
                }
            }
            return(true);
        }