Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9171655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:11:33+00:00 2026-06-17T16:11:33+00:00

I have an if else statement that identifies whether or not users have won

  • 0

I have an if else statement that identifies whether or not users have won my tic tac toe game however it’s my mission! 🙂 to make the code more compact and easier to read and I have lots of duplicate blocks of code and reduce the amount of code I have.

here’s some of my code:

if (button1.Text == "X" & button2.Text == "X" & button3.Text == "X")
{
    foreach (Button button in addButton())
    {
        button1.BackColor = Color.Green;
        button2.BackColor = Color.Green;
        button3.BackColor = Color.Green;
        button.Enabled = false;
    }
}
else if (button1.Text == "X" & button4.Text == "X" & button7.Text == "X")
{
    foreach (Button button in addButton())
    {
        button1.BackColor = Color.Green;
        button4.BackColor = Color.Green;
        button7.BackColor = Color.Green;
        button.Enabled = false;
    }
}
else if (button1.Text == "X" & button5.Text == "X" & button9.Text == "X")
{
    foreach (Button button in addButton())
    {
        button1.BackColor = Color.Green;
        button4.BackColor = Color.Green;
        button7.BackColor = Color.Green;
        button.Enabled = false;
    }
}

I was thinking maybe I could put this in a private method? But not sure if you actually can and I wouldn’t know how to call upon the method, or even a class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:11:34+00:00Added an answer on June 17, 2026 at 4:11 pm

    Use an underlying data model to represent your data. Let’s say an array of ints.

    int[,] board  = new int[,] {{0,0,0}, {0,0,0},{0,0,0}};
    

    Then anytime an X is played, you set that position in the array to 1.

    Anytime an O is played, you set the position to -1.

    To check for a winner, you simply loop over your winning combinations, across, down, and the 2 cross patters and if they = 3 X wins and if they = -3 then O wins.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an if/else statement that is not working. while (rdr.Read()) { string permission
I have a basic conditional statement that has a chaining function. After the else
I have a fairly simple if else statement in C# that looks something like
I have an if/else if statement that looks like this: if(myNode->left->is_red){ //CODE TO EXECUTE
I have an if else statement that change language Capabilitie EN to ENGLISH. The
I have a PHP file that contains a lot of if and else statements
I have a if-else statement which isn't quite working as I would want it
ill have an if statement if (int1 < int2) {} else {} I want
Is it possible to have a SELECT statement in mySQL with an IF/ELSE clause
How can I identify the datas that have anything else than a number in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.