// Use this for initialization void Start() { manager = UduinoManager.Instance; manager.pinMode(AnalogPin.A2, PinMode.Input); Lock1 = false; Lock2 = false; picRotCheck1 = false; picRotCheck2 = false; picRotCheck3 = false; Lamp1Script = Lamp1Access.GetComponent <Lamp1>(); Lamp2Script = Lamp2Access.GetComponent <Lamp2>(); Lamp3Script = Lamp3Access.GetComponent <Lamp3>(); Lamp4Script = Lamp4Access.GetComponent <Lamp4>(); BlueDoorScript = BlueDoorAccess.GetComponent <BlueDoor>(); RedDoorScript = RedDoorAccess.GetComponent <RedDoor>(); }
private void loadGridToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog theDialog = new OpenFileDialog(); theDialog.Title = "Open Text File"; theDialog.Filter = "TXT files|*.txt"; theDialog.InitialDirectory = @"\"; if (theDialog.ShowDialog() == DialogResult.OK) { string[] rawGridFile = File.ReadAllLines(theDialog.FileName); MessageBox.Show(rawGridFile.Length.ToString()); GridRows = int.Parse(rawGridFile[0]) + 1; GridColumns = int.Parse(rawGridFile[1]) + 1; string[] GridContains = new string[rawGridFile.Length - 1]; for (int i = 2, k = 0; i < rawGridFile.Length; i++, k++) { GridContains[k] = rawGridFile[i]; //remove borders from the file } List <int[]> CoordinatesAndRates = new List <int[]>(); int amount_of_params = 3; //x,y,rating int GridContains_Length = GridContains.Length - 1; for (int i = 0; i < GridContains.Length - 3; i += 3) { CoordinatesAndRates.Add(new int[] { Convert.ToInt32(GridContains[i]), Convert.ToInt32(GridContains[i + 1]), Convert.ToInt32(GridContains[i + 2]) }); //write coordinates and ratings of each member of grid in one list; } grid = new GridObject[GridRows - 1, GridColumns - 1]; const int NumberX = 0, NumberY = 1, Rating = 2; int X; int Y; int locY = 50, locX = 0; int Counter_for_Coordinates = 0; for (int i = 0; i < GridRows - 1; i++) //creating a grid { for (int j = 0; j < GridColumns - 1; j++) { X = CoordinatesAndRates[j][NumberX]; //constants for readable use Y = CoordinatesAndRates[j][NumberY]; locX = (j * BasicGridElementDelta); switch (CoordinatesAndRates[Counter_for_Coordinates][Rating]) //choosing what type of thing is in a field of box and creating it(now we have a grid full of objects) { case 0: grid[i, j] = new NoneEmpty(); break; case 1: grid[i, j] = new Wall(); break; case 2: grid[i, j] = new GreenDoor(); break; case 3: grid[i, j] = new RedDoor(); break; case 4: grid[i, j] = new GreenBox(); break; case 5: grid[i, j] = new RedBox(); break; } grid[i, j].Location = new Point(locX, locY); grid[i, j].Size = new Size(BasicGridElementDelta, BasicGridElementDelta); grid[i, j].Click += this.PictureClick; grid[i, j].BorderStyle = BorderStyle.Fixed3D; //because our class hierarchy is a heir of PictureBox all of this works. this.Controls.Add(grid[i, j]); Counter_for_Coordinates++; } locY = (locY + BasicGridElementDelta); } upBtn.Enabled = true; leftBtn.Enabled = true; downBtn.Enabled = true; rightBtn.Enabled = true; } }