Пример #1
0
        private void PieceSelected(PieceControl pieceControl)
        {
            PieceInfo pi = pieceControl.DataContext as PieceInfo;

            for (int i = 0; i < this.availableMoves.Length; i++)
            {
                if (this.availableMoves[i].Piece == pi.Number || (currentSituation.groupingDict.ContainsKey(pi.Number) && currentSituation.groupingDict[pi.Number].Contains(this.availableMoves[i].Piece)))
                {
                    ClearSelectionOptions();
                    game.SetSelectedMove(i);
                    break;
                }
            }
        }
Пример #2
0
        private void InitializePieces()
        {
            pieces = new PieceControl[16];
            for (int i = 0; i < 16; i++)
            {
                PieceInfo pi = new PieceInfo();
                pi.Piece = (Piece)((i / 4)+1);
                switch (pi.Piece)
                {
                    case Piece.Green: pi.PieceColor = Colors.Green; break;
                    case Piece.Red: pi.PieceColor = Colors.Red; break;
                    case Piece.Blue: pi.PieceColor = Colors.Blue; break;
                    case Piece.Yellow: pi.PieceColor = Colors.Yellow; break;
                }
                pi.Number = i;
                pieces[i] = new PieceControl();
                pieces[i].DataContext = pi;
                pieces[i].PieceSelected += new PieceSelectedHandler(PieceSelected);

                Position position = (Position)(i + (int)Position.GreenHome1);

                Point offset = GetAbsolutePosition(position);

                Canvas.SetTop(pieces[i], offset.Y);
                Canvas.SetLeft(pieces[i], offset.X);
                mainCanvas.Children.Add(pieces[i]);
            }
        }