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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:10:29+00:00 2026-06-15T04:10:29+00:00

Im creating a game that generates a random word and then lets the user

  • 0

Im creating a game that generates a random word and then lets the user guess the word.
After the user enters his word the game will compare them and return what letter were correct and if they had the right position. Right now it return differents results when i input the same word.

This is what i have so far:

class Game
{
    public string CorrectPlace;
    public string WrongPlace;
    public string NoneExist;
    public string CorrectWord;
    public string InputWord; // the word the uis
    public int points;

    public string[] Wordarray = new string[] { "radar", "andar", "raggar", "rapar", "raser", "rastar", "rikas" };

    public string getRandomWord(string names)
    {   
        Random ran = new Random();
        return Wordarray[(ran.Next(0,Wordarray.Length-1))];
    }

    public void CheckWords(string name)
    {
        InputWord.ToCharArray(); 

        CorrectWord = getRandomWord(CorrectWord); // store the random word in a string

        for (int i = 0; i < CorrectWord.Length; i++)
        {
            if (InputWord[i] == CorrectWord[i])
                MessageBox.Show("Letter #" + (i + 1).ToString() + " was correct!");
            else
                break;
        }  
    }
}

Im calling the method in my form

    private void button1_Click(object sender, EventArgs e)
    {

        Game nc = new Game();

        nc.InputWord = textBox1.Text;
        nc.CheckWords(nc.InputWord);



        }
  • 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-15T04:10:31+00:00Added an answer on June 15, 2026 at 4:10 am

    Try like this:

    class Game
    {
        public string CorrectPlace;
        public string WrongPlace;
        public string NoneExist;
        public string CorrectWord;
        public string InputWord;  
        public int points;
    
        public string[] Wordarray = null;
    
        public string getRandomWord(string names)
        {   
            Random ran = new Random();
            return Wordarray[(ran.Next(0,Wordarray.Length-1))];
        }
    
        public void Game()
        {
            Wordarray = new string[] { "radar", "andar", "raggar", "rapar", "raser", "rastar", "rikas" }
            CorrectWord = getRandomWord(); // store the random word in a string
        }
    
        public void CheckWords(string name)
        {
            for (int i = 0; i < CorrectWord.Length; i++)
            {
                if (InputWord[i] == CorrectWord[i])
                    MessageBox.Show("Letter #" + (i + 1).ToString() + " was correct!");
                else
                    break;
            }  
        }
    }
    

    The idea behind the scene is to get a random word when game starts( an instance of class Game instantiated) and then compare it with the user input in CheckWords method.

    I would suggest to do not call MessageBox.show in a loop, it will popup every time a match exists.
    occur

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

Sidebar

Related Questions

I'm creating a Tic tac toe game, in that after click made by user
We're creating a game that will run on iOS, Android and in the web
I am creating a game that lets the player enter input, changes some states,
I am creating a game, where it will ask the user to click a
I am currently creating a game that allows the user to click on numerous
im creating a game that has multiple levels and the levels contain multiple textures
I m creating a game, in that i want to use some animation, but
I am creating a game with winforms C#. The game contains some images that
I am creating a Stratego Game and am having trouble creating an algorithm that
i'm creating a card game on iphone. My problem is that i want to

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.