/*Prectete si po sobe zadani.. Testovaci soubory neobsahujou \r\n a dokonce ani nejsou textove soubory!!! Tohle mi vzalo dost velkou cast casu*/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Text.RegularExpressions; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string[,] points = new string[80, 80]; int width = 80; int height = 80; string maze = ""; int Xsel = 1; int Ysel = 1; string[] lines = new string[81]; private void Form1_Load(object sender, EventArgs e) { pictureBox1.Invalidate(); } //save private void button1_Click(object sender, EventArgs e) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { //nedokonceno } } } //load private void button2_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { string path = openFileDialog1.FileName; using (FileStream fs = File.OpenRead(path)) { byte[] buffer = new byte[1024]; UTF8Encoding temp = new UTF8Encoding(true); while (fs.Read(buffer, 0, buffer.Length) > 0) { maze += temp.GetString(buffer); } } lines = Regex.Split(maze, "\r\n"); string[] cosi = new string[2]; cosi = lines[0].Split(' '); try { width = Convert.ToInt32(cosi[0]); height = Convert.ToInt32(cosi[1]); } catch { MessageBox.Show("Error"); } } pictureBox1.Invalidate(); //nedokonceno } //Place Wall private void button3_Click(object sender, EventArgs e) { if (points[Xsel - 1, Ysel - 1] == "&" || points[Xsel - 1, Ysel - 1] == "#") { MessageBox.Show("Can't replace Lady/TV"); } else { points[Xsel-1, Ysel-1] = "X"; } pictureBox1.Invalidate(); } //Place Spy private void button6_Click(object sender, EventArgs e) { if (points[Xsel - 1, Ysel - 1] == "&" || points[Xsel - 1, Ysel - 1] == "#") { MessageBox.Show("Can't replace Lady/TV"); } else { points[Xsel-1, Ysel-1] = "@"; } pictureBox1.Invalidate(); } //Path of spy private void button8_Click(object sender, EventArgs e) { } //Move private void button4_Click(object sender, EventArgs e) { Form3 form = new Form3(); form.ShowDialog(); string help = points[Xsel - 1, Ysel - 1]; if (form.x < width || form.y < height) { points[Xsel - 1, Ysel - 1] = points[form.x, form.y]; points[form.x, form.y] = help; } else { MessageBox.Show("Error"); } } //Remove private void button5_Click(object sender, EventArgs e) { if (points[Xsel-1, Ysel-1] == "&" || points[Xsel-1, Ysel-1] == "#") { MessageBox.Show("Can't remove Lady/TV"); } else { points[Xsel-1, Ysel-1] = ""; } pictureBox1.Invalidate(); } //New maze private void button9_Click(object sender, EventArgs e) { Form2 form = new Form2(); form.ShowDialog(); width = form.width; height = form.height; Xsel = 1; Ysel = 1; points[0, 0] = "&"; points[width-1, height-1] = "#"; pictureBox1.Invalidate(); } //Selection private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.X / 5 + 1 <= width & e.Y / 5 + 1 <= height) { Xsel = e.X / 5 + 1; Ysel = e.Y / 5 + 1; } pictureBox1.Invalidate(); } //Repaint private void pictureBox1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen Line = new Pen(Brushes.Black); Brush Sel = new SolidBrush(Color.Yellow); Brush Wall = new SolidBrush(Color.Black); Brush Spy = new SolidBrush(Color.Red); Brush Lady = new SolidBrush(Color.Blue); Brush TV = new SolidBrush(Color.Green); //horizontal for (int x = 0; x <= width * 5; x += 5) { for (int y = 0; y <= height * 5; y += 5) { Point p1 = new Point(); Point p2 = new Point(); p1.X = x; p1.Y = y; p2.X = width; p2.Y = y; g.DrawLine(Line, p1, p2); } } //vertical for (int x = 0; x <= width * 5; x += 5) { for (int y = 0; y <= height * 5; y += 5) { Point p1 = new Point(); Point p2 = new Point(); p1.X = x; p1.Y = y; p2.X = x; p2.Y = height; g.DrawLine(Line, p1, p2); } } g.FillRectangle(Sel, (Xsel-1)*5+1, (Ysel-1)*5+1, 4, 4); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (points[x, y] == "X") { g.FillRectangle(Wall, x * 5 + 1, y * 5 + 1, 4, 4); } if (points[x, y] == "&") { g.FillRectangle(Lady, x * 5 + 1, y * 5 + 1, 4, 4); } if (points[x, y] == "@") { g.FillRectangle(Spy, x * 5 + 1, y * 5 + 1, 4, 4); } if (points[x, y] == "#") { g.FillRectangle(TV, x * 5 + 1, y * 5 + 1, 4, 4); } } } } } }