コード例 #1
0
        private void LitSquareClicked(object sender, MouseEventArgs e)
        {
            RemoveAllLitSquares();
            if (sender.GetType().Name == "Border")
            {
                Border v    = (Border)sender;
                string name = v.Name;
                SidePanelTextBox.Text += "\n" + name + " clicked.";
                SidePanelTextBox.ScrollToEnd();
                // get coords from name
                string[] vals = name.Split('_');
                if (vals.Count() == 3)
                {
                    string x_str = vals[1];
                    string y_str = vals[2];
                    int    x     = x_str[0] - '0';
                    int    y     = y_str[0] - '0';
                    int    xo    = SelectedCoordinate.x;
                    int    yo    = SelectedCoordinate.y;
                    SidePanelTextBox.Text += String.Format("Xn: {0} Yn: {1} Xo: {2} Yo: {3}", x, y, xo, yo);

                    // actually change the piece on the board now

                    /* TODO:    there's a question of where the turns should be stored - in the UI or the Backend.
                     *          I can see reasons for both sides.   Ultimately, I want to keep the Game lib separate
                     *          from an actual game -- at least for now because I'd like to be able to extend beyond 8x8 boards.
                     *          There are some hardcodes there that are keeping it 8x8, but I'd like to be able to scale soon
                     *          after getting an actual game to work.
                     */
                    //if (Board.ToString)
                    if (SelectedPiece.color == Turn)
                    {
                        Board.Move(new Point {
                            X = xo, Y = yo
                        }, new Point {
                            X = x, Y = y
                        });
                        GetSetTurn             = "";                // set turn color
                        SidePanelTextBox1.Text = Board.MoveList_PointNotation;
                        BoardString            = Board.BoardString; /// TODO: DataBinding isn't working the way I'd expect
                        SidePanelTextBox0.Text = BoardString;       // changing the BoardString from the GameLib doesn't update the UI
                        ViewBoardString();
                    }
                }
            }
        }
コード例 #2
0
        private void SquareClicked(object sender, MouseEventArgs e)
        {
            RemoveAllLitSquares();
            if (sender.GetType().Name == "Viewbox")
            {
                Viewbox v    = (Viewbox)sender;
                string  name = v.Name;
                SidePanelTextBox.Text += "\n" + name + " clicked.";
                SidePanelTextBox.ScrollToEnd();
                // get coords from name
                string[] vals = name.Split('_');
                if (vals.Count() == 3)
                {
                    string x_str = vals[1];
                    string y_str = vals[2];
                    int    x     = x_str[0] - '0';
                    int    y     = y_str[0] - '0';
                    SidePanelTextBox.Text += String.Format("X: {0} Y: {1}", x, y);
                    string PngName = ((Image)v.Child).Source.ToString();
                    PngName = 6 > PngName.Length ? PngName : PngName.Substring(PngName.Length - 6);


                    // get piece from dict
                    string PieceName = GetPieceFromPngName(PngName);
                    SidePanelTextBox.Text += String.Format(" {0} {1}", PngName, PieceName);
                    LightUpBorderOnGrid(x, y);  // light the current piece

                    // get piece on board
                    char       xchr = (y + 1).ToString()[0];
                    char       ychr = (x + 1).ToString()[0];
                    Game.Piece p    = Game.GetPieceOnSquare(Board, xchr, ychr);
                    SelectedCoordinate = new coordinate(x, y);
                    SelectedPiece      = p;

                    // get possible moves
                    List <Point> pts = Game.ValidMoves(Board, p);
                    // convert them and light them up
                    foreach (Point pt in pts)
                    {
                        LightUpBorderOnGrid((int)pt.Y - 1, (int)pt.X - 1);
                    }
                }
                // get image name from grid?
            }
        }