私はC#でGameofLifeをコーディングして学習プロセスを進めています。pictureBox
ユーザーが各セルをクリックしやすいように、を使用して上のグリッドを表示することができました。ではbutton1
、bool変数fill_in
に、クリックしたときに特定のセルに入力される値を割り当てることができます。しかし、私は現在、テキストファイルから取得した選択したセルの読み込みx
と座標を実験しています。このようなテキストファイルの最初の行には、 (スペース)y
という値が含まれます。どうすればこれを行うことができますか?260
50
コード
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
}