/// <summary>
        /// Evaluates whether this move is the same as another move
        /// </summary>
        /// <param name="square">Move to evaluate</param>
        public bool Equals(PieceMove move)
        {
            if (From == null)
            {
                return(move.From == null && To.Equals(move.To));
            }

            return(From.Equals(move.From) && To.Equals(move.To));
        }
Example #2
0
        /// <summary>
        /// Queues a piecemove as a animation
        /// </summary>
        /// <param name="move">Piecemove to animate</param>
        /// <param name="team">Team of move</param>
        /// <param name="time">Elapsed time for animation</param>
        public void QueueAnimation(PieceMove move, sbyte team, float time)
        {
            if (move.IsTakingOutMarble)
            {
                Vector2 start = Vector2.Zero;

                if (!currentPlayer.IsHuman)
                {
                    for (int j = starts[team].Length - 1; j >= 0; j--)
                    {
                        if (starts[team][j].HasMarble)
                        {
                            start = new Vector2(starts[team][j].Rect.X, starts[team][j].Rect.Y);
                            starts[team][j].HasMarble = false;
                            break;
                        }
                    }
                }

                Square homeSquare = new Square(team, 0);

                Vector2?homeSquareTarget = GetVector(homeSquare);
                Vector2?target           = GetVector(move.To);
                if (homeSquareTarget.HasValue && target.HasValue)
                {
                    MarbleView takeOut = new MarbleView(this, move.From, team, start);

                    if (homeSquare.Equals(move.To))
                    {
                        animations.Enqueue(new MarbleView[1] {
                            takeOut
                        });
                        takeOut.MoveTo(homeSquareTarget.Value, time);
                    }
                    else
                    {
                        MarbleView moveAnim = new MarbleView(this, move.From, team, homeSquareTarget.Value);
                        animations.Enqueue(new MarbleView[2] {
                            takeOut, moveAnim
                        });
                        takeOut.MoveTo(homeSquareTarget.Value, time / 2);
                        moveAnim.MoveTo(target.Value, time / 2);
                    }
                }
            }
            else
            {
                Vector2?start  = GetVector(move.From);
                Vector2?target = GetVector(move.To);
                if (start.HasValue && target.HasValue)
                {
                    MarbleView anim = new MarbleView(this, move.From, team, start.Value);
                    animations.Enqueue(new MarbleView[1] {
                        anim
                    });
                    anim.MoveTo(target.Value, time);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Gets the corner position of a square if the square exists
        /// </summary>
        /// <param name="square">Square</param>
        public Vector2?GetVector(Square square)
        {
            for (int i = 0; i < 13; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    if (squares[i][j] != null)
                    {
                        Square current = squares[i][j].Square;
                        if (current.Equals(square))
                        {
                            return(new Vector2(squares[i][j].Rect.X, squares[i][j].Rect.Y));
                        }
                    }
                }
            }

            return(null);
        }
Example #4
0
        /// <summary>
        /// Draws the marbles on the board
        /// </summary>
        /// <param name="batch">SpriteBatch</param>
        /// <param name="textures">Texture Library</param>
        public void DrawMarbles(SpriteBatch batch, TextureLib textures)
        {
            bool      artificiallyDrawMarble = false;
            bool      isPartOfMove           = false;
            PieceMove partOfMove             = null;

            for (int i = 0; i < 13; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    if (layout[i][j] != null)
                    {
                        Square current = new Square(layout[i][j]);
                        if (currentAnimation != null)
                        {
                            if (current.Equals(currentAnimation.From))
                            {
                                continue;
                            }
                        }

                        if (currentDrag != null)
                        {
                            if (current.Equals(currentDrag.From))
                            {
                                continue;
                            }
                        }

                        artificiallyDrawMarble = false;
                        isPartOfMove           = false;
                        for (int k = 0; k < currentMove.Count; k++)
                        {
                            if (currentMove[k].From != null)
                            {
                                if (currentMove[k].From.Equals(current))
                                {
                                    partOfMove             = currentMove[k];
                                    artificiallyDrawMarble = false;
                                    isPartOfMove           = true;
                                }
                            }

                            if (currentMove[k].To.Equals(current))
                            {
                                partOfMove             = currentMove[k];
                                artificiallyDrawMarble = true;
                                isPartOfMove           = true;
                                break;
                            }
                        }

                        if (isPartOfMove)
                        {
                            if (artificiallyDrawMarble)
                            {
                                string asset = GetMarbleAsset(currentPlayer.Team);
                                batch.Draw(textures[asset], squares[i][j].Rect, (squares[i][j].Selected) ? Color.LightBlue : Color.White);
                            }
                        }
                        else
                        {
                            int marble = board.Get(layout[i][j]);
                            if (marble != -1)
                            {
                                string asset = GetMarbleAsset(marble);
                                batch.Draw(textures[asset], squares[i][j].Rect, (squares[i][j].Selected) ? Color.LightBlue : Color.White);
                            }
                        }
                    }
                }
            }
        }