Keep in mind I'm still relatively new to both Visual Studio, and C#, but I'm stuck on that seemed like a pretty simple project at first.
I'm trying to read specific characters from a .CSV file, and turn it into a maze done with simple rectangles. I've gotten completely stuck, and after a few hours of headscratching, I'm not even sure I know where I'm at anymore. Any help is appreciated. I've attached the needed code. If you need any more information or some files
, I'll try to provide.
I'm trying to read specific characters from a .CSV file, and turn it into a maze done with simple rectangles. I've gotten completely stuck, and after a few hours of headscratching, I'm not even sure I know where I'm at anymore. Any help is appreciated. I've attached the needed code. If you need any more information or some files
The main .cs file:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Drawing
{
public partial class Form1 : Form
{
private string[,] maze = { { "X", "X", "X", "X" }, { "X", " ", " ", "X" }, { "X", "X", "X", "X" } };
private Graphics canvas;
private StreamReader file;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
canvas = lblDraw1.CreateGraphics();
}
private void readFile(string fileName = "maze.csv")
{
int X = 0, Y = 0;
int width = 0, height = 0, temp=0;
string[] array;
string theLine;
//stupid read just to find the Width and Height
file = new StreamReader(fileName);
readFile("maze.csv");
while ((theLine = file.ReadLine())!=null)
{
height++;
temp= theLine.Split(',').Length;
if (temp > width)
width = temp;
}
maze = new string[width, height]; //the whole point of the pre read
//Transfer Data
file = new StreamReader(fileName);
while ((theLine = file.ReadLine()) != null)
{
array = theLine.Split(',');//grab data
//
for (X = 0; X < width; X++)
{
//Transfer Part
maze[X, Y] = array[X];
}
Y++;
}
}
private void draw()
{
int size = 30;
for (int Y = 0; Y < 999; Y++)
{
for (int X = 0; X < 999; X++)
{
if (file.ReadLine() == "X")
{
canvas.FillRectangle(Brushes.Black, new Rectangle(Y * size, X * size, size, size));
}
else
{
canvas.FillRectangle(Brushes.White, new Rectangle(Y * size, X * size, size, size));
}
}
}
}
private void btnDraw_Click(object sender, EventArgs e)
{
canvas.Clear(Color.White);
draw();
/*
for (int Y = 0; Y < 999; Y++)
{
for (int X = 0; X < 999; X++)
{
if (file.ReadLine() == "x")
{
canvas.FillRectangle(Brushes.Black, new Rectangle(Y * size, X * size, size, size));
}
else
{
canvas.FillRectangle(Brushes.White, new Rectangle(Y * size, X * size, size, size));
}
}
}
*/
}
}
}