private void LoadButton_Click(object sender, EventArgs e) { SelectScreen.SavedGrids.Clear(); string newX, newY, newV; string newName = ""; bool start = true; List <GridBox> Grid = new List <GridBox>(); XmlReader reader = XmlReader.Create("savedGrids.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Text) { newX = reader.ReadString(); reader.ReadToNextSibling("y"); newY = reader.ReadString(); if ((!start) && (newX == "0") && (newY == "0")) { SelectScreen.SavedGrids.Add(new SavedGrid(Grid, newName)); Grid.Clear(); } reader.ReadToNextSibling("value"); newV = reader.ReadString(); reader.ReadToNextSibling("name"); newName = reader.ReadString(); GridBox hs = new GridBox(Convert.ToInt32(newX), Convert.ToInt32(newY), newV); Grid.Add(hs); start = false; } } reader.Close(); Thread.Sleep(180); menuClick.Play(); difficulty = "Saved"; GameScreen.Grid.Clear(); GameScreen.Grid = SavedGrids[0].Grid; SavedGrids[0].OnLoad(); GameScreen.NewGrid = false; GameScreen gs = new GameScreen(); Form f = this.FindForm(); f.Controls.Remove(this); f.Controls.Add(gs); }
private void GameScreen_MouseClick(object sGameEndeder, MouseEventArgs e) { if (!GameEnded) { ClickCounter++; ClickLable.Text = "Number of Clicks: " + ClickCounter; List <GridBox> zerobox = new List <GridBox>(); switch (e.Button) { case MouseButtons.Left: foreach (GridBox box in Grid) { Rectangle test = new Rectangle(tr.X + (box.x) * 40, tr.Y + (box.y) * 40, 39, 39); Rectangle cursor = new Rectangle(Cursor.Position.X, Cursor.Position.Y, 1, 1); if (test.IntersectsWith(cursor)) { if (box.value == "Gem" || box.value == "TGem" || box.value == "BGem") { GameEnded = true; OutputLabel.Visible = true; OutputLabel.Text = "You have died due to your incompetence"; GameTimer.Enabled = false; ClickCounter = 0; TimeTaken = 0; break; } if (box.value == "0") { zerobox.Add(box); } else { box.appearence = "Visible"; } #region zerobox loop while (zerobox.Count() > 0) { GridBox b = zerobox[0]; Grid[Grid.IndexOf(b)].appearence = "Visible"; // Top Center if ((Grid.IndexOf(b) + 1 < Grid.Count()) && (b.y != SelectScreen.GridHeight - 1)) { if ((Grid[Grid.IndexOf(b) + 1].value != "Gem") && (Grid[Grid.IndexOf(b) + 1].value != "TGem")) { if ((Grid[Grid.IndexOf(b) + 1].value == "0") && (Grid[Grid.IndexOf(b) + 1].appearence == "Invisible")) { zerobox.Add(Grid[Grid.IndexOf(b) + 1]); } else { Grid[Grid.IndexOf(b) + 1].appearence = "Visible"; } } } // Bottom Center if ((Grid.IndexOf(b) - 1 > 0) && (b.y != 0)) { if ((Grid[Grid.IndexOf(b) - 1].value != "Gem") && (Grid[Grid.IndexOf(b) - 1].value != "BGem")) { if ((Grid[Grid.IndexOf(b) - 1].value == "0") && (Grid[Grid.IndexOf(b) - 1].appearence == "Invisible")) { zerobox.Add(Grid[Grid.IndexOf(b) - 1]); } else { Grid[Grid.IndexOf(b) - 1].appearence = "Visible"; } } } // Right if (Grid.IndexOf(b) + SelectScreen.GridHeight < Grid.Count()) { if ((Grid[Grid.IndexOf(b) + SelectScreen.GridHeight].value != "Gem") && (Grid[Grid.IndexOf(b) + SelectScreen.GridHeight].value != "BGem") && (Grid[Grid.IndexOf(b) + SelectScreen.GridHeight].value != "TGem")) { if ((Grid[Grid.IndexOf(b) + SelectScreen.GridHeight].value == "0") && (Grid[Grid.IndexOf(b) + SelectScreen.GridHeight].appearence == "Invisible")) { zerobox.Add(Grid[Grid.IndexOf(b) + SelectScreen.GridHeight]); } else { Grid[Grid.IndexOf(b) + SelectScreen.GridHeight].appearence = "Visible"; } } } // Left if ((Grid.IndexOf(b) - SelectScreen.GridHeight > 0)) { if ((Grid[Grid.IndexOf(b) - SelectScreen.GridHeight].value != "Gem") && (Grid[Grid.IndexOf(b) - SelectScreen.GridHeight].value != "BGem") && (Grid[Grid.IndexOf(b) - SelectScreen.GridHeight].value != "TGem")) { if ((Grid[Grid.IndexOf(b) - SelectScreen.GridHeight].value == "0") && (Grid[Grid.IndexOf(b) - SelectScreen.GridHeight].appearence == "Invisible")) { zerobox.Add(Grid[Grid.IndexOf(b) - SelectScreen.GridHeight]); } else { Grid[Grid.IndexOf(b) - SelectScreen.GridHeight].appearence = "Visible"; } } } // Top Left if ((Grid.IndexOf(b) + SelectScreen.GridHeight + 1 < Grid.Count()) && (b.y != SelectScreen.GridHeight - 1)) { if ((Grid[Grid.IndexOf(b) + SelectScreen.GridHeight + 1].value != "Gem") && (Grid[Grid.IndexOf(b) + SelectScreen.GridHeight + 1].value != "TGem") && (Grid[Grid.IndexOf(b) + SelectScreen.GridHeight + 1].value != "BGem")) { if ((Grid[Grid.IndexOf(b) + SelectScreen.GridHeight + 1].value == "0") && (Grid[Grid.IndexOf(b) + SelectScreen.GridHeight + 1].appearence == "Invisible")) { zerobox.Add(Grid[Grid.IndexOf(b) + SelectScreen.GridHeight + 1]); } else { Grid[Grid.IndexOf(b) + SelectScreen.GridHeight + 1].appearence = "Visible"; } } } // Bottom Right if ((Grid.IndexOf(b) + SelectScreen.GridHeight - 1 < Grid.Count()) && (b.y != 0)) { if ((Grid[Grid.IndexOf(b) + SelectScreen.GridHeight - 1].value != "Gem") && (Grid[Grid.IndexOf(b) + SelectScreen.GridHeight - 1].value != "BGem") && (Grid[Grid.IndexOf(b) + SelectScreen.GridHeight - 1].value != "TGem")) { if ((Grid[Grid.IndexOf(b) + SelectScreen.GridHeight - 1].value == "0") && (Grid[Grid.IndexOf(b) + SelectScreen.GridHeight - 1].appearence == "Invisible")) { zerobox.Add(Grid[Grid.IndexOf(b) + SelectScreen.GridHeight - 1]); } else { Grid[Grid.IndexOf(b) + SelectScreen.GridHeight - 1].appearence = "Visible"; } } } // Top Right if ((Grid.IndexOf(b) - SelectScreen.GridHeight + 1 > 0) && (b.y != SelectScreen.GridHeight - 1)) { if ((Grid[Grid.IndexOf(b) - SelectScreen.GridHeight + 1].value != "Gem") && (Grid[Grid.IndexOf(b) - SelectScreen.GridHeight + 1].value != "TGem") && (Grid[Grid.IndexOf(b) - SelectScreen.GridHeight + 1].value != "BGem")) { if ((Grid[Grid.IndexOf(b) - SelectScreen.GridHeight + 1].value == "0") && (Grid[Grid.IndexOf(b) - SelectScreen.GridHeight + 1].appearence == "Invisible")) { zerobox.Add(Grid[Grid.IndexOf(b) - SelectScreen.GridHeight + 1]); } else { Grid[Grid.IndexOf(b) - SelectScreen.GridHeight + 1].appearence = "Visible"; } } } // Bottom Left if ((Grid.IndexOf(b) - SelectScreen.GridHeight - 1 > 0) && (b.y != 0)) { if ((Grid[Grid.IndexOf(b) - SelectScreen.GridHeight - 1].value != "Gem") && (Grid[Grid.IndexOf(b) - SelectScreen.GridHeight - 1].value != "BGem") && (Grid[Grid.IndexOf(b) - SelectScreen.GridHeight - 1].value != "TGem")) { if ((Grid[Grid.IndexOf(b) - SelectScreen.GridHeight - 1].value == "0") && (Grid[Grid.IndexOf(b) - SelectScreen.GridHeight - 1].appearence == "Invisible")) { zerobox.Add(Grid[Grid.IndexOf(b) - SelectScreen.GridHeight - 1]); } else { Grid[Grid.IndexOf(b) - SelectScreen.GridHeight - 1].appearence = "Visible"; } } } zerobox.Remove(b); } #endregion } } // Reaveal block break; case MouseButtons.Right: Mouse = new Point(Cursor.Position.X, Cursor.Position.Y); foreach (GridBox b in Grid) { Rectangle test = new Rectangle(tr.X + (b.x) * 40, tr.Y + (b.y) * 40, 39, 39); Rectangle cursor = new Rectangle(Cursor.Position.X, Cursor.Position.Y, 1, 1); if (test.IntersectsWith(cursor)) { if (!(b.appearence == "Visible")) { if ((b.appearence == "Invisible") && !FlagLimitReached) { b.appearence = "Marked"; } else { b.appearence = "Invisible"; } } } } // Mark block break; } Refresh(); } }