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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:51:44+00:00 2026-06-18T00:51:44+00:00

I’m making a hangman game, this part of the code goes behind the button

  • 0

I’m making a hangman game, this part of the code goes behind the button new game. Everytime the user selects new game I want the game to load a new word for users to guess. My problem is I need to put my code in to a loop. For example if non of the if/else statements are not true, select another random number until a statement is true…

I hope that make sense =) Here’s my code so far.

namespace HangMan
{
public partial class Form1 : Form
{
    int RW;
    string previous;

    public Form1()
    {
        InitializeComponent();

    }



    private void Form1_Load(object sender, EventArgs e)
    {
        foreach (TextBox textBox in addTextBox())
        {
            textBox.Visible = false;
            textBox.Text = "";
        }
    }

    private static void LoadImages()
    {
        Image newImageIntro = Image.FromFile("HangmanIntro.jpg");
        Image newImage1 = Image.FromFile("1.jpg");
        Image newImage2 = Image.FromFile("2.jpg");
        Image newImage3 = Image.FromFile("3.jpg");
        Image newImage4 = Image.FromFile("4.jpg");
        Image newImage5 = Image.FromFile("5.jpg");
        Image newImage6 = Image.FromFile("6.jpg");
        Image newImage7 = Image.FromFile("7.jpg");
        Image newImage8 = Image.FromFile("8.jpg");
        Image newImage9 = Image.FromFile("9.jpg");
    }

    private void txtEnText_TextChanged(object sender, EventArgs e)
    {

    }

    private void txtEnText_Enter(object sender, EventArgs e)
    {

    }

public List<TextBox> addTextBox()
    {
        List<TextBox> tBox = new List<TextBox>();

        tBox.Add(textBox1);
        tBox.Add(textBox2);
        tBox.Add(textBox3);
        tBox.Add(textBox4);
        tBox.Add(textBox5);
        tBox.Add(textBox6);
        tBox.Add(textBox7);
        tBox.Add(textBox8);
        tBox.Add(textBox9);
        tBox.Add(textBox10);

        return tBox;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Random rW = new Random();

        foreach (TextBox textBox in addTextBox())
        {
            textBox.Visible = false;
        }


        RW = rW.Next(1, 4);

        if (RW == 1 & previous != "1" ) //Cat
        {
            textBox1.Visible = true;
            textBox2.Visible = true;
            textBox3.Visible = true;
            previous = "1";


        }
        else if (RW == 2 & previous != "2" ) //Elephant
        {
            textBox1.Visible = true;
            textBox2.Visible = true;
            textBox3.Visible = true;
            textBox4.Visible = true;
            textBox5.Visible = true;
            textBox6.Visible = true;
            textBox7.Visible = true;
            textBox8.Visible = true;
            previous = "2";
        }
        else if (RW == 3 & previous != "3") //Giraffe
        {
            textBox1.Visible = true;
            textBox2.Visible = true;
            textBox3.Visible = true;
            textBox4.Visible = true;
            textBox5.Visible = true;
            textBox6.Visible = true;
            textBox7.Visible = true;
            previous = "3";
        }
        else if (RW == 4 & previous != "4") //Monkey
        {
            textBox1.Visible = true;
            textBox2.Visible = true;
            textBox3.Visible = true;
            textBox4.Visible = true;
            textBox5.Visible = true;
            textBox6.Visible = true;
            previous = "4";
        }
        else
        {
        }



    }
}

}

  • 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-18T00:51:45+00:00Added an answer on June 18, 2026 at 12:51 am

    Put this around your code:

    while(true)
    {
    // CODE
    break;
    }
    

    and inside the else {} part:

    continue;
    

    Edit:
    You can also use LINQ, e. g.

    while(Controls.OfType<TextBox>().All(t => !t.Visible))
    

    if you only have those boxes whose visibility changes inside the loop.

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

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

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.