Пример #1
0
        private void square_click(object sender, EventArgs e)
        {
            SquareButton square = (SquareButton)sender;

            if (turn)
            {
                square.BackgroundImage       = imagePlayer1;
                square.BackgroundImageLayout = ImageLayout.Stretch;

                square.ButtonText = "X";
                this.toolStripStatusLabel.Text = "Player 2 Turn";
            }
            else
            {
                square.BackgroundImage = imagePlayer2;
                //square.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Tim_Downey2));
                square.BackgroundImageLayout = ImageLayout.Stretch;

                square.ButtonText = "O";
                this.toolStripStatusLabel.Text = "Player 1 Turn";
            }

            turn = !turn;
            turnCount++;
            square.Enabled = false;

            checkForWinner();
            CaptureForm();
        }
Пример #2
0
        /*
         * allows us to draw over controls
         * hack...I mean code taken from:
         * https://stackoverflow.com/questions/282838/drawing-on-top-of-controls-inside-a-panel-c-winforms
         */
        private void DrawWininigLine(object sender, Graphics g)
        {
            Point p1 = WiningLineStartPosition();
            Point p2 = WiningLineEndPositon();

            if (sender is SquareButton)
            {
                SquareButton btn = (SquareButton)sender;
                {
                    p1.X -= btn.Left;
                    p1.Y -= btn.Top;
                    p2.X -= btn.Left;
                    p2.Y -= btn.Top;
                }
            }
            g.DrawLine(pen, p1, p2);
        }