Ejemplo n.º 1
0
        /// <summary>
        /// Sets the current start square as clicked
        /// </summary>
        /// <param name="view">Start Square</param>
        public void SetStart(BoardSquareView view)
        {
            if (currentPlayer.IsHuman && currentRoll != null && IsAllowedToMoveMarbles())
            {
                Square sq = view.Square;
                if (!IsPartOfMove(sq))
                {
                    if (currentDrag == null && board.Get(sq) == currentPlayer.Team)
                    {
                        Vector2?pos = GetVector(sq);

                        if (pos.HasValue)
                        {
                            currentDrag = new MarbleView(this, sq, currentPlayer.Team, pos.Value);
                            currentDrag.StartDrag();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resizes the board
        /// </summary>
        private void Resize(Rectangle size)
        {
            this.View = size;
            const int startOffset = 20;

            int tileWidth  = (int)Math.Round(View.Width / 29.166666666666666666666666666667);
            int tileHeight = (int)Math.Round(View.Height / 29.166666666666666666666666666667);

            int multiplierX = (int)Math.Round(View.Width / 12.962962962962962962962962962963);
            int multiplierY = (int)Math.Round(View.Height / 12.962962962962962962962962962963);

            for (int i = 0; i < 13; i++)
            {
                if (squares[i] == null)
                {
                    squares[i] = new BoardSquareView[13];
                }
                for (int j = 0; j < 13; j++)
                {
                    if (layout[i][j] != null)
                    {
                        Square square = new Square(layout[i][j]);
                        squares[i][j] = new BoardSquareView(this, square, new Rectangle(View.X + startOffset + j * multiplierX, View.Y + startOffset + i * multiplierY, tileWidth, tileHeight));
                    }
                }
            }

            int offset      = startOffset / 2;
            int porportionX = (int)Math.Round(View.Width / 15.555555555555555555555555555556);
            int porportionY = (int)Math.Round(View.Height / 15.555555555555555555555555555556);

            for (sbyte t = 0; t < Board.TEAM_COUNT; t++)
            {
                if (starts[t] == null)
                {
                    starts[t] = new SquareView[Board.TEAM_SIZE];
                }
                for (int m = 0; m < Board.TEAM_SIZE; m++)
                {
                    Rectangle target      = new Rectangle();
                    int       orientation = t + (2 - teamPerspective);
                    if (orientation < 0)
                    {
                        orientation += 4;
                    }
                    else if (orientation >= 4)
                    {
                        orientation -= 4;
                    }

                    switch (orientation)
                    {
                    case 0:     //UPPER LEFT
                        target = new Rectangle(View.X + offset + m * porportionX, View.Y + 10 + m * porportionY, tileWidth, tileHeight);
                        break;

                    case 1:     //UPPER RIGHT
                        target = new Rectangle(View.X + View.Width - offset - (m * porportionX), View.Y + offset + m * porportionY, tileWidth, tileHeight);
                        break;

                    case 2:     //BOTTOM RIGHT
                        target = new Rectangle(View.X + View.Width - offset - (m * porportionX), View.Y + View.Height - offset - (m * porportionY), tileWidth, tileHeight);
                        break;

                    case 3:     //BOTTOM LEFT
                        target = new Rectangle(View.X + offset + m * porportionX, View.Y + View.Height - offset - (m * porportionY), tileWidth, tileHeight);
                        break;

                    default:
                        break;
                    }

                    if (starts[t][m] == null)
                    {
                        starts[t][m] = new SquareView(this, target, t);
                    }
                    else
                    {
                        starts[t][m].Rect = target;
                    }
                }
            }
        }