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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:35:13+00:00 2026-06-12T09:35:13+00:00

I am going through a learning process by coding in C# the Game of

  • 0

I am going through a learning process by coding in C# the Game of Life. I have been able to use a pictureBox and display a grid above so the user can easily click each cell. In button1 I am able to assign the bool variable fill_in a value that will fill in a certain cell when clicked on. But I am now experimenting with loading x and y coordinates of selected cells grabbed from a textfile. Such text file will have on the first line the values: 260 (space) 50. Any Ideas how i can do this?

CODE

namespace life
    {
        public partial class Form1 : Form
        {

            Graphics paper;
            bool[,] fill_in = new bool[450, 450];

        public Form1()
            {
                InitializeComponent();
                paper = pictureBox1.CreateGraphics();

            }


    //makes grid in picture box
    private void drawGrid()
            {
                int numOfCells = 100;
                int cellSize = 10;
                Pen p = new Pen(Color.Blue);
                paper.Clear(Color.White);

                for (int i = 0; i < numOfCells; i++)
                {   
                    // Vertical
                    paper.DrawLine(p, i * cellSize, 0, i * cellSize, numOfCells * cellSize);
                    // Horizontal
                    paper.DrawLine(p, 0, i * cellSize, numOfCells * cellSize, i * cellSize);
                }
            }

    // populate bool fill_in with true (alive) or false (dead)
            private void clearGrid()
            {
                for (int x = 0; x < 450; x = x + 10)
                {
                    for (int y = 0; y < 450; y = y + 10)
                    {
                        fill_in[x, y] = false;
                    }
                }
            }

     private void button1_Click(object sender, EventArgs e)
            {
                drawGrid();
                clearGrid();

        //randomly populate grid squares
         fill_in[50, 50] = true;
                 fill_in[60, 50] = true;
                 fill_in[30, 40] = true;
                 fill_in[40, 40] = true;

                for (int x = 0; x < 440; x = x + 10)
                {
                    for (int y = 0; y < 440; y = y + 10)
                    {
                        if (fill_in[x, y] == true)
                            paper.FillRectangle(Brushes.Black, x, y, 10, 10);
                    }
                }
            }

     private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openReport = new OpenFileDialog();
            openReport.Filter = "Text Files | *.txt";
            openReport.ShowDialog();          
            StreamReader infile = File.OpenText(openReport.FileName);


        //Need Help/Guidance read text file coordinates and populate grid

        }
  • 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-12T09:35:15+00:00Added an answer on June 12, 2026 at 9:35 am

    I assume that when you get a value pair “x y” from the text file you want to set fill_in[x, y] to true. So here is a code snip-it to do so.

     while (infile.Peek() >= 0) 
     {
         string[] values = infile.ReadLine().Split(' ');
         fill_in[int.Parse(values[0]), int.Parse(values[1])] = true;
     }
    

    The basic idea is simple, you read in lines from the file until there are none left. Then you split up said lines based on the criteria that there will be two ints separated by a space. This method is pretty quick and crude because it doesn’t check for malformed data in the text file and doesn’t handle exception, but it will get the job done if you’re careful with forming the text files.

    Reading and parsing data from a file is pretty important in programming, so I’d suggest googling the subject and familiarize yourself with the concepts.

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

Sidebar

Related Questions

I have been going through the book Learning WCF trying to get my head
I'm going through the process of learning backbone and don't understand all of the
I'm going through the process of learning Backbone.js and I've come across a few
I am learning how to use the SQLBindParameter function. I was going through a
I'm just starting out learning ASP.NET MVC 3. I've been going through the Music
I am currently learning how to use the symfony2 framework. Going through the cook
I was going through a tutorial on http://www.vogella.de/articles/AndroidListView/article.html learning how to do use ListActivity.
I've been learning more about Python recently, and as I was going through the
I am studying Python and currently going through some more learning with dictionaries. I
I'm just learning the Opa language and going through their Manual. In the third

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.