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 9184959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:10:45+00:00 2026-06-17T19:10:45+00:00

I have made a tic tac toe game and I am producing another version

  • 0

I have made a tic tac toe game and I am producing another version with less code. Anyway… here is my code… I’ve taken some of the code in between the do while statement but yeah…

    var rc = new Random();
    do
    {
        storeRI = rc.Next(1, 9);

        if (storeRI == 1 & button1.Text == "")
        {
            button1.Text = "O";
            Turn = 1;
            TestWin();
            break;
        }
        else if (storeRI == 2 & button2.Text == "")
        {
            button2.Text = "O";
            Turn = 1;
            TestWin();
            break;
        }


    } while (Turn == 2 & button1.Text == "" | button2.Text == "" | button3.Text == "" | button3.Text == "" | button4.Text == "" | button5.Text == "" | button6.Text == "" | button7.Text == "" | button8.Text == "" | button9.Text == "");
}
else
{
    MessageBox.Show("It's a draw");
}

I mainly want to focus on this block of code… to shorten down… 🙂

 } while (Turn == 2 & button1.Text == "" | button2.Text == "" | button3.Text == "" | button3.Text == "" | button4.Text == "" | button5.Text == "" | button6.Text == "" | button7.Text == "" | button8.Text == "" | button9.Text == "");
  • 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-17T19:10:46+00:00Added an answer on June 17, 2026 at 7:10 pm

    Create a List of buttons from your individual buttons and then change it to

    while(Turn==2 && buttons.Any(b => b.Text == ""))
    

    In general with 9 buttons they should probably be in an array or list for simpler access:

    Button[] buttons = new Button[] {button1, button2, button3, ... } ;
    

    then you can access it as buttons[0] instead of button1, etc.

    I would do this in your Form initializer rather than having a function that does this on-demand.

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

Sidebar

Related Questions

I have a tic tac toe game I made, I am not done yet,
I made a simple tic,tac,toe game. I have two forms, Form1 and frmStats .
My daughters have made a game not unlike tic-tac-toe. Of course as I played
I have made a Tic-Tac-Toe game for 2 players. Now, I want to give
I have made a simple tic tac toe app for Android which needs no
I have read a book and am trying to make a game of tic-tac-toe
I have made some measurements with tic-toc of X=qr(A) and [Q,R]=qr(A), where A is
I have made some code that makes powerpoint and excel work together. And I
I have made some code to do this, but as It doesn't work. I
I'm making a tic tac toe game and I'm making the player's opponent now.

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.