Example #1
0
        private void setDecorations()
        {
            //1st (size-1): white top left
            //2nd (size-1): white bottom right
            //3rd (size-1): black bottom left
            //4th (size-1): black top right

            ContentControl contentControl;
            HexPiece       hexPiece;
            PointInt       pnt;

            for (int i = 0; i < _decorations.Length; i++)
            {
                bool isWhite = (i / ((_hexBoard.Size - 1) * 2)) == 0;

                pnt = getDecoratorPnt(i);

                hexPiece       = new HexPiece(pnt);
                hexPiece.State = isWhite ? HexPieceState.White : HexPieceState.Black;

                contentControl             = new Button();
                contentControl.Opacity     = .3;
                contentControl.IsEnabled   = false;
                contentControl.DataContext = contentControl.Content = hexPiece;

                _decorations[i] = contentControl;

                this.AddVisualChild(contentControl);
            }
        }
Example #2
0
        internal bool Play(PointInt point)
        {
            if (!IsFinished)
            {
                validatePnt(point, m_size);
                int index = getIndex(point);

                HexPiece piece = _pieces[index];

                if (piece.State == HexPieceState.Unused)
                {
                    piece.State  = (CurrentPlayer == Player.Black) ? HexPieceState.Black : HexPieceState.White;
                    piece.Number = (++PlayCount);

                    checkFinished();
                    if (!IsFinished)
                    {
                        CurrentPlayer = (CurrentPlayer == Player.Black) ? Player.White : Player.Black;
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        public HexBoard(int size)
        {
            Contract.Requires <ArgumentOutOfRangeException>(size >= 2);
            m_size  = size;
            _pieces = new HexPiece[m_size * m_size];

            m_resetCommand = new DelegateCommand(Reset, () => m_playCount > 0);

            m_connectionTest = new BitArrayPlus(m_size * m_size);

            initialize();
        }
Example #4
0
        private void initialize()
        {
            for (int col = 0; col < m_size; col++)
            {
                for (int row = 0; row < m_size; row++)
                {
                    _pieces[getIndex(col, row)] = new HexPiece(col, row);
                }
            }

            CurrentPlayer = Player.White;
            PlayCount     = 0;
            IsFinished    = false;
        }