Example #1
0
    // Handle click events from the image buttons on the web page
    protected void ImageButton_Click(object sender, ImageClickEventArgs e)
    {
        // Get a reference to the image button that was clicked
        ImageButton imgBtn = ((ImageButton)sender);
        // Get the number of the button that was clicked
        int bNum = int.Parse(imgBtn.ID.Substring(11));

        // Put an X or O in into the GameGrid array
        int row = bNum / TicTacToe.COLS;    // Get a zero based table row number
        int col = bNum % TicTacToe.COLS;    // Get a zero based table column number

        if (!tttGame.AddMark(row, col))
        {
            lblMessage.Text = "You can't change that!";
        }

        // See if we have a winner
        char winner = tttGame.CheckForWinner();

        if (winner != ' ')
        {
            lblMessage.Text = winner + " Won!";
        }

        UpdateImage(row, col);
        //  ReloadPageData();
    }