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 cc; HexPiece hp; PointInt pnt; for (int i = 0; i < _decorations.Length; i++) { bool isWhite = (i / ((_hexBoard.Size - 1) * 2)) == 0; pnt = getDecoratorPnt(i); hp = new HexPiece(pnt); hp.State = isWhite ? HexPieceState.White : HexPieceState.Black; cc = new Button(); cc.Opacity = .3; cc.IsEnabled = false; cc.DataContext = cc.Content = hp; _decorations[i] = cc; this.AddVisualChild(cc); } }
public void Execute(object parameter) { HexPiece piece = (HexPiece)parameter; Debug.Assert(piece.State == HexPieceState.Unused); _hexBoard.Play(piece.Point); }
public HexBoard(int size) { Debug.Assert(size >= 2); _size = size; _pieces = new HexPiece[_size * _size]; _playCommand = new HexPlayCommand(this); _resetCommand = new HexResetCommand(this); _connectionTest = new BitArrayPlus(_size * _size); initialize(); }
private void initialize() { for (int col = 0; col < _size; col++) { for (int row = 0; row < _size; row++) { _pieces[getIndex(col, row)] = new HexPiece(col, row); } } CurrentPlayer = Player.White; PlayCount = 0; IsFinished = false; }
internal void Play(PointInt point) { if (!IsFinished) { validatePnt(point, _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; } } } }
public bool CanExecute(object parameter) { HexPiece piece = (HexPiece)parameter; return(piece.State == HexPieceState.Unused); }